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

Better API for merging features #128

Closed
ghyatzo opened this issue Feb 11, 2025 · 2 comments
Closed

Better API for merging features #128

ghyatzo opened this issue Feb 11, 2025 · 2 comments

Comments

@ghyatzo
Copy link

ghyatzo commented Feb 11, 2025

Hello,

It would be nice to be able to merge features automatically into a single one.
Either is not documented, or I could not find how to do it.

For example: say I have a vector of polygons extracted from a shape file, and I want to create a single polygon features with multiple parts. Is there a way to do that easily?
I could just do it by manually merging the polygon points calculate the parts and windings, but it is very tedious and error prone.
Is there a way I can do something like Shapefile.Polygon(::Vector{Shapefile.Polygon}) and automatically generate a new polygon with the correct parts and offsets?

If the Writer API is the way to do it, it's not at all clear the correct way to do this, since the geoms argument already expect a geometry iterator.

@rafaqz
Copy link
Member

rafaqz commented Feb 11, 2025

Shapefile is just for reading and writing, not manipulating. But it will write any kind of geometry objects so you don't have to make the native ones like you describe.

I would use GeoInterface.jl methods and wrappers to reorganise, never work with these geometry objects directly, as you say it's tedious. They're just made to represent Shapefile objects close to how they come from disk. GeoInterface and GeometryOps.jl makes it pretty easy because you can use any compatible objects together.

(And note that Shapefile polygons are already multipolygons in the modern standards sense.)

import GeometryOps as GO
import GeoInterface as GI
# Get a vector of Polygon from whatever you pass in
polygons = GO.flatten(GI.PolygonTrait, your_polygon_vec)
# Make a MultiPolygon from them
combined = GI.MultiPolygon(polygons)

@ghyatzo
Copy link
Author

ghyatzo commented Feb 12, 2025

I must have misunderstood the scope of this package. I apologize.
I guess this is not supposed to be used directly then, sort of a first and last mile package when manipulating "geometric shapes".
Thank you! I'll close this issue then.
Still, it might be valuable mentioning (for future clueless visitors like me) that manipulation should be done with packages higher up in the chain somewhere in the readme :)

@ghyatzo ghyatzo closed this as completed Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants