使用geopandas将属性导出到.geojson文件中
我有一个脚本,它可以使用Shapely创建许多多边形,然后将它们导出为.geojson文件。 但是请参见下面的玩具示例
from shapely.geometry import Polygon
import geopandas
roi = Polygon([(0,0), (0,1), (1,0), (1,1)])
rois = [roi, roi]
geopandas.GeoSeries(rois).to_file("detection_data.geojson", driver='GeoJSON')
,但是我也有一个数字列表,每个数字都与一个ploygon关联。有没有办法用属性内的geojson文件导出此?
例如,如果我有一个列表:
detection_prob = [0.8, 0.9]
在.geojson文件中,我希望第一个多边形的属性部分
“ properties”:{“ dentection_prob”:0.8}
和第二个多边形
“ properties”:{“ dentection_prob”:0.9}
etc等...在输出的geojson文件中。
I have a script that creates a lot of Polygons using Shapely and then exports them as .geojson files. See toy example below
from shapely.geometry import Polygon
import geopandas
roi = Polygon([(0,0), (0,1), (1,0), (1,1)])
rois = [roi, roi]
geopandas.GeoSeries(rois).to_file("detection_data.geojson", driver='GeoJSON')
However, I also have a list of numbers, each number is associated with one ploygon. Is there a way to export this with the GeoJSON file inside properties?
For example, if I have a list:
detection_prob = [0.8, 0.9]
In the .geojson file I would like the properties section for the first polygon to read
"properties":{"detection_prob":0.8}
and for the second polygon
"properties":{"detection_prob":0.9}
etc etc etc... in the outputted GeoJSON file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在数据框架上而不是系列上调用
to_file
,则可以将额外的属性添加为列:If you call
to_file
on a dataframe instead of a series, you can add extra attributes as columns: