簡體   English   中英

Flickr GeoJSON無法加載Python

[英]Flickr GeoJSON fails to load in Python

我正在嘗試閱讀Flickr發布的一組shapefile,它們位於此處 我嘗試使用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], 

上面的評論是正確的。 我必須在文件中讀取,刪除最后的逗號並創建一個新的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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM