代码之家  ›  专栏  ›  技术社区  ›  Douglas Haubert

如何导入GeoJSON文件以在Google Earth引擎代码编辑器中使用?

  •  3
  • Douglas Haubert  · 技术社区  · 7 年前

    geojson:

        {
        "FeatureCollection" : [
            {
                "geometry" : {
                    "coordinates" : [
                        -45.927083,
                        -12.260889
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "626.46"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.916500,
                        -12.255944
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "565.04"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.949417,
                        -12.270361
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "631.47"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.958833,
                        -12.277361
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "591.85"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.942944,
                        -12.249889
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "644.67"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.930917,
                        -12.243611
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "644.67"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.871917,
                        -12.197139
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.866861,
                        -12.206417
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.967389,
                        -12.261889
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "592.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.973500,
                        -12.250639
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "592.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.962944,
                        -12.245444
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "621.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.952667,
                        -12.239778
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "592.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.931639,
                        -12.228528
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.908694,
                        -12.247472
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "557.20"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.918667,
                        -12.239139
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "644.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.897028,
                        -12.246000
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "557.20"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.906417,
                        -12.230472
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "64.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.895750,
                        -12.225028
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "644.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.927111,
                        -12.213750
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "564.90"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.917639,
                        -12.208750
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "564.90"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.897833,
                        -12.198444
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "584.00"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.881583,
                        -12.202233
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.876833,
                        -12.235306
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.867278,
                        -12.230306
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.856806,
                        -12.224889
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.861806,
                        -12.215611
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.887833,
                        -12.192806
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "12.60"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.877639,
                        -12.187917
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "564.90"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.941889,
                        -12.234611
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "644.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.887111,
                        -12.239889
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "644.50"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.907944,
                        -12.203361
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "591.70"
                },
                "type" : "Feature"
            },
            {
                "geometry" : {
                    "coordinates" : [
                        -45.892722,
                        -12.208028
                    ],
                    "type" : "Point"
                },
                "properties" : {
                    "grower" : "foo",
                    "name" : "bar",
                    "radius" : "574.60"
                },
                "type" : "Feature"
            }
        ]
    }
    

    assets manager )GEE将资产接受为光栅图像、形状文件(.shp、shx、dbf、prj)。

    我发现了一些geojson到shapefile Conversor,不过我需要一种方法将我的geojson直接导入GEE上的功能集合。这可能吗?

    2 回复  |  直到 7 年前
        1
  •  5
  •   Adam Erickson    2 年前

    您还可以使用以下格式将GeoJSON几何体对象直接导入JavaScript或Python API,例如多多边形:

    feature_geometry = {
      "type": "MultiPolygon",
      'coordinates": [
        [
          [
            [-120, 35],
            [-120.001, 35],
            [-120.001, 35.001],
            [-120, 35.001],
            [-120, 35]
          ]
        ]
      ]
    }
    

    两个哈希映射(即字典)都与GeoJSON规范相同( source ):

    {
      "type": "MultiPolygon",
      "coordinates": [
        [
          [
            [-120, 35],
            [-120.001, 35],
            [-120.001, 35.001],
            [-120, 35.001],
            [-120, 35]
          ]
        ]
      ]
    }
    

    import json
    data = json.loads(geojson_file)
    

    对于简单的Python包装器,有 pygeoj 但是JSON数据在Python和JavaScript中本机处理得很好。

        2
  •  2
  •   Noel Gorelick    7 年前

    您可以轻松地使用OGR将数据转换为形状文件(然后可以通过代码编辑器上载)或KML,并将其上载到FusionTables。

    ogr2ogr -f KML output.kml input.json
    

    然而,您的FeatureCollection不是有效的GeoJSON,您必须首先修复它。序言应如下所示:

    {
        "type": "FeatureCollection",
        "features": [
            {
                "geometry" : { ...