【问题标题】:How to use a FeatureCollection (imported from GEOJson format) and filter a ImageCollection?如何使用 FeatureCollection(从 GEOJson 格式导入)并过滤 ImageCollection?
【发布时间】:2019-11-16 18:52:11
【问题描述】:

我有一个从 GEOJson 文件中导入的 FeatureCollection(它是从 shapefile 中提取的)并将其导入以在 Python 中与 Google Earth Engine API 一起使用。

问题是我不知道如何将它与 ImageCollection 的 filterBounds 函数一起使用。我尝试了几种方法,都无法得到想要的结果(主要是错误响应)

我还需要(如果可能的话)找到一种方法来裁剪这些图像,以便结果具有我正在使用的初始形状(在这种情况下是一条河流)

import ee
import json
import geojson
from IPython.display import Image

ee.Initialize()

# GEOJson (extracted from shapefile)
with open("/content/drive/My Drive/.../mascara.json") as json_file:
   gjson = geojson.load(json_file)

# FeatureCollection imported from geojson
fc = ee.FeatureCollection(geojson.dumps(gjson))

# Landsat Collection (focus on filterBounds function)
imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(fc).filterDate('2016-12-01','2016-12-31')

# trying to filter image by FeatureCollection (not working at all)
image = ee.Image(imageCollection.sort('CLOUD_COVER').first())
Image(url=image.select(['B5','B4','B3']).getThumbUrl({'min':0,'max':3000}))

我收到了一些错误响应:

EEException: Collection.loadTable: Collection asset '{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "MultiPolygon", "coordinates":...

我刚开始学习 Google Earth Engine 的 API,但无法获得我需要的过滤图像和河流形状。

【问题讨论】:

  • 在 gis stackoverflow 社区发布问题

标签: python google-earth-engine


【解决方案1】:
with open('shape/_json/roi.json') as f:
        txt = f.read()
        f.close()

temp = json.JSONDecoder().decode(txt)
temp = temp['features'][0]['geometry']

def byteify(input):
    if isinstance(input, dict):
        return {byteify(key): byteify(value) for key, value in input.iteritems()}
    elif isinstance(input, list):
        return [byteify(element) for element in input]
    elif isinstance(input, unicode):
        return input.encode('utf-8')
    else:
        return input

roi = str(byteify(temp))

roi = roi.replace('\'','\"')

【讨论】:

  • 请评论您的解决方案以便于理解。
猜你喜欢
  • 1970-01-01
  • 2020-11-09
  • 1970-01-01
  • 2021-05-07
  • 2014-12-31
  • 2014-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多