Python-geoJSON 产生无效的 JSON 输出
Python-geoJSON producing invalid JSON output
我正在使用 python-geojson 1.0.9,由于某种原因,它产生的输出 json 无效。我试过在我的 google 地图 API 上使用它,但没有用。我已经通过 geojson.io 检查了它,同样它是无效的。
我是不是用错了库?或者这是库的问题?
我的Python代码如下:
DATABASE FORMAT
1. ROW 0 = node_number
2. ROW 1 = latitude
3. ROW 2 = longitude
4. ROW 3 = time
5. ROW 4 = water_level
dict = {}
print "\n Show me the databases: \n"
for row in rows:
dict[row[0]] = {'latitude' : str(row[1]), 'longitude' : str(row[2]), 'time' : str(row[3]), 'water_level' : str(row[4]), 'node_number' : str(row[0])}
print dict
nodeCount = 0
plist=[]
flist=[]
for node in dict:
#Cast our GPS coords into floats
lat = float(dict[node]['latitude'])
lon = float(dict[node]['longitude'])
print "\n Point = %d : Lat = %f Long = %f" % (nodeCount,lat,lon)
#Increase nodeCount
nodeCount += 1
# Generate point and add to point list
point = Point((lon,lat))
plist.append(point)
# Generate feature and add it to feature list
feature = Feature(geometry=point, properties={"nodeNumber": dict[node] ['node_number'], "waterLevel": dict[node]['water_level'], "time": dict[node]['time'], "longitude": dict[node]['longitude'], "latitude": dict[node]['latitude']})
flist.append(feature)
# Generate Feature Collection and dump to file
FeatureClct = FeatureCollection(flist)
#Encode FeatureCollection as JSON
dump = geojson.dumps(FeatureClct, sort_keys=True)
print dump
with open("output.json", "w") as text_file:
text_file.write("%s" % dump)
这是我得到的 JSON 输出:http://104.236.77.88/bostonunderwater/geojson/
请注意,eqfeed_callback( JSON ) 是我手动放置的包装器,即使删除 JSON 仍然无效。
如果您能就我生成无效 JSON 的原因给出任何可能的指示,我们将不胜感激。
link 中的 GeoJSON(没有包装器)是有效的。您可以在此处自行检查:http://geojsonlint.com/ Just copy/paste into the textarea and don't forget to click "FeatureCollection" in the top navbar first. It's also valid when i run it through http://jsonlint.com/ It must be something sketchy with http://geojson.io/ 因为您的 GeoJSON 非常好。
我正在使用 python-geojson 1.0.9,由于某种原因,它产生的输出 json 无效。我试过在我的 google 地图 API 上使用它,但没有用。我已经通过 geojson.io 检查了它,同样它是无效的。
我是不是用错了库?或者这是库的问题?
我的Python代码如下:
DATABASE FORMAT
1. ROW 0 = node_number
2. ROW 1 = latitude
3. ROW 2 = longitude
4. ROW 3 = time
5. ROW 4 = water_level
dict = {}
print "\n Show me the databases: \n"
for row in rows:
dict[row[0]] = {'latitude' : str(row[1]), 'longitude' : str(row[2]), 'time' : str(row[3]), 'water_level' : str(row[4]), 'node_number' : str(row[0])}
print dict
nodeCount = 0
plist=[]
flist=[]
for node in dict:
#Cast our GPS coords into floats
lat = float(dict[node]['latitude'])
lon = float(dict[node]['longitude'])
print "\n Point = %d : Lat = %f Long = %f" % (nodeCount,lat,lon)
#Increase nodeCount
nodeCount += 1
# Generate point and add to point list
point = Point((lon,lat))
plist.append(point)
# Generate feature and add it to feature list
feature = Feature(geometry=point, properties={"nodeNumber": dict[node] ['node_number'], "waterLevel": dict[node]['water_level'], "time": dict[node]['time'], "longitude": dict[node]['longitude'], "latitude": dict[node]['latitude']})
flist.append(feature)
# Generate Feature Collection and dump to file
FeatureClct = FeatureCollection(flist)
#Encode FeatureCollection as JSON
dump = geojson.dumps(FeatureClct, sort_keys=True)
print dump
with open("output.json", "w") as text_file:
text_file.write("%s" % dump)
这是我得到的 JSON 输出:http://104.236.77.88/bostonunderwater/geojson/ 请注意,eqfeed_callback( JSON ) 是我手动放置的包装器,即使删除 JSON 仍然无效。
如果您能就我生成无效 JSON 的原因给出任何可能的指示,我们将不胜感激。
link 中的 GeoJSON(没有包装器)是有效的。您可以在此处自行检查:http://geojsonlint.com/ Just copy/paste into the textarea and don't forget to click "FeatureCollection" in the top navbar first. It's also valid when i run it through http://jsonlint.com/ It must be something sketchy with http://geojson.io/ 因为您的 GeoJSON 非常好。