Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Geojson数组中删除旧版本_Javascript_Python_Excel_Duplicates_Geojson - Fatal编程技术网

Javascript 从Geojson数组中删除旧版本

Javascript 从Geojson数组中删除旧版本,javascript,python,excel,duplicates,geojson,Javascript,Python,Excel,Duplicates,Geojson,我有一个大型geojson文件,具有以下一般结构: { “特点”:[{ “几何学”:{ “坐标”:[ [ [-12.345, 26.006], [-78.56, 24.944], [-76.44, 24.99], [-76.456, 26.567], [-78.345, 26.23456] ] ], “类型”:“多边形” }, “身份证”:“某些身份证”, “财产”:{ “参数”:“标高” }, “类型”:“特征” }, { “几何学”:{ “坐标”:[ [ [139.345, 39.2345

我有一个大型geojson文件,具有以下一般结构:

{
“特点”:[{
“几何学”:{
“坐标”:[
[
[-12.345, 26.006],
[-78.56, 24.944],
[-76.44, 24.99],
[-76.456, 26.567],
[-78.345, 26.23456]
]
],
“类型”:“多边形”
},
“身份证”:“某些身份证”,
“财产”:{
“参数”:“标高”
},
“类型”:“特征”
},
{
“几何学”:{
“坐标”:[
[
[139.345, 39.2345],
[139.23456, 37.3465],
[141.678, 37.7896],
[141.2345, 39.6543],
[139.7856, 39.2345]
]
],
“类型”:“多边形”
},
“id”:“Some_OtherID_01”,
“财产”:{
“参数”:“标高”
},
“类型”:“特征”
}, {
“几何学”:{
“坐标”:[
[
[143.8796, -30.243],
[143.456, -32.764],
[145.3452, -32.76],
[145.134, -30.87],
[143.123, -30.765]
]
],
“类型”:“多边形”
},
“id”:“某些id”,
“财产”:{
“参数”:“标高”
},
“类型”:“特征”
}
],
“类型”:“功能集合”

}
我选择了使用python,因为我在python语言方面比较强。我将在下面发布我的代码以供参考,但您也可以找到我的另一篇文章,其中详细介绍了我在使用列表从字典中删除键时遇到的问题

import json

json_file = open('features.json')
json_str = json_file.read()
json_data = json.loads(json_str)

dictionaryOfJsonId = {}
removalCounter = 0
keyToRemove = []
valueToRemoveFromList = []
IDList = []

for values in json_data['features']:    #This loop converts the values in the json parse into a dict of only ID
    stringToSplit = values["id"]        #the id values from the json file
    IDList.append(stringToSplit)        #list with all the ID
    newKey = stringToSplit[:-2]         #takes the initial substring up to the last 2 spaces (version)
    newValue = stringToSplit[-2:]       #grabs the last two characters of the string

    if newKey in dictionaryOfJsonId:
        dictionaryOfJsonId[newKey].append(newValue)
    else:
        dictionaryOfJsonId[newKey] = [newValue]


for key in dictionaryOfJsonId:          #Remove entries that do not have duplicates
    if len(dictionaryOfJsonId[key])<2:
        valueToRemoveFromList.append(str(key + dictionaryOfJsonId[key][0]))
    else:
        valueToRemoveFromList.append(str(key +max(dictionaryOfJsonId[key])))


for string in valueToRemoveFromList:    #Remove all values that don't have duplicates from the List of ID
    IDList.remove(string)
    removalCounter+=1


good_features = [i for i in json_data['features'] if i['id'] not in IDList] #Loops through the original and 
                                                                            #removes keys on list from original JSON


with open('features.geojson','w') as outfile:   #create JSON file from list
    json.dump(good_features,outfile)



print "Removed",len(json_data['features'])-removalCounter, "entries from JSON" 
导入json
json_file=open('features.json')
json_str=json_file.read()
json_data=json.loads(json_str)
dictionaryOfJsonId={}
移除计数器=0
keyToRemove=[]
valueToRemoveFromList=[]
IDList=[]
对于json_数据['features']中的值:#此循环将json解析中的值转换为仅包含ID的dict
stringToSplit=values[“id”]#json文件中的id值
IDList.append(stringToSplit)#列出所有ID
newKey=stringToSplit[:-2]#将初始子字符串保留到最后2个空格(版本)
newValue=stringToSplit[-2:]#获取字符串的最后两个字符
如果字典中的newKey为yofjsonid:
dictionaryOfJsonId[newKey].append(newValue)
其他:
dictionaryOfJsonId[newKey]=[newValue]
对于输入字典yOfJSONID:#删除没有重复项的条目
if len(字典yofjsonid[key])