2017-03-03 12 views
1

Flickrからリリースされたシェイプファイルのグループを読み込もうとしていますが、これはhereです。私はにGeoJSONに焦点を当てたライブラリーと通常のJSONライブラリの両方でそれをインポートしようとしましたが、私は同じエラーを取得:Flickr GeoJSONがPythonで読み込めません

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 16 column 4 (char 765) 

私は、ファイル内のJSONに何か問題があると仮定します。ここでは上記正しかったファイル

{ 
    "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/ shapefiles/4_20101215_40503d67d7.tar.gz "、' – roganjosh

答えて

0

コメントの1の最初の数行をpygeoj

pygeoj.load(filepath='/flickr_shapefiles/flickr_shapes_localities.geojson') 

から私が使用しているコマンドですし、ここにあります。 geojsonが正しく読み込むためには、ファイルを読み込み、最後のコンマを削除して新しいjsonファイルを作成しなければなりませんでした。

ここで私はそのために使用するコードです:

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) 
関連する問題