3 min read

Clipping image collections to shapefile with Google Earth Engine ๐ŸŒŒ

Clipping image collections to shapefile with Google Earth Engine ๐ŸŒŒ
Photo by Shubham Rawat / Unsplash

One of the most challenging aspects of Google Earth Engine is managing the size of image collections. Remotely sensed images, by nature, are large. But what if you want to clip images so they are smaller and concentrated within a study area?

To solve this problem I've put together a script you can find here:

GitHub - ShrimpandGits/gee-custom-area-clip: A script to load in a shapefile and clip image collection to that shape exporting to google drive
A script to load in a shapefile and clip image collection to that shape exporting to google drive - GitHub - ShrimpandGits/gee-custom-area-clip: A script to load in a shapefile and clip image colle...

Import Data

For this experiment I've decide to use the Consistent And Corrected Nighttime Light Dataset. You can learn more about the dataset on the google earth engine page here.

the data catalog page for google earth engine

For my clipping shape, I've deiced to use county line shapefile from data.gov. My goal is to use this data for future analysis once cut down and once I have a shapefile loaded.

Data.gov shapefile page

To add my shapefile to Earth Engine, I first had to upload it as an asset by clicking the "New" button in the asset pannel of the code editor.

Once loaded, then creating a variable that holds the value of the shapefile (brought in as a table)

Once loaded, I added a few more lines to visualize the dataset a bit more clearly.

Clipping โœ‚

Clipping the dataset is done with the two following lines of code:

The first line, clips the dataset using the the table variable. The second line ย converst the table to a feature collection so it can be loaded to the map if so desired.

var image=dataset.first().clip(table)
var counties = ee.FeatureCollection(table);

Exporting & Uses

a bit more code is needed if you want to export the clipped image to be used in another software such as QGIS.

This dataset was processed using the zonal statistics plugin in QGIS to create average values for each of the counties for light in each.

I used this as a reference to export my ย dataset after running into issues with exporting data because of the size of my clipping shapefile. If you run into hanging exports, you might look into this solution:

Earth Engine payload request exceeded on export
I am trying to export MOD13A2 data from Earth Engine. Export attempts have resulted in payload errors consistently, even after chipping away at the data volume. I tried removing clipping elements o...