I want to save each image of this collection into my drive.
var filtered_Image=ee.ImageCollection('LANDSAT/LC8_L1T_TOA')
.filter(ee.Filter.eq('WRS_PATH', 138))
.filter(ee.Filter.eq('WRS_ROW', 45))
.filterMetadata('CLOUD_COVER','less_than',20)
.filterDate('2017-01-01', '2017-06-31')
.select(['B2', 'B3', 'B4']);
Try this
choose your geometry/point of interest from imports.
var batch = require('users/fitoprincipe/geetools:batch');
var filtered_Image=ee.ImageCollection('LANDSAT/LC8_L1T_TOA')
.filterBounds(POI)
.filter(ee.Filter.eq('WRS_PATH', 138))
.filter(ee.Filter.eq('WRS_ROW', 45))
.filterMetadata('CLOUD_COVER','less_than',20)
.filterDate('2017-01-01', '2019-12-31')
.select(['B2', 'B3', 'B4']);
Map.setCenter(88, 21, 7);
var vizParams = {
bands: ['B2', 'B3', 'B4'],
min: 0,
max: 0.5,
gamma: [0.95, 1.1, 1]
};
Map.addLayer (filtered_Image.first(), vizParams, 'false color composite')
batch.Download.ImageCollection.toDrive(filtered_Image, 'Landsat8', {
name: 'filtered_Image_{system:index}',
type: 'float',
scale: 30,
region: POI
});
Related
I've had this error in Google Earth Engine. I'm trying to account for sunglint off the ocean as I attempt to map seagrass.
Here is my code.
The error is happening when I try to run the Sunglint Corrected map layer. I've tried changing the max number of pixels but to no avail. I've also tried setting best effort to true, but this hasn't helped either which is extremely unfortunate. Please help!
var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2021-05-01', '2021-09-30')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
.filterBounds(roi)
.select(['B2','B3','B4','B1', 'B8']);
var rgbVis = {
min: 0.0,
max: 1000,
bands: ['B3', 'B2', 'B4'],
};
Map.addLayer(dataset, rgbVis, 'Filtered Collection');
var mosaic = dataset.mosaic();
var medianComposite = dataset.min();
Map.addLayer(medianComposite, rgbVis, 'Median Composite', 0);
var hansenImage = ee.Image('UMD/hansen/global_forest_change_2015');
var datamask = hansenImage.select('datamask');
var mask = datamask.eq(2);
var maskedComposite = medianComposite.updateMask(mask);
Map.addLayer(maskedComposite, rgbVis, 'masked');
Map.addLayer(maskedComposite, {
bands: ['B4', 'B3', 'B2',],
min: 0,
max: 1000
}, 'BOA');
var B2 = maskedComposite.select(['B8', 'B2']);
var B3 = maskedComposite.select(['B8', 'B3']);
var B4 = maskedComposite.select(['B8', 'B4']);
var lfitB2 = B2.reduceRegion({
reducer: ee.Reducer.linearFit(),
geometry: glint,
scale: 10,
//maxPixels: 1000,
//bestEffort: true
});
var lfitB3 = B3.reduceRegion({
reducer: ee.Reducer.linearFit(),
geometry: glint,
scale: 10,
});
var lfitB4 = B4.reduceRegion({
reducer: ee.Reducer.linearFit(),
geometry: glint,
scale: 10,
});
//print('B2 OLS estimates:', lfitB2);
//print('B2 y-intercept:', lfitB2.get('offset'));
//print('B2 Slope:', lfitB2.get('scale'));
//print('B3 Slope:', lfitB3.get('scale'));
//print('B4 Slope:', lfitB4.get('scale'));
var slope_B2 = ee.Image.constant(lfitB2.get('scale')).clip(roi).rename('slope_B2');
var slope_B3 = ee.Image.constant(lfitB3.get('scale')).clip(roi).rename('slope_B3');
var slope_B4 = ee.Image.constant(lfitB4.get('scale')).clip(roi).rename('slope_B4');
var min_B8 = ee.Image.constant(maskedComposite.select('B8').reduceRegion(ee.Reducer.min(),roi, 3).get('B8')).rename('min_B8');
var glint_factors = ee.Image([slope_B2, slope_B3, slope_B4, min_B8]);
var S2 = maskedComposite.addBands(glint_factors);
/*var deglint_B2 = S2.select('B8').subtract(min_B8);
var deglint_B2 = slope_B2.multiply(deglint_B2);
var deglint_B2 = S2.select('B2').subtract(deglint_B2);
Map.addLayer(deglint_B2);*/
var deglint_B2 = S2.expression(
'Blue - (Slope * (NIR - MinNIR))', {
'Blue': S2.select('B2'),
'NIR': S2.select('B8'),
'MinNIR': S2.select('min_B8'),
'Slope': S2.select('slope_B2')
}).rename('B2');
var deglint_B3 = S2.expression(
'Green - (Slope * (NIR - MinNIR))', {
'Green': S2.select('B3'),
'NIR': S2.select('B8'),
'MinNIR': S2.select('min_B8'),
'Slope': S2.select('slope_B3')
}).rename('B3');
var deglint_B4 = S2.expression(
'Red - (Slope * (NIR - MinNIR))', {
'Red': S2.select('B4'),
'NIR': S2.select('B8'),
'MinNIR': S2.select('min_B8'),
'Slope': S2.select('slope_B4')
}).rename('B4');
var S2_deglint = ee.Image([deglint_B2, deglint_B3, deglint_B4]);
Map.addLayer(S2_deglint, {
bands: ['B4', 'B3', 'B2'],
min: 0.0,
max: 0.2
}, 'Sunglint Corrected');
var linkedMap = ui.Map();
Map.addLayer(S2, {
bands: ['B4', 'B3', 'B2'],
min: 0.0,
max: 0.15,
}, 'Top-of-Atmosphere Reflectance');
Map.addLayer(S2_deglint, {bands: ['B4', 'B3', 'B2'], min: 0.0, max: 1000, scale: 1}, 'Sunglint Corrected');
var linker = ui.Map.Linker([ui.root.widgets().get(0), linkedMap]);
To explain better what I need, think about a tank and a can of soda.
No matter what the speed of that can of soda would be, the tank wouldn't move if it's hit.
But the tank should be able to move when force is applied to it.
Already opened an issue here with more details:
https://github.com/liabru/matter-js/issues/841
And I also made an example here for what I need.
var Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Bodies = Matter.Bodies,
Body = Matter.Body;
var engine = Engine.create();
engine.positionIterations = 10;
engine.velocityIterations = 8;
var render = Render.create({
element: document.body,
engine: engine,
options: {
width: 800,
height: 400,
wireframes: false
}
});
engine.world.gravity.y = 0;
var topWall = Bodies.rectangle(400, 50, 720, 20, { isStatic: true });
var leftWall = Bodies.rectangle(50, 210, 20, 300, { isStatic: true });
var rightWall = Bodies.rectangle(750, 210, 20, 300, { isStatic: true });
var bottomWall = Bodies.rectangle(400, 350, 720, 20, { isStatic: true });
var ball = Bodies.circle(100, 200, 5, {
friction: 0.05,
frictionAir: 0.05,
density: 0.001,
restitution: 0.2
});
var bigBox = Matter.Bodies.rectangle(500, 200, 120, 120, {
inertia: Infinity,
frictionAir: 1,
friction: 1,
density: 0.1
});
World.add(engine.world, [topWall, leftWall, rightWall, bottomWall, ball, bigBox]);
Engine.run(engine);
Render.run(render);
// CMD + SHIFT + 7 to reload
$('.shoot').on('click', function () {
var speed = 0.02;
var angle = 0;
let vector = Matter.Vector.create(Math.cos(angle) * speed, Math.sin(angle) * speed);
Body.applyForce(ball, ball.position, vector);
});
https://codepen.io/dmerlea/pen/BaoQJYK
Edit: Working solution.
(Works with the changes made by DevBab).
Extra: added an option to style the Polygon. (var polyStyle)
var url = 'http://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.json' +
'?app_id='+ app_id +
'&app_code=' + app_code +
'&prox=' + lat +','+ lng +',1000' +
'&mode=retrieveAddresses&maxresults=1' +
'&level=county'+
'&additionaldata=IncludeShapeLevel,county';
$.getJSON(url,function (data) {
var location = data.Response.View[0].Result[0].Location;
var wktShape = location.Shape.Value;
var polyStyle = {
strokeColor: 'red',
fillColor: 'rgba(255, 255, 255, 0.3',
lineWidth: 2
};
var geoPoint = H.util.wkt.toGeometry(wktShape);
map.addObject(new H.map.Polygon(geoPoint,{style:polyStyle}));
});
You are creating a polygon, not a marker, so modify this:
map.addObject(new H.map.Marker(geoPoint));
by that:
map.addObject(new H.map.Polygon(geoPoint));
I am trying to change color of destination waypoint to green from red. Currently following the code from example:
Google waypoints
I googled, but could not find answer.
Many thanks in advance.
I'm afraid you can't.
What you can do is pass the google.maps.DirectionsRenderer an options object to disable markers altogether
var DirectionsRenderer= new google.maps.DirectionsRenderer({map:map, suppressMarkers: true});
and then add your custom markers yourself using the location of the origin and destination that you passed to the google.maps.DirectionsService instance.
proof of concept fiddle
// global variables to keep the start and end locations
var startLocation = {};
var endLocation = {};
Parse the directions response, putting a custom marker at the start and end of the route
var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
var summaryPanel = document.getElementById('directions_panel');
summaryPanel.innerHTML = '';
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i + 1;
summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment + '</b><br>';
summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
}
var path = response.routes[0].overview_path;
var legs = response.routes[0].legs;
for (i = 0; i < legs.length; i++) {
if (i == 0) {
startLocation.latlng = legs[i].start_location;
startLocation.address = legs[i].start_address;
createMarker(legs[i].start_location, "start", legs[i].start_address, "green");
}
endLocation.latlng = legs[i].end_location;
endLocation.address = legs[i].end_address;
}
}
createMarker(endLocation.latlng, "end", endLocation.address, "red");
custom marker functions (you can simplify this if you only need 2 markers):
var icons = [];
icons["red"] = {
url: 'http://maps.google.com/mapfiles/ms/micons/red.png',
// This marker is 34 pixels wide by 34 pixels tall.
size: new google.maps.Size(34, 34),
// The origin for this image is 0,0.
origin: new google.maps.Point(0, 0),
// The anchor for this image is at 9,34.
anchor: new google.maps.Point(17, 34)
};
function getMarkerImage(iconColor) {
if ((typeof (iconColor) == "undefined") || (iconColor == null)) {
iconColor = "red";
}
if (!icons[iconColor]) {
icons[iconColor] = {
url: "http://maps.google.com/mapfiles/ms/micons/" + iconColor + ".png",
// This marker is 34 pixels wide by 34 pixels tall.
size: new google.maps.Size(34, 34),
// The origin for this image is 0,0.
origin: new google.maps.Point(0, 0),
// The anchor for this image is at 6,20.
anchor: new google.maps.Point(17, 34)
};
}
return icons[iconColor];
}
// Marker sizes are expressed as a Size of X,Y
// where the origin of the image (0,0) is located
// in the top left of the image.
// Origins, anchor positions and coordinates of the marker
// increase in the X direction to the right and in
// the Y direction down.
var iconImage = {
url: 'http://maps.google.com/mapfiles/ms/micons/red.png',
// This marker is 20 pixels wide by 34 pixels tall.
size: new google.maps.Size(20, 34),
// The origin for this image is 0,0.
origin: new google.maps.Point(0, 0),
// The anchor for this image is at 9,34.
anchor: new google.maps.Point(9, 34)
};
// Shapes define the clickable region of the icon.
// The type defines an HTML <area> element 'poly' which
// traces out a polygon as a series of X,Y points. The final
// coordinate closes the poly by connecting to the first
// coordinate.
var iconShape = {
coord: [9, 0, 6, 1, 4, 2, 2, 4, 0, 8, 0, 12, 1, 14, 2, 16, 5, 19, 7, 23, 8, 26, 9, 30, 9, 34, 11, 34, 11, 30, 12, 26, 13, 24, 14, 21, 16, 18, 18, 16, 20, 12, 20, 8, 18, 4, 16, 2, 15, 1, 13, 0],
type: 'poly'
};
var infowindow = new google.maps.InfoWindow({
size: new google.maps.Size(150, 50)
});
function createMarker(latlng, label, html, color) {
var contentString = '<b>' + label + '</b><br>' + html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: getMarkerImage(color),
shape: iconShape,
title: label,
zIndex: Math.round(latlng.lat() * -100000) << 5
});
marker.myname = label;
gmarkers.push(marker);
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(contentString);
infowindow.open(map, marker);
});
}
I need to draw a square polygon of 100x100 screenpixels whereever I click on the Google map (Amsterdam, lat 52, lng 4), on every zoomlevel, with e.latlng at the center of the polygon. I tried to figure it out using fromLatLngToPoint, fromPointToLatLng, scale and worldCoordinates, but I can't get the polygon drawn. If someone likes this puzzle I would appreciate the solution very much.
(I want to use this as a simple start to edit the polygon to a more complex shape, not using the DrawingManager)
I tried:
google.maps.event.addListener(map, 'click', function(e) {
var scale = Math.pow(2, map.getZoom());
var nw = new google.maps.LatLng(map.getBounds().getNorthEast().lat(),map.getBounds().getSouthWest().lng());
var worldCoordinateNW = map.getProjection().fromLatLngToPoint(nw);
var worldCoordinate = map.getProjection().fromLatLngToPoint(e.latLng);
var deX = Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale);
var deY = Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale);
// so far so good, deX and deY give the centerpixel
var deNW = map.getProjection().fromPointToLatLng(new google.maps.Point(deX-50,deY-50));
var deNO = map.getProjection().fromPointToLatLng(new google.maps.Point(deX+50,deY-50));
var deZO = map.getProjection().fromPointToLatLng(new google.maps.Point(deX+50,deY+50));
var deZW = map.getProjection().fromPointToLatLng(new google.maps.Point(deX-50,deY+50));
var dePathArray = [deNW, deNO, deZO, deZW];
deObjectNew = new google.maps.Polygon({
paths: dePathArray,
strokeColor: '#000000',
strokeWeight: 1,
fillColor: "#FF0000",
fillOpacity: 0.3,
});
deObjectNew.setMap(map);
});
Got it:
var deNW = deKaart.getProjection().fromPointToLatLng(new google.maps.Point((deX-50)/scale+worldCoordinateNW.x,(deY-50)/scale+worldCoordinateNW.y));
var deNO = deKaart.getProjection().fromPointToLatLng(new google.maps.Point((deX+50)/scale+worldCoordinateNW.x,(deY-50)/scale+worldCoordinateNW.y));
var deZO = deKaart.getProjection().fromPointToLatLng(new google.maps.Point((deX+50)/scale+worldCoordinateNW.x,(deY+50)/scale+worldCoordinateNW.y));
var deZW = deKaart.getProjection().fromPointToLatLng(new google.maps.Point((deX-50)/scale+worldCoordinateNW.x,(deY+50)/scale+worldCoordinateNW.y));