Как импортировать файлы GeoJSON для использования в редакторе кода Google Earth Engine?

Я создал несколько интересных моментов с моей базой данных с SQL для geoJSON.

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"
        }
    ]
}

Я хотел бы импортировать этот геоджсон в свой редактор кода в Google Earth Engine. В документации (менеджер ресурсов) GEE принимает ресурсы в виде растровых изображений, шейп-файлов ( .shp, shx, dbf, prj).

Кроме того, я обнаружил импорт в коллекцию функций через таблицы слияния, но для этого по-прежнему нужны шейп-файлы.

Я нашел несколько преобразователей geojson в шейп-файлы, но мне нужен способ напрямую импортировать свой geojson в коллекцию функций на GEE. Возможно ли это?


person Douglas Haubert    schedule 11.10.2017    source источник
comment
Вы не можете использовать редактор кода, но вы можете использовать Python API, чтобы найти обходной путь. Извлекайте данные и создавайте объекты ee.Geometry.Point, делайте все, что вам нужно (обработка изображений), и получайте результаты   -  person Rodrigo E. Principe    schedule 17.10.2017
comment
Есть ли какая-нибудь библиотека Python, которую вы рекомендуете для обработки GeoJSON?   -  person Douglas Haubert    schedule 18.10.2017
comment
Смотрите мой ответ ниже. Стандартная библиотека Python json работает очень хорошо, поскольку данные преобразуются в dictionary идентичную по структуре.   -  person Adam Erickson    schedule 27.04.2018


Ответы (2)


Вы также можете напрямую импортировать геометрические объекты GeoJSON, используя, например, этот формат для MultiPolygon:

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

Это идентично спецификации GeoJSON (исходный код):

{
   "type": "MultiPolygon",
   "coordinates": [
       [
           [ [102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0] ]
       ],
       [
           [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
           [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
       ]
   ]
}

Конечно, вы также можете прочитать эти данные из файла GeoJSON:

import json
data = json.loads(geojson_file)

В качестве красивой простой оболочки есть библиотека pygeoj, но данные JSON хорошо обрабатываются изначально в Python и, конечно же, в JS.

person Adam Erickson    schedule 27.04.2018

Вы можете легко использовать OGR для преобразования ваших данных в шейп-файл (который затем можно загрузить через редактор кода) или в KML и загрузить его в FusionTables.

ogr2ogr -f KML output.kml input.json

Однако ваш FeatureCollection недействителен GeoJSON, и вам сначала придется это исправить. Преамбула должна выглядеть так:

{
    "type": "FeatureCollection",
    "features": [
        {
            "geometry" : { ...
person Noel Gorelick    schedule 30.10.2017