Kamal Hosen
Kamal Hosen
Geospatial Developer | Data Science | Python

Apr 09, 2023

How to Count Total Number of Features in Vector Data in Earth Engine?

/media/article-img/count.jpg

In Earth Engine, the number of features in a FeatureCollection can be obtained using the .size() method. Here, we will count the number of total features in the TIGER states feature collection.

// Load a feature collection.
var fc = ee.FeatureCollection('TIGER/2018/States');

// Count total number of features in feature collection.
var count = fc.size();

// Print the number to the console.
print(count)

This will return the number of features as an integer.

 

Alternatively, you can use the ee.FeatureCollection function to create a new FeatureCollection from an existing collection and use the aggregate_count() function to get the count of features. For example:

var count = ee.FeatureCollection(fc).aggregate_count('.all');
print(count)

 

Share To

About Author
  • Kamal Hosen
  • Kamal Hosen
    Geospatial Developer | Data Science | Python

    A passionate geospatial developer and analyst whose core interest is developing geospatial products/services to support the decision-making process in climate change and disaster risk reduction, spatial planning process, natural resources management, and land management sectors. I love learning and working with open source technologies like Python, Django, LeafletJS, PostGIS, GeoServer, and Google Earth Engine.