基本图形状文件可视化

2024-10-01 00:30:33 发布

您现在位置:Python中文网/ 问答频道 /正文

在用Basemap创建了一些地图之后,我变得热情起来。我想集成shapefile信息,比如一个多边形,但是有一些问题。我在这里下载了巴伐利亚乡村的寄宿生:

https://www.arcgis.com/home/item.html?id=b752861d1a08489b9a40337668d4367e

现在我要对一个多边形进行积分,比如说,雷根斯堡。我可以用这段代码获取信息,但是我有一些问题

#!/usr/bin/env python

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import shapefile

map = Basemap(projection='merc',
              resolution='l',
              area_thresh=0.01,
              llcrnrlon=9.497681, llcrnrlat=47.827908,
              urcrnrlon=12.683716, urcrnrlat=50.408517)

map.drawcountries(color="gray")
map.fillcontinents(color='#c8dfb0', lake_color='#53BEFD')
map.drawmapboundary(color='black', linewidth=0.5, fill_color='#53BEFD')

sf = shapefile.Reader("BY_Gemeinden/BY_Gemeinden_WM.shp")
shapes = sf.shapes()
records = sf.records()
for record, shape in zip(records, shapes):
    if record[3] == "Regensburg":
        print(shape.shapeType)
        lons, lates = zip(*shape.points)
        print(record)
        print(lons)
        print(lates)

plt.savefig("foo.eps")

输出如下:

^{pr2}$

我的问题:

  1. 我假设lon[1],lon[1]是边界的一个点。显然还有很多。在
  2. 我怎么知道档案上写了什么。什么是shapeTyperecords中的数字是多少?在
  3. 坐标似乎不在“标准”WGS84中?它是什么?在
  4. 有没有快速绘制多边形的方法?在

非常感谢!!!在


Tags: importmapbypltsfrecord多边形color
1条回答
网友
1楼 · 发布于 2024-10-01 00:30:33

我最近写了一篇关于用Basemap制作地图的博客文章,在这篇文章中,我用形状文件在英格兰和威尔士的邮政编码区域绘制和着色。这可能会有所帮助。http://www.jamalmoir.com/2016/06/creating-map-visualisations-in-python.html

基本上你可以用你的shapefile创建一个PatchCollection,然后给它上色。然后你把它加到你的地图上,鲍勃就是你叔叔。在

m.readshapefile('data/uk_postcode_bounds/Areas', 'areas')

df_poly = pd.DataFrame({
        'shapes': [Polygon(np.array(shape), True) for shape in m.areas],
        'area': [area['name'] for area in m.areas_info]
    })
df_poly = df_poly.merge(new_areas, on='area', how='left')

cmap = plt.get_cmap('Oranges')   
pc = PatchCollection(df_poly.shapes, zorder=2)
norm = Normalize()

pc.set_facecolor(cmap(norm(df_poly['count'].fillna(0).values)))
ax.add_collection(pc)

在这个例子中,我用新房子的数量来给每个区域上色,但是你可以随心所欲。在

相关问题 更多 >