The Geo-ICT Blog

Tutorials/Post – ICT, GIS, Remote Sensing, Earth System, Humanitarian, Disaster Management, Travel

Filter a Feature Collection by attribute in Google Earth Engine

The full source code for the same can be found here.

  1. If you do not have the data yet, you can download it from here. I downloaded the Admin 1 boundary, but this method is generic, so applies to any shapefile that you have.
  2. Open up the QGIS or any other GIS software that you use. Load the shapefile and see the attributes tables to find out about the column name and the list of values that column posses. In the image below: ADM1_NAME is the name of the column and the values underneath eg. Hoa Binh, Thanh Hoa, … are the range of values. Make note of the value(s) that you are interested in.qojazje
  3. Now in Earth Engine, import the assets that you want to filter and display the result to ensure that this is the area that you want to filter. In this tutorial, I show you how you can upload your shapefile to the Earth Engine asset.
    var vietnam = ee.FeatureCollection('users/biplov/blog/vietnam_admin1');
    Map.centerObject(vietnam);
    Map.addLayer(vietnam, {color: 'red'}, 'vietnam');
    
  4. We will use ee.Filter objects and the associated method to do the filtering, in particular for this exercise we will use ee.Filter.inList method. From step 1, we have two areas of interests. Lets filter to those areas.
    var filter = ee.Filter.inList('ADM1_NAME', ['Hoa Binh', 'Thanh Hoa']);
    var filteredArea = vietnam.filter(filter);
    Map.addLayer(filteredArea, {color: 'green'}, 'filteredArea');
    

Previous

Uploading a shapefile to Google Earth Engine

Next

Point sampling in Google Earth Engine

1 Comment

  1. Matthew

    fantastic, I have finally been able to filter my featureCollection import now! thanks

Leave a Reply

Powered by WordPress & Theme by Anders Norén

%d bloggers like this: