Skip to content

Commit

Permalink
Try to get CRS from DataAPI metadata in writer
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Aug 8, 2024
1 parent b1398ad commit 060843f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ struct Writer

all(x -> GI.isgeometry(x) || ismissing(x), geoms) || error("Not all geoms satisfy `GeoInterface.isgeometry`.")

# Try to get the CRS from the table if it exists
writable_crs = if isnothing(crs) && DataAPI.metadatasupport(feats).read && "GEOINTERFACE:crs" in DataAPI.metadatakeys(feats)
DataAPI.metadata(feats, "GEOINTERFACE:crs"; style = false)
else
crs
end

ngeoms = sum(1 for _ in geoms)
nfeats = sum(1 for _ in Tables.rows(feats))

ngeoms == nfeats || error("Number of geoms does not match number of features. Found: $ngeoms$nfeats.")

new(geoms, feats, crs)
new(geoms, feats, writable_crs)
end
end

Expand Down

0 comments on commit 060843f

Please sign in to comment.