我刚刚创建了一个非常简单的geopandas示例(请参见下文)。它有效,但是我注意到能够拥有世界的自定义部分对我来说很重要。有时德国,有时只有柏林。(此外,我想按在geopandas文件中定义为多边形的区域汇总我拥有的数据,但我将其添加到另一个问题中。)
我如何获得与“
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
Run Code Online (Sandbox Code Playgroud)
可视化?
# 3rd party modules
import pandas as pd
import geopandas as gpd
import shapely
# needs 'descartes'
import matplotlib.pyplot as plt
df = pd.DataFrame({'city': ['Berlin', 'Paris', 'Munich'],
'latitude': [52.518611111111, 48.856666666667, 48.137222222222],
'longitude': [13.408333333333, 2.3516666666667, 11.575555555556]})
gdf = gpd.GeoDataFrame(df.drop(['latitude', 'longitude'], axis=1),
crs={'init': 'epsg:4326'},
geometry=[shapely.geometry.Point(xy)
for xy in zip(df.longitude, df.latitude)])
print(gdf)
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
base = world.plot(color='white', edgecolor='black')
gdf.plot(ax=base, marker='o', color='red', markersize=5)
plt.show()
Run Code Online (Sandbox Code Playgroud)
如geopandas.datasets.get_path(...)文档中所述,必须执行
>>> geopandas.datasets.available
['naturalearth_lowres', 'naturalearth_cities', 'nybb']
Run Code Online (Sandbox Code Playgroud)
哪里
搜索“德国shapefile”给出了一个arcgis.com网址,该网址使用“ BundesamtfürKartographie undGeodäsie ”作为来源。使用的结果vg2500_geo84/vg2500_krs.shp如下所示:
资源:
©BundesamtfürKartographie undGeodäsie,美因河畔法兰克福,2011年。
我还必须设置base.set_aspect(1.4),否则看起来不对。该值1.4是通过反复试验发现的。
柏林此类数据的另一个来源是daten.berlin.de
当geopandas读取shapefile时,它是带有列的geopandas数据框
['USE', 'RS', 'RS_ALT', 'GEN', 'SHAPE_LENG', 'SHAPE_AREA', 'geometry']
Run Code Online (Sandbox Code Playgroud)
与:
USE=4 对于所有元素RS 是像16077或01003这样的字符串RS_ALT 是像160770000000或010030000000这样的字符串GEN是一个类似'Saale-Holzland-Kreis'或的字符串'Erlangen'SHAPE_LENG是像202986.1998816或248309.91235015SHAPE_AREA是像1.91013141e+08或1.47727769e+09geometry 是一个匀称的几何形状-主要是多边形| 归档时间: |
|
| 查看次数: |
5838 次 |
| 最近记录: |