geopandas.GeoSeries.dwithin#
- GeoSeries.dwithin(other, distance, align=None)[来源]#
返回一个
Series,其dtype('bool')值为True,用于每个与other的几何形状在设定距离内的对齐几何。该操作以一对一的行方式进行:
- Parameters:
- otherGeoSeries or geometric object
要测试相等性的GeoSeries(逐元素)或几何对象。
- distancefloat, np.array, pd.Series
距离,用于测试每个几何图形是否在内。标量距离将应用于所有几何图形。数组或序列将逐元素应用。如果使用 np.array 或 pd.Series,则必须与 GeoSeries 的长度相同。
- alignbool | None (default None)
如果为真,则根据其索引自动对齐GeoSeries。 如果为假,则保留元素的顺序。 None默认为真。
- Returns:
- Series (bool)
另请参阅
笔记
此方法以行的方式工作。它不会检查一个GeoSeries的元素是否在另一个元素的任何元素的设定距离内。
示例
>>> from shapely.geometry import Polygon, LineString, Point >>> s = geopandas.GeoSeries( ... [ ... Polygon([(0, 0), (1, 1), (0, 1)]), ... LineString([(0, 0), (0, 2)]), ... LineString([(0, 0), (0, 1)]), ... Point(0, 1), ... ], ... index=range(0, 4), ... ) >>> s2 = geopandas.GeoSeries( ... [ ... Polygon([(1, 0), (4, 2), (2, 2)]), ... Polygon([(2, 0), (3, 2), (2, 2)]), ... LineString([(2, 0), (2, 2)]), ... Point(1, 1), ... ], ... index=range(1, 5), ... )
>>> s 0 POLYGON ((0 0, 1 1, 0 1, 0 0)) 1 LINESTRING (0 0, 0 2) 2 LINESTRING (0 0, 0 1) 3 POINT (0 1) dtype: geometry
>>> s2 1 POLYGON ((1 0, 4 2, 2 2, 1 0)) 2 POLYGON ((2 0, 3 2, 2 2, 2 0)) 3 LINESTRING (2 0, 2 2) 4 POINT (1 1) dtype: geometry
我们可以检查每个GeoSeries的几何体是否包含一个单独的几何体:
>>> point = Point(0, 1) >>> s2.dwithin(point, 1.8) 1 True 2 False 3 False 4 True dtype: bool
我们还可以逐行检查两个GeoSeries。 上面的GeoSeries具有不同的索引。我们可以基于索引值对两个GeoSeries进行对齐,并使用相同索引比较元素,使用
align=True,或者忽略索引并根据它们的匹配顺序比较元素,使用align=False:>>> s.dwithin(s2, distance=1, align=True) 0 False 1 True 2 False 3 False 4 False dtype: bool
>>> s.dwithin(s2, distance=1, align=False) 0 True 1 False 2 False 3 True dtype: bool