2017-03-03 58 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)