第一个注意事项:我的机器是Apple M1,这些机器上还不支持GeoPandas,因此尽管GeoPandas很容易使用,但在这种情况下它不是一个可接受的解决方案。
是否可以创建一个函数或类,以从现有数据帧创建geojson文件,其中几何体是多边形并存储在列中
我已经提取了自定义地图的轮廓,并设法创建了所述轮廓的形状几何体。从那里,我将来自自定义轮廓的几何图形与关于轮廓的一些信息的数据框合并
下面是数据帧结构的示例
ID metric geometry
0 Item_1 23 POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
1 Item_2 17 POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))
2 Item_3 15 POLYGON ((0 0, 3 0, 3 3, 0 3, 0 0))
找到的解决方案here看起来可以满足点坐标的要求,但没有geojson.polygon属性。至少我在文件里找不到。下面是解决方案;我已经强调了它的适用性哪里出了问题
import pandas as pd
import geojson
def data2geojson(df):
features = []
insert_features = lambda X: features.append(
geojson.Feature(geometry=geojson.Point((X["long"],X["lat"],X["elev"])),
### I don't want to create a geoson.point geometry,
### there is no such geojson.polygon attribute to point to my DataFrame's 'geometry' column of polygons,
### and I don't have the lats, longs, etc. due to the polygon being extracted from a custom contour.
### So the closest applicable solution breaks down at this point.
properties=dict(ID=X["ID"],
metric=X["metric"])))
df.apply(insert_features, axis=1)
with open('map1.geojson', 'w', encoding='utf8') as fp:
geojson.dump(geojson.FeatureCollection(features), fp, sort_keys=True, ensure_ascii=False)
data2geojson(df)
提前谢谢
在安装和重新安装GeopDaas、菲奥娜和PyProj之后,这个问题仍然存在。经过一番挖掘,我发现GeoPandas和PyPRJ安装完毕,但菲奥娜卸载了周期性错误,GeoPandas按预期工作。p>
相关问题 更多 >
编程相关推荐