geopandas.GeoDataFrame.sjoin#
- GeoDataFrame.sjoin(df, *args, **kwargs)#
两个GeoDataFrame的空间联接。
请参阅用户指南页面 正在合并数据 有关详细信息,请参阅。
- 参数
- dfGeoDataFrame
- how字符串,缺省为‘内部’
联接的类型:
‘Left’:使用Left_df中的键;仅保留Left_df几何列
‘right’:使用right_df中的密钥;仅保留right_df几何列
‘ner’:使用来自两个DFS的键的交集;仅保留LEFT_DF几何列
- predicate字符串,默认‘Intersects’
二元谓词。有效值由使用的空间索引确定。您可以检查Left_df或Right_df中的有效值为
left_df.sindex.valid_query_predicates
或right_df.sindex.valid_query_predicates
- lsuffix字符串,默认为‘Left’
应用于重叠列名的后缀(左GeoDataFrame)。
- rsuffix字符串,默认为‘Right’
应用于重叠列名的后缀(右GeoDataFrame)。
参见
GeoDataFrame.sjoin_nearest
最近邻加入
sjoin
等价顶层函数
注意事项
GeoPandas中的每个操作都是平面的,即没有考虑潜在的第三维。
示例
>>> countries = geopandas.read_file( geopandas.datasets.get_path("naturalearth_lowres")) >>> cities = geopandas.read_file( geopandas.datasets.get_path("naturalearth_cities")) >>> countries.head() pop_est continent name iso_a3 gdp_md_est geometry 0 920938 Oceania Fiji FJI 8374.0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000... 1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... 2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.66559 27.65643, -8.66512 27.58948... 3 35623680 North America Canada CAN 1674000.0 MULTIPOLYGON (((-122.84000 49.00000, -122.9742... 4 326625791 North America United States of America USA 18560000.0 MULTIPOLYGON (((-122.84000 49.00000, -120.0000... >>> cities.head() name geometry 0 Vatican City POINT (12.45339 41.90328) 1 San Marino POINT (12.44177 43.93610) 2 Vaduz POINT (9.51667 47.13372) 3 Luxembourg POINT (6.13000 49.61166) 4 Palikir POINT (158.14997 6.91664)
>>> cities_w_country_data = cities.sjoin(countries) >>> cities_w_country_data.head() name_left geometry index_right pop_est continent name_right iso_a3 gdp_md_est 0 Vatican City POINT (12.45339 41.90328) 141 62137802 Europe Italy ITA 2221000.0 1 San Marino POINT (12.44177 43.93610) 141 62137802 Europe Italy ITA 2221000.0 192 Rome POINT (12.48131 41.89790) 141 62137802 Europe Italy ITA 2221000.0 2 Vaduz POINT (9.51667 47.13372) 114 8754413 Europe Au stria AUT 416600.0 184 Vienna POINT (16.36469 48.20196) 114 8754413 Europe Austria AUT 416600.0