Migrating from PyGEOS#
The PyGEOS package was merged with Shapely in December 2021 and will be released as part of Shapely 2.0. No further development will take place for the PyGEOS package (except for providing up to date packages until Shapely 2.0 is released).
Therefore, everybody using PyGEOS is highly recommended to migrate to Shapely 2.0.
Generally speaking, this should be a smooth experience because all
functionality of PyGEOS was added to Shapely. All vectorized functions
pygeos have been added to the top-level
with only minor differences (see below). Migrating from PyGEOS to Shapely 2.0
can thus be done by replacing the
pygeos import and module calls:
import pygeos polygon = pygeos.box(0, 0, 2, 2) points = pygeos.points(...) pygeos.contains(polygon, points)
Using Shapely 2.0, this can now be written as:
import shapely polygon = shapely.box(0, 0, 2, 2) points = shapely.points(...) shapely.contains(polygon, points)
In addition, you now also have the scalar interface of Shapely which wasn’t implemented in PyGEOS.
Differences between PyGEOS and Shapely 2.0#
STRtree API changes#
Functionality-wise, everything from
pygeos.STRtree is available in
Shapely 2.0. But while merging into Shapely, some methods have been changed
query_bulk()methods have been merged into a single
query()method now accepts an array of geometries as well in addition to a single geometry, and in that case it will return 2D array of indices.
It should thus be a matter of replacing
queryin your code.
STRtree.query()for more details.
nearest()method was changed to return an array of the same shape as the input geometries. Thus, for a scalar geometry it now returns a single integer index (instead of a (2, 1) array), and for an array of geometries it now returns a 1D array of indices ((n,) array instead of a (2, n) array).
STRtree.nearest()for more details.
nearest_all()method has been replaced with
query_nearest(). For an array of geometries, the output is the same, but when passing a scalar geometry as input, the method now returns a 1D array instead of a 2D array (consistent with
In addition, this method gained the new
all_matcheskeywords (with defaults preserving existing behaviour from PyGEOS). See
STRtree.query_nearest()for more details.
pygeos.Geometry(..)constructor has not been retained in Shapely (the class exists as base class, but the constructor is not callable). Use one of the subclasses, or
apply()function was renamed to
tolerancekeyword of the
segmentize()function was renamed to
quadsegskeyword of the
offset_curve()functions was renamed to
simplify()now defaults to
The behaviour of
symmetric_difference_allwas changed to return an empty GeometryCollection for an empty or all-None sequence as input (instead of returning None).
radiuskeyword of the
buffer()funtion was renamed to