Google Earth Engine – Converting Feature to Geometry for .filterBounds from Shapefile

google-earth-engineshapefile

This is my first time working with GEE.

I am working with a shapefile (imported with name polygon and then generated var shp) for Indonesia, which contains as features the various districts in Indonesia. These features are contained under ADM2_EN. I have labelled the shapefile with district labels, but get an error when converting feature to geometry for .filterBounds. The error occurs on the line indonesiaShape = shp.filter(ee.Filter.eq('ADM2_EN', 'Seruyan')) Where Seruyan is the district I want to filter. I am using Landsat data and the end goal is calculate the water level in this district at a particular point in time.

I want to to filterBounds by district contained in the shapefile and then I want to filter the bounds for the district of Seruyan, contained within the ADM2_EN feature of the shapefile and then calculate the water level before and after a period in time using LandSat data after cleaning the data for cloud coverage etc – I was almost sure my code would work, but I can't quite pinpoint my mistake.

The code is here:

var Polygon: Table users/Admin1/ShapeFileIndoDistricts_Good
var text = require('users/gena/packages:text'); 
var shp = ee.FeatureCollection(polygon)
Map.addLayer(shp,{},'My Polygon')

var scale =Map.getScale()* 1 



var labels = polygon.map(function(feat) {
  feat=ee.Feature(feat)
  var name = ee.String(feat.get("ADM2_EN"))
  var centroid = feat.geometry().centroid()
  var t = text.draw(name, centroid, scale, {
    fontSize:12, 
    textColour: 'red',
    outlineWidth: 0.5, 
    outlineColor: 'red'
  })
  
  return t 
  
})

var labels_final = ee.ImageCollection(labels)

Map.addLayer(labels_final, {}, "Polygon Label")


// Loading Landsat image.
var image = ee.Image(ee.ImageCollection('LANDSAT/LC8_L1T_TOA')

.filterDate('2006-12-19', '2007-01-04')

indonesiaShape = shp.filter(ee.Filter.eq('ADM2_EN', 'Seruyan')); //  
var geometry = indonesiaShape.geometry();
Map.addLayer(geometry);

image.filterBounds(geometry)

Best Answer

As suggested there is a whole bunch of typo mistakes in your example, also the workflow you are trying is pretty flawed. A simple google search will get you to the earth engine documentation: https://developers.google.com/earth-engine/guides/asset_manager

Without access to your asset this is my guess on solving your initial errors:

var text = require('users/gena/packages:text'); 
var shp = ee.FeatureCollection('users/Admin1/ShapeFileIndoDistricts_Good')
Map.addLayer(shp,{},'My Polygon')

var scale =Map.getScale()* 1 

var labels = shp.map(function(feat) {
  feat=ee.Feature(feat)
  var name = ee.String(feat.get("ADM2_EN"))
  var centroid = feat.geometry().centroid()
  var t = text.draw(name, centroid, scale, {
    fontSize:12, 
    textColour: 'red',
    outlineWidth: 0.5, 
    outlineColor: 'red'
  })
  
  return t 
  
})

var labels_final = ee.ImageCollection(labels)

Map.addLayer(labels_final, {}, "Polygon Label")


// Loading Landsat image.
var image = ee.Image(ee.ImageCollection('LANDSAT/LC8_L1T_TOA')

.filterDate('2006-12-19', '2007-01-04').first())

indonesiaShape = shp.filter(ee.Filter.eq('ADM2_EN', 'Seruyan')); //  
var geometry = indonesiaShape.geometry();
Map.addLayer(geometry);

image.filterBounds(geometry)
Related Question