Skip to content

[WIP] Convert shapely geometries#47

Closed
jorisvandenbossche wants to merge 1 commit intopygeos:masterfrom
jorisvandenbossche:from_shapely
Closed

[WIP] Convert shapely geometries#47
jorisvandenbossche wants to merge 1 commit intopygeos:masterfrom
jorisvandenbossche:from_shapely

Conversation

@jorisvandenbossche
Copy link
Copy Markdown
Member

This PR adds a from_shapely functionality, to convert an array of shapely objects into pygeos objects.
This is something I will often need to use pygeos in GeoPandas (since all (testing) code their is written to handle shapely input).

Work in progress for now, the None handling is not yet working.

@caspervdw
Copy link
Copy Markdown
Member

Do we really need to go through C here? We will have the interpreter overhead anyway as shapely stores its GEOSGeometry pointer in a (dynamic) attribute.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

How would you convert a shapely object into a pygeos object on the python level? (without going through WKB)

@caspervdw
Copy link
Copy Markdown
Member

How would you convert a shapely object into a pygeos object on the python level? (without going through WKB)

Calling the GEOSClone function on a pointer originating from a Python int is asking for problems. It will be easy to get segfaults. Also I am thinking about GEOS versioning issues.

I was thinking about WKB indeed. In general I like using stable API protocols like that. Does it add that much overhead?

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

Calling the GEOSClone function on a pointer originating from a Python int is asking for problems.

That's what Shapely is doing all the time ..
But of course, they know that the GEOS function they are calling comes from the same GEOS installation as with which they created the geometry. And indeed, in our case you could end up with a different GEOS .. (one included in the shapely wheel, and pygeos using another one for some reason). I didn't think of that. As long as it are two separate projects, we should probably indeed not do this.

Will do a check of performance difference between both options.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

I did a quick check, and to give an idea of the speed-up, for an array of 100000 shapely points, going through WKB takes ~960ms, while the method in this PR (cloning) takes ~40ms.

But ok, for now this is not a blocker, and agree that GEOS versioning issues makes this problematic. But when we think again about better integration with shapely, this might something to reconsider.

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

Successfully merging this pull request may close these issues.

2 participants