apply
and try to rely as much as you can on built-in GeoSeries methods. If needed use the underlying array of pygeos geometries directly with pygeos functions. You can access it as gdf.geometry.values.data
. When you can use numpy functions instead of for loops, use them. Look up some vectorization guide for pandas, the rules are fairly similar. And when using spatial index, use query_bulk
.
get_geometry
), but we've been adding more functions to vectorize the most common operations where you would get these back as ragged arrays (e.g., get_parts
), where there are varying numbers of geometries within arrays of multi / geometry collections.UserWarning: The Shapely GEOS version (3.8.0-CAPI-1.13.1 ) is incompatible with the GEOS version PyGEOS was compiled with (3.9.0-CAPI-1.16.2). Conversions between both will be slow.
warnings
python package, you can filter that specific UserWarning
GeoDataFrame
? I'm trying to quickly make many simple plots at once. I've tried variations on the following, but it feels a bit hacky.for feature in gdf.iterfeatures():
temp = gpd.GeoSeries(Point(*feat['geometry']['coordinates'][0]), crs=gdf.crs)
ax = temp.plot(figsize=(20, 20), color='red', marker='o', alpha=0.9)
ctx.add_basemap(ax=ax)
fig = ax.get_figure()
fig.savefig('.../out/path/...')
x_coords = np.array([[1, 2, 3], [4, 5, 6]])
y_coords = np.array([[1, 2, 3], [4, 5, 6]])
pygeos.polygons(pygeos.linearrings(x_coords, y=y_coords))
array([<pygeos.Geometry POLYGON ((1 1, 2 2, 3 3, 1 1))>,
<pygeos.Geometry POLYGON ((4 4, 5 5, 6 6, 4 4))>], dtype=object)
try to get your coordinates in a structure like this
numpy
, but I can be wrong
In [5]: polygons1 = pygeos.polygons(np.random.randn(10, 3, 2))
In [6]: polygons2 = pygeos.polygons(np.random.randn(10, 3, 2))
In [7]: pygeos.union(polygons1, polygons2)
Out[7]:
array([<pygeos.Geometry MULTIPOLYGON (((1.12 1.27, 0.677 -1.4, 1.27 -0.521, 1.12 1....>,
<pygeos.Geometry POLYGON ((-2.33 -0.959, -1.35 -0.317, 0.53 0.064, -0.602 1....>,
<pygeos.Geometry POLYGON ((0.69 -1.4, 0.454 -0.704, 0.0886 -0.934, 0.448 -0....>,
<pygeos.Geometry POLYGON ((-0.78 -1.96, -0.967 -0.353, -0.731 -0.221, -1.01 ...>,
<pygeos.Geometry POLYGON ((0.885 0.607, -0.62 -0.964, -0.213 -0.0648, -0.318...>,
<pygeos.Geometry POLYGON ((0.682 1.38, 0.68 -0.76, 0.215 -1.09, 0.755 -1.52,...>,
<pygeos.Geometry MULTIPOLYGON (((-1 0.0676, 1.21 -1.35, -0.0311 -1.23, -1 0....>,
<pygeos.Geometry MULTIPOLYGON (((-1.55 1.55, -0.198 -0.242, -0.614 0.613, -1...>,
<pygeos.Geometry POLYGON ((-0.661 0.291, -0.181 0.0644, 0.246 0.118, 0.861 -...>,
<pygeos.Geometry MULTIPOLYGON (((-0.702 2.27, 0.874 -1.25, -0.751 0.967, -0....>],
dtype=object)
In [8]: polygons = pygeos.polygons(np.random.randn(10, 3, 2))
In [9]: pygeos.union_all(polygons)
Out[9]: <pygeos.Geometry POLYGON ((-0.973 0.0936, -0.976 0.0886, -1.03 0.138, -1.1 0...>