用于图像分类的Earth Engine Python API

时间:2019-02-08 14:19:19

标签: python google-earth-engine

我想使用Google Earth引擎python API对Jupyter笔记本进行图像分类。我导入训练数据,图像并剪辑它们,但在分类步骤中却感到困惑。我可以加载和可视化图像,但是当我尝试加载分类图像时,会遇到此错误:

  

EEException:功能“ 2”的属性“ B2”丢失。

我不知道出什么问题了,将不胜感激。谢谢。

这是代码:

import ee  
import ipyleaflet  

def GetTileLayerUrl(ee_image_object):
  map_id = ee.Image(ee_image_object).getMapId()
  tile_url_template = "https://earthengine.googleapis.com/map/{mapid}/{{z}}/{{x}}/{{y}}?token={token}"
  return tile_url_template.format(**map_id)

image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_232067_20130726').select(bands)
points = ee.FeatureCollection('ft:10X7SUjDTiFJDyIA58zLcptK8pwBwjj1BV12SQOgJ').remap([1, 2], [0, 1], 'class')

bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'B11']

training = image.sampleRegions(collection= points, properties= ['class'], scale= 30)
trained = ee.Classifier.cart().train(points, 'class', bands)
classified = image.select(bands).classify(trained)


map1 = ipyleaflet.Map(
    center=(-9.882, -63.124), zoom=8,
    layout={'height':'400px'})

map1.add_layer(
    ipyleaflet.TileLayer(url=GetTileLayerUrl(
    classified.visualize(min=0, max=1, palette=['00FF00', 'FF0000'])
    )))

map1


EEException                               Traceback (most recent call last)
<ipython-input-182-dbb799b9df18> in <module>()
      5 map1.add_layer(
      6     ipyleaflet.TileLayer(url=GetTileLayerUrl(
----> 7     classified.visualize(min=0, max=1, palette=['00FF00', 'FF0000'])
      8 #     image.visualize(bands= ['B4', 'B3', 'B2'], max= 0.4)
      9     )))

<ipython-input-147-0504e16e4b36> in GetTileLayerUrl(ee_image_object)
      3 
      4 def GetTileLayerUrl(ee_image_object):
----> 5   map_id = ee.Image(ee_image_object).getMapId()
      6   tile_url_template = "https://earthengine.googleapis.com/map/{mapid}/{{z}}/{{x}}/{{y}}?token={token}"
      7   return tile_url_template.format(**map_id)

~/anaconda3/lib/python3.7/site-packages/ee/image.py in getMapId(self, vis_params)
    129     vis_image, request = self._apply_visualization(vis_params)
    130     request['image'] = vis_image
--> 131     response = data.getMapId(request)
    132     response['image'] = self
    133     return response

~/anaconda3/lib/python3.7/site-packages/ee/data.py in getMapId(params)
    339     params['image'] = params['image'].serialize()
    340   params['json_format'] = 'v2'
--> 341   result = send_('/mapid', params)
    342   url_format = '%s/map/%s/{z}/{x}/{y}?token=%s' % (
    343       _tile_base_url, result['mapid'], result['token'])

~/anaconda3/lib/python3.7/site-packages/ee/data.py in send_(path, params, opt_method, opt_raw)
   1062       raise ee_exception.EEException('Invalid JSON: %s' % content)
   1063     if 'error' in json_content:
-> 1064       raise ee_exception.EEException(json_content['error']['message'])
   1065     if 'data' not in content:
   1066       raise ee_exception.EEException('Malformed response: ' + str(content))

EEException: Property 'B2' of feature '2' is missing.

0 个答案:

没有答案