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)
indonesiaShape
isn't prefixed withvar
(Maybe that is done in a part of your script not shared here?).