我试图读取Flickr发布的一组shapefile,它们位于here。我尝试使用geojson聚焦库和常规JSON库导入它,但是我得到了同样的错误:
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 16 column 4 (char 765)
我认为文件中的JSON有问题。这是我在pygeoj
中使用的命令pygeoj.load(filepath='/flickr_shapefiles/flickr_shapes_localities.geojson')
这里是其中一个文件的前几行
{
"type": "FeatureCollection",
"name": "Flickr Shapes Public Dataset 2.0 - Localities",
"description": "To the extent possible under law, Flickr has waived all copyright and related or neighboring rights to the Flickr Shapes Public Dataset, Version 2.0. This work is published from the United States. While you are under no obligation to do so, wherever possible it would be extra-super-duper-awesome if you would attribute Flickr.com when using the dataset. Thanks!",
"license": "http://creativecommons.org/publicdomain/zero/1.0/",
"features": [
{
"type": "Feature",
"id": 4,
"properties": {
"woe_id": 4,
"place_id": "4PrzNyCd",
"place_type": "locality",
"place_type_id": 7,
"label": "Advocate Harbour, Nova Scotia, Canada",
},
"geometry":
{
"type": "MultiPolygon",
"created": 1292452804,
"alpha": 0.0006103515625,
"points": 123,
"edges": 28,
"is_donuthole": 0,
"link": {
"href": "http://farm6.static.flickr.com/5206/shapefiles/4_20101215_40503d67d7.tar.gz",
},
"bbox": [-64.857444763184,45.287086486816,-64.686729431152,45.383140563965],
"coordinates": [
[
[[-64.783630,45.337303], [-64.763374,45.334953], [-64.725792,45.352398], [-64.711700,45.359261], [-64.686729,45.383141], [-64.708260,45.354263], [-64.705696,45.339539], [-64.725792,45.352398], [-64.758568,45.328918], [-64.763885,45.307491], [-64.764145,45.303268], [-64.765602,45.295658], [-64.766289,45.287205], [-64.774803,45.287086],
答案 0 :(得分:0)
上面的评论是正确的。我必须在文件中读取,删除最后的逗号并创建一个新的json文件,以便geojson正确读取它。
以下是我用于此的代码:
with open('flickr_shapefiles/flickr_shapes_regions.geojson', 'r') as file:
data = ""
for line in file.readlines():
data += line.replace(" ", "").replace("\t", "").replace("\n", "")
new_data = data.replace(",}", "}")
this = json.loads(new_data)
with open('/flickr_shapefiles/flickr_shapes_regions_fix.geojson', 'w') as outfile:
json.dump(this, outfile)