geopandas.sjoin#
- geopandas.sjoin(left_df, right_df, how='inner', predicate='intersects', lsuffix='left', rsuffix='right', distance=None, on_attribute=None, **kwargs)[来源]#
两个GeoDataFrames的空间连接。
有关详细信息,请参阅用户指南页面 合并数据。
- Parameters:
- left_df, right_dfGeoDataFrames
- howstring, default ‘inner’
连接的类型:
‘left’: 使用 left_df 的键;仅保留 left_df 几何列
‘right’: 使用来自 right_df 的键;仅保留 right_df 的几何列
‘inner’: 使用两个数据框的键的交集;仅保留left_df几何列
- predicatestring, default ‘intersects’
二元谓词。有效值由所使用的空间索引确定。您可以在
left_df.sindex.valid_query_predicates或right_df.sindex.valid_query_predicates中检查有效值。替代已弃用的op参数。- lsuffixstring, default ‘left’
应用于重叠列名的后缀(左侧GeoDataFrame)。
- rsuffixstring, default ‘right’
应用于重叠列名的后缀(右侧GeoDataFrame)。
- distancenumber or array_like, optional
在每个输入几何图形周围查询树的距离(s),用于'dwithin'谓词。如果是类似数组,必须是一维的,且长度等于左侧GeoDataFrame的长度。如果
predicate='dwithin',则为必填项。- on_attributestring, list or tuple
作为空间谓词的附加连接限制的连接列名。这些列名必须在两个数据框中都存在。如果设置了此选项,观察结果仅在谓词适用且指定列中的值匹配时进行连接。
另请参阅
overlay叠加操作导致新的几何形状
GeoDataFrame.sjoin等效方法
笔记
GeoPandas中的每个操作都是平面的,即不考虑潜在的第三维度。
示例
>>> import geodatasets >>> chicago = geopandas.read_file( ... geodatasets.get_path("geoda.chicago_health") ... ) >>> groceries = geopandas.read_file( ... geodatasets.get_path("geoda.groceries") ... ).to_crs(chicago.crs)
>>> chicago.head() ComAreaID ... geometry 0 35 ... POLYGON ((-87.60914 41.84469, -87.60915 41.844... 1 36 ... POLYGON ((-87.59215 41.81693, -87.59231 41.816... 2 37 ... POLYGON ((-87.62880 41.80189, -87.62879 41.801... 3 38 ... POLYGON ((-87.60671 41.81681, -87.60670 41.816... 4 39 ... POLYGON ((-87.59215 41.81693, -87.59215 41.816... [5 rows x 87 columns]
>>> groceries.head() OBJECTID Ycoord ... Category geometry 0 16 41.973266 ... NaN MULTIPOINT (-87.65661 41.97321) 1 18 41.696367 ... NaN MULTIPOINT (-87.68136 41.69713) 2 22 41.868634 ... NaN MULTIPOINT (-87.63918 41.86847) 3 23 41.877590 ... new MULTIPOINT (-87.65495 41.87783) 4 27 41.737696 ... NaN MULTIPOINT (-87.62715 41.73623) [5 rows x 8 columns]
>>> groceries_w_communities = geopandas.sjoin(groceries, chicago) >>> groceries_w_communities.head() OBJECTID community geometry 0 16 UPTOWN MULTIPOINT ((-87.65661 41.97321)) 1 18 MORGAN PARK MULTIPOINT ((-87.68136 41.69713)) 2 22 NEAR WEST SIDE MULTIPOINT ((-87.63918 41.86847)) 3 23 NEAR WEST SIDE MULTIPOINT ((-87.65495 41.87783)) 4 27 CHATHAM MULTIPOINT ((-87.62715 41.73623)) [5 rows x 95 columns]