Tutorials/Post - Remote Sensing, GIS, Earth System, Geo-AI/ML

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

9 Comments

  1. Matthew

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

  2. 席茜

    but when I using the shape i upload to calculate the NDVI ,the label could not be defined as exsiting column .

  3. biplovbhandari

    I cannot access your table. You need to make sure anyone can read it (i.e. public) by going into your asset tab and sharing it.

  4. Akinchan

    Hi Biplov

    Could you help me about display the label/text of a shapefile. I have to display few POI’s city with over raster layer and dont want to show the detailed default base map in GEE.
    Thanks

Leave a Reply

Powered by WordPress & Theme by Anders Norén