Skip to content

Commit

Permalink
Add support for writing Feature Collection without properties (#106)
Browse files Browse the repository at this point in the history
* Add support for writing feature collection without properties

* Test: Comment Julia 1.9 and Windows in CI

* Test: Comment Windows in CI

* Test: Comment 1.9 in CI

* Test: Undo CI changes

* Exclude Windows from Julia 1.9 tests

* Add comment with explanation
  • Loading branch information
eliascarv authored Mar 27, 2024
1 parent 23ecbb2 commit 186ea20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit 186ea20

Please sign in to comment.