用geojson制作多边形对象
我有可以包含X多边形量的Geojson文件,因此我有一个循环浏览文件,并将每个多边形的坐标添加到一个数组中。现在,我在制作多边形对象时试图索引数组。
def check_overlap():
geom = []
for j in range(int(get_polygon_count())):
for i, feature in enumerate(data['features'][j+1:]):
geom.append(feature['geometry']['coordinates'])
value1 = geom[0]
polygon1 = Polygon(value1)
#polygon2 = Polygon(geom[1])
print(polygon1)
print(geom[1])
#print(polygon1.intersects(polygon2))
我得到的错误是ValueRorr:亚麻环必须至少具有3个坐标元组
I have geojson files that can have x amount of polygons so I have a for loop that goes through the file and adds the coords of each polygon to an array. Now i'm trying to index the array when making Polygon objects.
def check_overlap():
geom = []
for j in range(int(get_polygon_count())):
for i, feature in enumerate(data['features'][j+1:]):
geom.append(feature['geometry']['coordinates'])
value1 = geom[0]
polygon1 = Polygon(value1)
#polygon2 = Polygon(geom[1])
print(polygon1)
print(geom[1])
#print(polygon1.intersects(polygon2))
The error I get is ValueError: A LinenearRing must have at least 3 coordinate tuples
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个猜测,但是
GEOM
列表被填写和以后的索引的方式polygon()
在每个Geojson Polygon中失败,因为结构是不同的。geojson polygon
如果
GEOM [X]
中的结构恰好是没有孔的Geojson Polygon,则看起来像这样:shapely
polygon()
:polygon()
期望的是Geojson Polygon的第一个元素,可选为孔:尽管我只是将整个东西加载到geopandas中。
It's bit of a guesswork, but the way that
geom
list gets filled and later indexed makesPolygon()
to fail with every GeoJSON Polygon as structures are different.GeoJSON polygon:
If structure in
geom[x]
happens to be GeoJSON Polygon with no holes, it looks something like this :Shapely
Polygon()
:What
Polygon()
expects is the first element of GeoJSON Polygon, optionally followed by holes:Though I'd just load the whole thing into GeoPandas.