我有一个从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,但无法获取所需的过滤图像和河流形状。
答案 0 :(得分:0)
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('\'','\"')