I am running a water spread mask of Karnataka, India using SAR imagery (sentinel-1). I want the water classified pixels to be in vector (shapefile) to export them to google drive.. As I am new to coding, I have no idea where to convert into polygon and export..
When I run this code in GEE, its throwing an error saying too many pixels in the region
see image description here
Where can I specify "maxPixels: 1e13" in code??
Here is my code:
// Load region defined by polygon and add it to the map
var roi = ee.Geometry.Polygon(
[[[74.63296789984143, 12.352944150647819],
[76.39078039984143, 10.975770921005301],
[78.19253821234143, 11.708246106171616],
[78.89566321234143, 13.038873400860725],
[77.70913977484143, 14.915124560145125],
[78.01675696234143, 17.740377764381783],
[77.48941321234143, 18.82525833832097],
[75.20425696234143, 17.782228450502235],
[73.62222571234143, 15.931813752920174]]]);
Map.addLayer(roi, {}, 'ROI')
Map.centerObject(roi, 8)
//Load Sentinel-1 SAR collection and filter according to data collection type
var S1 = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterBounds(roi)
.filterDate('2021-09-03','2021-09-027')
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
//Add first image to map to get an idea of what a SAR image looks like
Map.addLayer(S1.first(),{bands: 'VV',min: -18, max: 0}, 'SAR image')
// Filter speckle noise
var filterSpeckles = function(img) {
var vv = img.select('VV') //select the VV polarization band
var vv_smoothed = vv.focal_median(100,'circle','meters').rename('VV_Filtered') //Apply a focal median filter
return img.addBands(vv_smoothed) // Add filtered VV band to original image
}
// Map speckle noise filter across collection. Result is same collection, with smoothed VV band added to each image
S1 = S1.map(filterSpeckles)
//Add speckle filtered image to map to sompare with raw SAR image
Map.addLayer(S1.first(),{bands: 'VV_Filtered',min: -18, max: 0}, 'Filtered SAR image')
//Here we are using -12.7. This is only an approximation and will result in some errors. Try adjusting the
var classifyWater = function(img) {
var vv = img.select('VV_Filtered')
var water = vv.lt(-12.7).rename('Water') //Identify all pixels below threshold and set them equal to 1. All other pixels set to 0
water = water.updateMask(water) //Remove all pixels equal to 0
return img.addBands(water) //Return image with added classified water band
}
//Map classification across sentinel-1 collection and print to console to inspect
S1 = S1.map(classifyWater)
print(S1)
//Make time series of water pixels within region
var ClassChart = ui.Chart.image.series({
imageCollection: S1.select('Water'),
region: roi,
reducer: ee.Reducer.sum(),
scale: 100,
})
.setOptions({
title: 'Inundated Pixels',
hAxis: {'title': 'Date'},
vAxis: {'title': 'Number of Inundated Pixels'},
lineWidth: 2
})
//Set the postion of the chart and add it to the map
ClassChart.style().set({
position: 'bottom-right',
width: '500px',
height: '300px'
});
Map.add(ClassChart)
// Create a label on the map.
var label = ui.Label('Click a point on the chart to show the image for that date.');
Map.add(label);
//Create callbakc function that adds image to the map coresponding with clicked data point on chart
ClassChart.onClick(function(xValue, yValue, seriesName) {
if (!xValue) return; // Selection was cleared.
// Show the image for the clicked date.
var equalDate = ee.Filter.equals('system:time_start', xValue);
//Find image coresponding with clicked data and clip water classification to roi
var classification = ee.Image(S1.filter(equalDate).first()).clip(roi).select('Water');
var SARimage = ee.Image(S1.filter(equalDate).first());
//Make map layer based on SAR image, reset the map layers, and add this new layer
var S1Layer = ui.Map.Layer(SARimage, {
bands: ['VV'],
max: 0,
min: -20
});
Map.layers().reset([S1Layer]);
var visParams = {
min: 0,
max: 1,
palette: ['#FFFFFF','#0000FF']
}
//Add water classification on top of SAR image
Map.addLayer(classification,visParams,'Water')
// Show a label with the date on the map.
label.setValue((new Date(xValue)).toUTCString());
});