Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for writing Feature Collection without properties #106

Merged
merged 7 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
- windows-latest
arch:
- x64
# tests are not working on Windows with Julia 1.9
exclude:
- os: windows-latest
version: '1.9'
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
Expand Down
3 changes: 2 additions & 1 deletion src/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function get_writer(obj)
elseif GI.trait(obj) isa GI.AbstractFeatureCollectionTrait
geoms = map(GI.geometry, GI.getfeature(obj))
feats = Tables.dictcolumntable(map(GI.properties, GI.getfeature(obj)))
return Writer(geoms, feats, crs)
tbl = isempty(feats) ? emptytable(geoms) : feats
return Writer(geoms, tbl, crs)
elseif Tables.istable(obj)
tbl = getfield(Tables.dictcolumntable(obj), :values) # an OrderedDict
geomfields = findall(tbl) do data
Expand Down
12 changes: 12 additions & 0 deletions test/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
@test t.one == [1, 1]
@test t.two == [2, 2]

# feature collection without properties
struct NoProps end
feats = [(; geometry=Point(0,0)), (; geometry=Point(1,1))]
GI.geomtrait(::NoProps) = GI.FeatureCollectionTrait()
GI.isfeaturecollection(::NoProps) = true
GI.getfeature(::GI.FeatureCollectionTrait, ::NoProps, i) = feats[i]
GI.nfeature(::GI.FeatureCollectionTrait, ::NoProps) = length(feats)
file = tempname()
Shapefile.write(file, NoProps())
t = Shapefile.Table(file)
@test t.geometry == [Point(0,0), Point(1,1)]

# table (with missing)
tbl = [
(geo=Point(0,0), feature=1),
Expand Down
Loading