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

Python: Prototype top-level functions that work on external input #266

Closed
kylebarron opened this issue Nov 21, 2023 · 0 comments · Fixed by #293
Closed

Python: Prototype top-level functions that work on external input #266

kylebarron opened this issue Nov 21, 2023 · 0 comments · Fixed by #293

Comments

@kylebarron
Copy link
Member

kylebarron commented Nov 21, 2023

So each function will do:

  • Assert input has __arrow_c_array__ dunder
  • Check that input has geospatial type metadata
  • Convert to rust arrays via FFI
  • Run the algorithm
  • Convert back to the python class after the operation.

This may make sense to do after #236 is done, because then you can just use dyn GeometryArray here, though I guess refactoring after that would be a pretty small change.

For geoarrow/geoarrow-python#38

kylebarron added a commit that referenced this issue Dec 4, 2023
This is just a proof of concept, only for area. It's annoying how
verbose the implementation is, so I want to ideate on that a bit more.

It works!

```py
import pyarrow as pa
import shapely
import pandas as pd
import geopandas as gpd
from geoarrow.rust.core import WKBArray

gdf = gpd.read_file(gpd.datasets.get_path('nybb'))
large_gdf = pd.concat([gdf] * 1000)
wkb = shapely.to_wkb(large_gdf['geometry'])

pa_wkb_arr = pa.array(wkb)
rust_wkb_arr = WKBArray.from_arrow(pa_wkb_arr)
rust_multi_polygon_arr = rust_wkb_arr.to_multi_polygon_array()
area1 = rust_multi_polygon_arr.area()

from geoarrow.rust.core import area
area2 = area(rust_multi_polygon_arr)
```

<img width="350" alt="image"
src="https://github.com/geoarrow/geoarrow-rs/assets/15164633/e0ba4dc2-b441-4f7a-a4f3-b10dea43f1a6">


Closes #266. For
geoarrow/geoarrow-python#38
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 a pull request may close this issue.

1 participant