2017-03-03 59 views
1

我试图读取从Flickr发布的一组shapefile,它们位于here。我试图同时具有以GeoJSON为重点库和常规JSON库导入它,但我得到了同样的错误:Flickr GeoJSON无法在Python中加载

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], 
+1

'jsonlint'是不满意的'“标签”的结尾逗号:“倡导港,新斯科舍省,加拿大”'。恐怕我不知道这个(或为什么它在那里)的一般修复,因为删除该逗号只会将问题推到“”href“:”http://farm6.static.flickr.com/5206/ shape文件/ 4_20101215_40503d67d7.tar.gz”,' – roganjosh

回答

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)