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 a utility function to GeometryOpsCore, to get geometries from any data structure #240

Open
wants to merge 1 commit into
base: as/usecore
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions GeometryOpsCore/src/geometry_utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@

_linearring(geom::GI.LineString) = GI.LinearRing(parent(geom); extent=geom.extent, crs=geom.crs)
_linearring(geom::GI.LinearRing) = geom


function get_geometries(x)
if GI.isgeometry(x)
return x
# elseif GI.isgeometrycollection(x)
# return GI.getgeom(x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need collect, and needs to be checked first

elseif GI.isfeature(x)
return GI.geometry(x)
elseif GI.isfeaturecollection(x)
return [GI.geometry(f) for f in GI.getfeature(x)]
elseif Tables.istable(x) && Tables.hascolumn(x, first(GI.geometrycolumns(x)))
return Tables.getcolumn(x, first(GI.geometrycolumns(x)))
else
c = collect(x)
Copy link
Member

@rafaqz rafaqz Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to skip this if x is already an AbstractArray, you can have a do nothing condition

if c isa AbstractArray && GI.trait(first(c)) isa GI.AbstractGeometryTrait
return c
else
throw(ArgumentError("""
Expected a geometry, feature, feature collection, table with geometry column, or iterable of geometries.
Got $(typeof(x)).

The input must be one of:
- A GeoInterface geometry (has trait <: AbstractGeometryTrait)
- A GeoInterface feature (has trait FeatureTrait)
- A GeoInterface feature collection (has trait FeatureCollectionTrait)
- A Tables.jl table with a geometry column
- An iterable containing geometries
"""))
end
end
end
Loading