GEOJSON 到要素(在 ArcGIS 中)缺少属性

GEOJSON to features (in ArcGIS) missing properties

我有一个 GEOJSON 文件,用于在 ArcGIS 中创建要素 class。我的 JSON 有一些缺失的属性,我注意到 ArcGIS 的 JSONToFeatures 工具添加了相邻对象的缺失属性。

例如,我的原始 json 看起来像这样(注意第二个特征缺少 'site_id' 属性):

     {"type": "Feature", "geometry": 
           {"type": "Polygon", "coordinates": [[[-xxx.xxxx, xx.xxxxxxx],....]]]}, "properties": 
                {"id": "0", "address": "xx xxxxx", "site_id": "111111111"}},
     {"type": "Feature", "geometry": 
           {"type": "Polygon", "coordinates": [[[-xxx.xxxx, xx.xxxxxxx],....]]]}, "properties": 
                {"id": "1", "address": "xx xxxxx"}},

使用 Arc JSONToFeatures 工具处理此 json 生成如下所示的 table:

OBJECTID ID Address site_id
0 xx xxx 1111111
1 xx xxx 1111111

注意:第一条记录的 site_id 被添加到第二条记录。

我正在使用 Python 的请求和 json 模块来下载和准备 JSON 文件,然后再创建功能 class。 JSON有100,000个对象,这是一个比较规律的过程,不是一次性的任务。

我的问题是:有没有办法在将 JSON 转换为特征 class 之前对其进行准备,以避免添加不正确的属性?或者,有没有办法让 Arc 使用这些缺失的属性来表现自己?

我找到了使用 JSON 模块的 setdefault 函数的解决方案。

url_ = r"https://...."
with urllib.request.urlopen(url_) as url:
    data = json.loads(url.read().decode('utf-8', 'replace'))
    for items in data['features']:
        if 'ID' not in items['properties']:
            del items
        else:
            items['properties'].setdefault("site_id", '000000000')
with open(r'F:\JSON.json', 'w') as outfile:
    json.dump(data, outfile)