CODE
CODE
ui.Panel([app.filters.selectExtent,app.filters.applyButton],ui.Panel.Layout.flow('h
orizontal'))
],
style: app.SECTION_STYLE
});
app.filters.selectExtent.setValue(app.filters.selectExtent.items().get(0));
/* The visualization section. */
app.vis = {
label: ui.Label(),
// Create a select with a function that reacts to the "change" event.
select: ui.Select({
items: Object.keys(app.VIS_OPTIONS),
onChange: function() {
// Update the label's value with the select's description.
var option = app.VIS_OPTIONS[app.vis.select.getValue()];
app.vis.label.setValue(option.description);
// Refresh the map layer.
app.refreshMapLayer();
}
}),
LeeOption: ui.Checkbox({
label: 'Aplicar filtro Lee',
value: false,
onChange: function() {
// Refresh the map layer.
app.applyFilters();
}
}),
QueganOption: ui.Checkbox({
label: 'Aplicar filtro temporal',
value: false,
onChange: function() {
// Refresh the map layer.
app.applyFilters();
}
})
};
/* The panel for the visualization section with corresponding widgets. */
app.vis.panel = ui.Panel({
widgets: [
ui.Label('Selecione um tipo de visualiza��o', {fontWeight: 'bold'}),
app.vis.select,
app.vis.label,
app.vis.LeeOption,
app.vis.QueganOption
],
style: app.SECTION_STYLE
});
// Default the select to the first value.
app.vis.select.setValue(app.vis.select.items().get(4));
// Base de referencia
app.baseg = {
chkProdes2016: ui.Checkbox({
label: 'Prodes at� 2016',
value: false,
onChange: function(checked) {
Map.layers().get(1).setShown(checked)
app.VIS_BASE.l1=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
chkProdes2017: ui.Checkbox({
label: 'Prodes 2017 (definitivo)',
value: false,
onChange: function(checked) {
Map.layers().get(2).setShown(checked)
app.VIS_BASE.l2=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
chkUCs: ui.Checkbox({
label: 'Unidades de Conserva��o Federais',
value: false,
onChange: function(checked) {
Map.layers().get(3).setShown(checked)
app.VIS_BASE.l3=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
chkTIS: ui.Checkbox({
label: 'Terras Ind�genas',
value: false,
onChange: function(checked) {
Map.layers().get(4).setShown(checked)
app.VIS_BASE.l4=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
chkMUN: ui.Checkbox({
label: 'Municipios PA/MT',
value: false,
onChange: function(checked) {
Map.layers().get(5).setShown(checked)
app.VIS_BASE.l5=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
chkASS: ui.Checkbox({
label: 'Assentamentos INCRA',
value: false,
onChange: function(checked) {
Map.layers().get(6).setShown(checked)
app.VIS_BASE.l6=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
chkL8: ui.Checkbox({
label: 'Mosaico Landsat 8 do periodo',
value: false,
onChange: function(checked) {
Map.layers().get(7).setShown(checked)
app.VIS_BASE.l7=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
chkGrid: ui.Checkbox({
label: 'Malha de referencia',
value: false,
onChange: function(checked) {
Map.layers().get(8).setShown(checked)
app.VIS_BASE.l8=checked;
// Refresh the map layer.
//app.refreshMapLayer();
}
}),
labelCreditos: ui.Label('Juan Doblas, Instituto Socioambiental, 2017',
{fontSize:'small'})
}
app.baseg.panel = ui.Panel({
widgets:[
ui.Label('Base de referencia', {fontWeight: 'bold'}),
app.baseg.chkProdes2016,
app.baseg.chkProdes2017,
app.baseg.chkUCs,
app.baseg.chkTIS,
app.baseg.chkMUN,
app.baseg.chkASS,
app.baseg.chkL8,
app.baseg.chkGrid,
app.baseg.labelCreditos
],
style: app.SECTION_STYLE
});
/* The export section. */
app.export = {
ebutton: ui.Button({
label: 'Exportar o mosaico como imagem',
// React to the button's click event.
onClick: function() {
// Get the visualization options.
var visOption = app.VIS_OPTIONS[app.vis.select.getValue()];
// Export the image to GCS.
Export.image.toDrive({
image: stack.visualize(visOption.visParams),
description: 'sentinel1_mosaico_multitemporal_AREA_PERIODO',
scale: 10,
maxPixels:2512890090
})
}
}),
ebutton2: ui.Button({
label: 'Exportar o mosaico como tiles',
// React to the button's click event.
onClick: function() {
// Get the visualization options.
var visOption = app.VIS_OPTIONS[app.vis.select.getValue()];
// Export map to GCS.
Export.map.toCloudStorage({
image: stack.visualize(visOption.visParams),
description: 'sentinel1_mosaico_multitemporal_AREA_PERIODO',
bucket: 'rmtx',
minZoom:4,
maxZoom:15,
fileFormat: 'png'
})
}
}),
// ebutton3: ui.Button({
// label: 'Exportar poligonos como kml',
// // React to the button's click event.
// onClick: function() {
// // Export polygons
// Export.table.toDrive({
// collection: geometry,
// description:'poligonos_mapeados_AREA_DATA',
// fileFormat: 'KML'
// });
// }
// }),
// ebutton4: ui.Button({
// label: 'Duplicar mosaico atual (avan�ado)',
// // React to the button's click event.
// onClick: function() {
// var stackAux=stack
// var visOption = app.VIS_OPTIONS[app.vis.select.getValue()];
// Map.addLayer(stackAux, visOption.visParams, 'Camada auxiliar');
// }
// }),
};
stack=im1vv.addBands(im2vv).addBands(im3vv).addBands(im1vh).addBands(im2vh).addBand
s(im3vh)
if (app.vis.LeeOption.getValue()){stack=stack_lee}
stack=stack.select([0,1,2,3,4,5],['p1vv','p2vv','p3vv','p1vh','p2vh','p3vh'])
// Get Landsat-8 for comparation purposes
var
l8col=ee.ImageCollection('LANDSAT/LC08/C01/T1_RT_TOA').filterBounds(Map.getBounds(t
rue)).filterDate(t1v1,t3v2).sort('CLOUD_COVER',false);
l8melhorCena=ee.Image(l8col.mosaic())
//var datal8 = ee.Date(l8melhorCena.get('system:time_start'));
//print('Data melhor imagem Landsat: ', datal8); // ee.Date
var vizParams = {
bands: ['B6', 'B5', 'B4'],
min: 0.01,
max: 0.5,
gamma: [0.95, 1.1, 1]}
var vizParamsB8 = {
bands: ['B8'],
min: 0.01,
max: 0.25,
gamma: [1.3]}
// Computes mapping aid grid
gridLines=createGrid(app.gridScale,ee.Feature(Map.getBounds(true)).buffer(app.gridS
cale).geometry())
// Redisplay everything
app.refreshMapLayer();
};
/** Refreshes the current map layer based on the UI widget states. */
app.refreshMapLayer = function() {
Map.clear();
var visOption = app.VIS_OPTIONS[app.vis.select.getValue()];
Map.addLayer(stack, visOption.visParams, 'Composite RGB');
Map.addLayer(ee.Image("users/juandb/SIRAD_DATA/PRODES_desmatAcumulado_2016"),
{},'Prodes 2016',app.VIS_BASE.l1)
Map.addLayer(ee.FeatureCollection("users/juandb/SIRAD_DATA/PRODES_definitivo_2017")
,{},'Prodes 2017',app.VIS_BASE.l2)
Map.addLayer(ee.Image().toByte().paint(ee.FeatureCollection(app.FT_UCS), 1, 3),
{"palette":["009b2f"]},'Unidades de Conserva��o',app.VIS_BASE.l3)
Map.addLayer(ee.Image().toByte().paint(ee.FeatureCollection(app.FT_TIS), 1, 3),
{"palette":["e59f12"]},'Terras Ind�genas',app.VIS_BASE.l4)
Map.addLayer(ee.Image().toByte().paint(ee.FeatureCollection(app.FT_MUN), 1, 1),
{"palette":["9212a5"]},'Munic�pios',app.VIS_BASE.l5)
Map.addLayer(ee.Image().toByte().paint(ee.FeatureCollection(app.FT_ASS), 1, 2),
{"palette":["1153a3"]},'Assentamentos',app.VIS_BASE.l6)
Map.addLayer(ee.Image(l8melhorCena),app.VIS_OPTIONS_L8,'Mosaico L8',
app.VIS_BASE.l7)
Map.addLayer(gridLines ,{'palette': '000000', 'opacity': 0.5},"Malha de
referencia",app.VIS_BASE.l8);
//Map.addLayer(ee.Image(l8melhorCena),app.VIS_OPTIONS_L8B8,'Cena L8B8', false
};
}
};
/** Creates the application interface. */
app.boot = function() {
app.createConstants();
app.createHelpers();
app.createPanels();
var main = ui.Panel({
widgets: [
app.intro.panel,
app.filters.panel,
app.vis.panel,
app.export.panel,
app.baseg.panel
],
style: {width: '320px', padding: '8px'}
});
Map.setCenter(LongInicial, LatInicial, ZoomInicial);
ui.root.insert(0, main);
app.applyFilters();
};
app.boot();
function toDB(img) {
return ee.Image(img).log10().multiply(10.0).copyProperties(img,
['system:time_start','sliceNumber']);
}
function toNatural(img) {
return ee.Image(10.0).pow(img.select(0).divide(10.0)).copyProperties(img,
['system:time_start','sliceNumber']);
}
function toGamma0(img) {
return
img.select(0).subtract(img.select(1).multiply(Math.PI/180.0).cos().log10().multiply
(10.0));
}
// Fun��o para calcular ENL em uma imagem S1, sobre uma area de referencia AOI
function computeENLS1(S1img,AOI){
// This function computes ENL index on Sentinel-1 bands.
// It will take in account only the first band
S1img=ee.Image(S1img)
S1img=S1img.select([0],['band'])
var mean=ee.Number(S1img.reduceRegion(ee.Reducer.mean(),AOI,20).get('band'))
var std=ee.Number(S1img.reduceRegion(ee.Reducer.stdDev(),AOI,20).get('band'))
return (mean.divide(std)).pow(2)
}
// Fun��o para filtrar uma cole�a� seguindo a metodologia de Quagan&Yu, 2001
// Importante: a cole��o deve estar em numeros naturais. N=tamanho do filtro
espacial
function QueganYuFilter(imgCol,N){
// This function will return a filtered collection
// the filter is the proposed by Quegan&Yu (2011),
// Warning: will only work on single scene time series on natural. No mosaics
(for now), no DB
var boxcar = ee.Kernel.square({radius: N, units: 'pixels', normalize: false});
var imgColMedian = imgCol.map(function(img){return img.convolve(boxcar)})
var correctionFactorCol=imgCol.map(function(img){return
img.divide(img.convolve(boxcar))})
var numberofsamples=imgCol.map(function(img){return img.divide(img)}).sum()
var correctionFactor=correctionFactorCol.sum().divide(numberofsamples)
return imgColMedian.map(function(img){return
img.multiply(correctionFactor).copyProperties(img,
['system:time_start','sliceNumber'])})
}
function extractDates(col){
var datesList=ee.List(col.aggregate_array('system:time_start'));
var datesListFmt=datesList.map(formatDate)
return datesListFmt
}
function formatDate(date){
return ee.Date(date).format('YYYY-MM-dd')
}
function maskEdge(img) {
var mask = img.select(0).unitScale(-25,
5).multiply(255).toByte().connectedComponents(ee.Kernel.rectangle(1,1), 100);
return img.updateMask(mask.select(0));
}
// Use a sample of the 3x3 windows inside a 7x7 windows to determine gradients
and directions
var sample_weights = ee.List([[0,0,0,0,0,0,0], [0,1,0,1,0,1,0],[0,0,0,0,0,0,0],
[0,1,0,1,0,1,0], [0,0,0,0,0,0,0], [0,1,0,1,0,1,0],[0,0,0,0,0,0,0]]);
// Calculate mean and variance for the sampled windows and store as 9 bands
var sample_mean = mean3.neighborhoodToBands(sample_kernel);
var sample_var = variance3.neighborhoodToBands(sample_kernel);
// Create a mask for band pixels that are the maximum gradient
var gradmask = gradients.eq(max_gradient);
// "collapse" the stack into a singe band image (due to masking, each pixel has
just one value (1-8) in it's directional band, and is otherwise masked)
directions = directions.reduce(ee.Reducer.sum());
//var pal = ['ffffff','ff0000','ffff00', '00ff00', '00ffff', '0000ff', 'ff00ff',
'000000'];
//Map.addLayer(directions.reduce(ee.Reducer.sum()), {min:1, max:8, palette: pal},
'Directions', false);
// Calculate localNoiseVariance
var sigmaV =
sample_stats.toArray().arraySort().arraySlice(0,0,5).arrayReduce(ee.Reducer.mean(),
[0]);
// Create stacks for mean and variance using the original kernels. Mask with
relevant direction.
var dir_mean = img.reduceNeighborhood(ee.Reducer.mean(),
rect_kernel).updateMask(directions.eq(1));
var dir_var = img.reduceNeighborhood(ee.Reducer.variance(),
rect_kernel).updateMask(directions.eq(1));
dir_mean = dir_mean.addBands(img.reduceNeighborhood(ee.Reducer.mean(),
diag_kernel).updateMask(directions.eq(2)));
dir_var = dir_var.addBands(img.reduceNeighborhood(ee.Reducer.variance(),
diag_kernel).updateMask(directions.eq(2)));
// "collapse" the stack into a single band image (due to masking, each pixel has
just one value in it's directional band, and is otherwise masked)
dir_mean = dir_mean.reduce(ee.Reducer.sum());
dir_var = dir_var.reduce(ee.Reducer.sum());
var b = varX.divide(dir_var);