显示形状文件 [英] Displaying a Shapefile
本文介绍了显示形状文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 shapefile 想要显示.我尝试使用 matplotlib 来显示它,但我得到了这个:但是,当我尝试使用在线网站进行显示时,我得到了这个;
I have a shapefile that I want to display. I tried using matplotlib to display it, but I get this: However, when I tried to display using an online website I get this;
如何获得第二张图片?
这是我的代码:
import shapefile
import matplotlib.pyplot as plt
print("Initializing Shapefile")
sf = shapefile.Reader("ap_abl")
apShapes = sf.shapes()
points = apShapes[3].points
print("Shapefile Initialized")
print("Initializing Display")
fig = plt.figure()
ax = fig.add_subplot(111)
plt.xlim([78, 79])
plt.ylim([19, 20])
print("Display Initialized")
print("Creating Polygon")
ap = plt.Polygon(points, fill=False, edgecolor="k")
ax.add_patch(ap)
print("Polygon Created")
print("Displaying polygon")
plt.show()
提前致谢.
推荐答案
结果是一个 shapefile 内部有多个形状,我需要绘制所有形状.从那以后,这是有效的:
Turns out that a shapefile has multiples shapes inside and I needed to plot all of them. From that, this is what works:
import shapefile
import matplotlib.pyplot as plt
sf = shapefile.Reader("ap_abl")
print("Initializing Display")
fig = plt.figure()
ax = fig.add_subplot(111)
plt.xlim([76, 85])
plt.ylim([12, 21])
print("Display Initialized")
for shape in sf.shapes():
print("Finding Points")
points = shape.points
print("Found Points")
print("Creating Polygon")
ap = plt.Polygon(points, fill=False, edgecolor="k")
ax.add_patch(ap)
print("Polygon Created")
print("Displaying Polygons")
plt.show()
这篇关于显示形状文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文