Clipping image collections to shapefile with Google Earth Engine ๐
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:
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.
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.
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: