写入文件时添加功能ID

问题描述

为了使用tippicanoe创建Tilesets,我从postgis检索空间数据并将其写入带有geopandas的.geojson文件:

geodata = gpd.read_postgis("test",engine1,geom_col='geom')```
geodata.to_file("test.geojson",driver='GeoJSON')

我的问题是:是否有内置方法或方便的方法可以将 featureID 添加到要素集合中的所有要素?我需要一个如下所示的输出,在功能级别设置 id,而不是在属性中。

{
    "type": "FeatureCollection","features": [
        {
            "id": "1","type": "Feature","properties": {
                "atco_code": "300000492FZ",},"geometry": {
                "type": "Point","coordinates": (-1.1372773238238423,52.346655194010665),{
            "id": "2","properties": {
                "atco_code": "0600CR19133","coordinates": (-2.518177475249135,53.063122731640604),],}

我当前的工作流程是将文件写入 .geojson,再次读取,注入 id 并再次保存。这很不方便!

with open("test.geojson") as f:
    gj = geojson.load(f)
for i in range(0,len(gj["features"])):
    gj["features"][i]["id"] = gj["features"][i]["properties"]["id"]
with open("test.geojson",'w') as outfile:
    geojson.dump(gj,outfile)

提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)