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
availabe in pygeos
have been added to the top-level shapely
module,
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
or merged:
The
query()
andquery_bulk()
methods have been merged into a singlequery()
method. Thequery()
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
query_bulk
withquery
in your code.See
STRtree.query()
for more details.The
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).See
STRtree.nearest()
for more details.The
nearest_all()
method has been replaced withquery_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 withquery()
).In addition, this method gained the new
exclusive
andall_matches
keywords (with defaults preserving existing behaviour from PyGEOS). SeeSTRtree.query_nearest()
for more details.
Other differences#
The
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, orshapely.from_wkt(..)
, instead.The
apply()
function was renamed totransform()
.The
tolerance
keyword of thesegmentize()
function was renamed tomax_segment_length
.The
quadsegs
keyword of thebuffer()
andoffset_curve()
functions was renamed toquad_segs
.The
preserve_topology
keyword ofsimplify()
now defaults toTrue
instead ofFalse
.The behaviour of
union_all()
/intersection_all()
/symmetric_difference_all
was changed to return an empty GeometryCollection for an empty or all-None sequence as input (instead of returning None).The
radius
keyword of thebuffer()
funtion was renamed todistance
.