属性连接

  1. world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
  2. cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))
  3. country_shapes = world[['geometry', 'iso_a3']]
  4. country_names = world[['name', 'iso_a3']]
  5. # 属性连接
  6. country_shapes.head()
  7. country_names.head()
  8. country_shapes = country_shapes.merge(country_names, on='iso_a3')
  9. country_shapes.head()

空间连接

  1. cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))
  2. world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
  3. country_shapes = world[['geometry', 'iso_a3']]
  4. country_names = world[['name', 'iso_a3']]
  5. # For spatial join
  6. countries = world[['geometry', 'name']]
  7. countries = countries.rename(columns={'name':'country'})
  8. # 空间连接
  9. countries.head()
  10. cities.head()
  11. cities_with_country = geopandas.sjoin(cities, countries, how="inner", op='intersects')
  12. cities_with_country.head()