1

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)
3
  • Welcome to GIS SE. As a new user, please take the Tour, which emphasizes the importance of asking One question per Question. Please Edit the Question to focus on one issue.
    – Vince
    Mar 24, 2022 at 1:14
  • Please make sure your script is complete and executable. Share any assets you're using. Currently, the error is probably due to syntax error in your code. A parenthesis isn't closed, and indonesiaShape isn't prefixed with var (Maybe that is done in a part of your script not shared here?). Mar 24, 2022 at 7:23
  • How can I share the assets on here? the shapefile is given by var Polygon: Table users/Admin1/ShapeFileIndoDistricts_Good. Any help would be appreciated
    – dingdam
    Mar 24, 2022 at 9:14

1 Answer 1

2

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.