属性连接
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))country_shapes = world[['geometry', 'iso_a3']]country_names = world[['name', 'iso_a3']]# 属性连接country_shapes.head()country_names.head()country_shapes = country_shapes.merge(country_names, on='iso_a3')country_shapes.head()
空间连接
cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))country_shapes = world[['geometry', 'iso_a3']]country_names = world[['name', 'iso_a3']]# For spatial joincountries = world[['geometry', 'name']]countries = countries.rename(columns={'name':'country'})# 空间连接countries.head()cities.head()cities_with_country = geopandas.sjoin(cities, countries, how="inner", op='intersects')cities_with_country.head()