TransWikia.com

How to convert a shapefile (shp) to raster via GEE

Geographic Information Systems Asked by wesleysc352 on February 2, 2021

I would like to convert a shp to raster via GEE. My SHP has several polygons, which have a value between 1 and 2 in the attribute table.

I would like the output raster to assume values 1 and 2 according to the value of the polygons.

I know there is a "toReduce" command, but I didn’t understand how to do that, even with the tutorial provided by Google.

Context

I would like to add a mask for an image rating. In this shp, the value 1 would be ignored by the classifier.

One Answer

Using a raster as a mask to apply to your source image is the best way to do it so that the results are quick. Earth Engine works best when dealing with data in ImageSpace.

To mask pixels that are contained within a shapefile this is the process that I would use.

// This is an image with just 1.  You use it to build your mask.    
var myImage = ee.Image.constant(1);

// This would be your shape file. (had to create it from a bogus geometry to test it.    
var myFeature = ee.Feature(geometry);
    
// here you create an image that is a mask from your features.
var newImage = myImage.clip(myFeature).mask().not();
    
Map.addLayer(newImage,{},"maskToApply");
    
// Using the mask from above, you update the mask of the source Image 
// I use the image of constants created above for an example
var exitImage = myImage.updateMask(newImage);
    
// When added to the map, you can see that the image has a new mask, where all pixels that are within the polygons are masked.
Map.addLayer(myImage, {},"Original Image");
Map.addLayer(exitImage,{}, "Exit Image");

PS: Kudos on this goes to Rodrigo E. Principe who wrote the code that I inspired myself from here: Masking pixels inside the polygons using Google Earth Engine?

Answered by Sean Roulet on February 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP