Shapely¶
For interoperability with Shapely, you have three options:
- Top-level
to_shapelyandfrom_shapelyfunctions which aim to accept all array input. to_shapelyandfrom_shapelymethods available on geometry arraysto_shapelyandfrom_shapelymethods available on chunked geometry arrays
How to choose?
-
If you know your data's geometry type, prefer the
from_shapelymethod on a chunked array class. E.g.ChunkedLineStringArray.from_shapely().This has type hinting and auto-completion benefits because your code editor knows what output array you'll receive. It also validates that your data match the geometry type you expect.
It can also lead to better performance because many operations over chunked arrays are automatically multi-threading. - Top-level functions should work with all GeoArrow data structures (except tables as Shapely is geometry-only). The downside is that
Shapely interoperability requires shapely to be installed, and requires Shapely version 2.0 or higher.
Examples¶
from geoarrow.rust.core import from_shapely, to_shapely
import shapely
shapely_geoms = to_shapely(geoarrow_array)
geoarrow_array = from_shapely(shapely_geoms)
Or, if you know the geometry type:
from geoarrow.rust.core import ChunkedLineStringArray
import shapely
geoarrow_array = ChunkedLineStringArray.from_shapely(shapely_geoms)
shapely_geoms = geoarrow_array.to_shapely()