question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vectorize all GEOS functions

See original GitHub issue

Vectorized functions would be a big help to GeoPandas and other projects trying to organize Shapely geometry in arrays, and there seems to be a consensus that it’s best to implement the vectorized GEOS functions within Shapely. (See https://github.com/geopandas/geopandas/issues/430#issuecomment-291083993.)

After taking a look through the code I think we could implement this without too much trouble by adding a version of topology.py that generates vectorized versions of the functions. At that point it would be easy to call the functions from the vectorized module, or add them to the BaseGeometry class, or call them in Geopandas (I think).

I just want to get some feedback to make sure I’m on the right track before I start this, and figure out where people should send the pull requests.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:35 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
caspervdwcommented, Jun 10, 2019

For the last couple of weeks, I did some work on this on the side. Basically, I wrapped most of the GEOS function in numpy ufuncs using this example from the numpy docs.

I started out using @jorisvandenbossche and @mrocklin approach (great blog posts, these really got me started on this) by putting raw pointers in ndarrays. The problem with this is the memory management: you really have to call Destroy precisely once per pointer, else you are left with a memory leak or SIGABRTs because you try to free the same memory block twice.

I ended up with a numpy structured dtype that has the shapely object along with the pointer to the GEOSGeometry. This makes sure GEOSGeometries are deallocated.

The code is now at https://github.com/caspervdw/pygeos, but I am willing to make a PR to shapely if someone wants to review/help with integrating it in shapely.

3reactions
mrocklincommented, Mar 7, 2019

Please excuse the self-advertisement, but we worked a bit on this. It’s summarized here

http://matthewrocklin.com/blog/work/2017/09/21/accelerating-geopandas-1 https://github.com/geopandas/geopandas/issues/473

There is probably new information about this now. I’m a bit out of date.

On Thu, Mar 7, 2019 at 2:56 PM Will May notifications@github.com wrote:

I put this on the backburner because the project I was working on that needed fast shapely loops wasn’t a priority anymore.

As far as I know the concept of what I was trying to do here is sound, though it may require some awkward C++ code. And this is just one possible approach-- I can’t say if it’s better than other possible approaches.

I also saw earlier that geopandas was providing some vectorized shapely functions, so they may have solved your problem already.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Toblerity/Shapely/issues/501#issuecomment-470690821, or mute the thread https://github.com/notifications/unsubscribe-auth/AASszIAntrh6ePMk_xl1zYgVjKOaY8jMks5vUXz-gaJpZM4OR6La .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vectorize all GEOS functions · Issue #501 · shapely ... - GitHub
Vectorized functions would be a big help to GeoPandas and other projects trying to organize Shapely geometry in arrays, and there seems to ......
Read more >
geos::geom::Geometry Class Reference
A vector of non-const Geometry pointers. ... Public Member Functions ... Computes a new geometry which has all component coordinate sequences in reverse ......
Read more >
Open Source Geometry Engine ('GEOS') R API
High-performance functions to extract information from, calculate relationships between, and transform geometries are provided.
Read more >
PyGEOS — pygeos documentation
PyGEOS is a C/Python library with vectorized geometry functions. The geometry operations are done in the open-source geometry library GEOS.
Read more >
geos function - RDocumentation
All functions (or methods) returning a geometry return an object of the same class as that of the first argument ( x )....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found