我是 Shapely 的新手(但对它充满热情),最近我发现了一些障碍。
我有一个正在通过 Fiona 读取的多边形 shapefile。这个 shapefile 包含多边形和多多边形项目,我需要为其中所有坐标的每个特征(即外部和/或内部)构建一个数组。值得注意的是,其中两个多边形项目具有内环(并且它们是有效的)。
我似乎没有问题访问多边形/多多边形的外部坐标......但我没有为内部坐标拉任何东西。
我需要在这里采取一种新的方法(即LinearRings)...?
def convert_polygons(inFile):
for polys in fiona.open(inFile):
myShape = shape(polys['geometry'])
exterior_poly = 0
interior_poly = 0
if isinstance(myShape, Polygon):
print "yes, I am a polygon"
# count how many points for each interior polygon
try:
interior_poly += len(myShape.interior.coords)
except:
pass
# count how many points for each exterior polygon
exterior_poly += len(myShape.exterior.coords)
geomArray = asarray(myShape.exterior)
print geomArray
print "number of interior points in polygon " + str(interior_poly)
print "number of exterior points in polygon " + str(exterior_poly)
elif isinstance(myShape, MultiPolygon):
print "yes, I am a MultiPolygon"
# count how many points for each interior polygon
try:
interior_poly += len(myShape.interior.coords)
except:
pass
try:
# count how many points for each exterior polygon
exterior_poly += len(myShape.exterior.coords)
except:
pass
try:
geomArray = asarray(myShape.interior)
except:
pass
try:
geomArray = asarray(myShape.exterior)
except:
pass
print geomArray
print "number of interior points in polygon " + str(interior_poly)
print "number of exterior points in polygon " + str(exterior_poly)