Why I can't get correct value when used proj4js's method transform() (wgs84 -> utm-k) - data-conversion

I want to get correct value transform in proj4js.
coordinate converted value wgs84 (EPSG:4326) -> utm-k (EPSG:5179)
I tried to get coordinate converted value but i couldn't get correct value.
But other convert values were correct.
Coordinate is 제주도청 in korea.
Correct value :
wgs84 (lat = 33.48900054, lon = 126.4982831) -> utm-k (906941.5, 1500134.1)
Incorrect value :
wgs84 (lat = 33.48900054, lon = 126.4982831) -> utm-k (5252601.193315057, 7146101.943385382)
Why can't get correct value when used proj4js to convert wgs84 -> utm-k.
My source :
Proj4js.defs["EPSG:5179"] = "+proj=tmerc +lat_0=38 +lon_0=127.5 +k=0.9996 +x_0=1000000 +y_0=2000000 +ellps=GRS80 +units=m +no_defs";
Proj4js.defs["EPSG:5186"] = "+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000 +ellps=GRS80 +units=m +no_defs";
var projWGS84 = new OpenLayers.Projection("EPSG:4326");
// projection for UTM-K
var projUTMK = new OpenLayers.Projection("EPSG:5179");
var point_to_transform = new OpenLayers.LonLat(33.489219, 126.498379);
point_to_transform.transform(projWGS84, projUTMK);
console.log(point_to_transform.lon, point_to_transform.lat);
or
// var center4WMS = new OpenLayers.LonLat(33.489219, 126.498379);
// var mapCenter = center4WMS.transform(projWGS84, projUTMK);
// console.log( 'mapCenter : '+mapCenter.toShortString() );
But I can get correct value when I convert utm-k -> wgs84
anyway,result:
incorrect value image

sorry it was my mistake....
I changed the latitude and longitude when i entered value in LonLat method.
var point_to_transform = new OpenLayers.LonLat(126.498379, 33.489219);

Related

computing the math formula on the mask (google earth engine)

I am about to calculate Chorophyll-a in the water bodies in one region, as I outlined above. I have created a mask, with water=1, land=0(transparent). And I want to calculate quality formula (NDCI, refer to normalized difference chl-a index) over the mask I created in the last step. Here are my code.
function maskS2clouds(image) {
var qa = image.select('QA60')
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0))
return image.updateMask(mask).divide(10000)
.select("B.*")
.copyProperties(image, ["system:time_start"])
}
var tiles = ['29UNV']
var collection = ee.ImageCollection("COPERNICUS/S2_SR")
.filterDate('2020-01-01', '2020-12-31')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.filter(ee.Filter.inList('MGRS_TILE', tiles))
print(collection)
var minmin = collection.map(maskS2clouds)
print(minmin)
var calndwi = function(image){
//water mask
var NDWI = image.normalizedDifference(['B3', 'B8']).rename('NDWI');
return image.addBands(NDWI).updateMask(NDWI.gt(0));
};
print(minmin.map(calndwi));
//Add NDWI to the clipped image collection
var withNDWI = minmin.map(calndwi).select('NDWI');
print("NDWI collection", withNDWI);
var bb = withNDWI.first();
Map.addLayer(bb,{},'ss');
var addNDCI = function(image) {
var ndci = image.normalizedDifference(['B5', 'B4']).rename('NDCI');
return image.addBands(ndci);
};
var withNDCI = minmin.map(addNDCI).select('NDCI');
print("NDCI collection", withNDCI);
var MASK = function(image) {
var mask = bb.mask(image);
return image.addBands(mask);
};
var maskk = withNDCI.map(MASK).select('mask');
print(maskk)**
and it give me the bug like ImageCollection (Error)
Error in map(ID=20200106T114451_20200106T114531_T29UNV):Image.select: Pattern 'mask' did not match any bands.what should I do? thanks a million
The maskk object does not contain any bands named mask, because your MASK function does not create or add any bands with that name.
What your code does, as you've currently written it, is this:
var MASK = function(image) {
// Apply a mask over the 'bb' image.
var mask = bb.mask(image);
// return 'image' (which was the 'mask' parameter above),
// with ALL bands from the object 'mask', which is now a 'masked' version of bb.
// since mask = bb.mask(image), all the bands from bb will be added.
return image.addBands(mask);
};
var maskk = withNDCI
// Map the 'MASK' function over the 'withNDCI' collection
.map(MASK)
// Attempt to select a band named 'mask' (which does not exist).
.select('mask');
I'm not sure what you're looking for when you try to select the mask 'band' - I assume what you want is the masked NCDI image. That's essentially what you have already - but the band names of the 'maskk' object are "NDWI" and "NDCI", since it is derived from the bb, and those are the bands that bb contains. There is no band named "mask".

Extract Index vegetation by points over collection in GEE

How I can extract index vegetation points over collections by adapting this beautiful code by #Rodrigo E. Principe:
Extract pixel values by points and convert to a table in Google Earth Engine
I try extract all values mas GEE is crashing, so only NDVI or EVI can works fine.
I did it with this tutorial https://developers.google.com/earth-engine/tutorial_api_06
// Dataset do sensor LS8
var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate('2018-04-01', '2019-03-31')
.select('B5', 'B4')
.filterBounds(aoi6010)
.filter(ee.Filter.lt('CLOUD_COVER', 20));
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
var withNDVI = dataset.map(addNDVI);
print(withNDVI);
// Empty Collection to fill
var ft = ee.FeatureCollection(ee.List([]))
var fill = function(img, ini) {
// type cast
var inift = ee.FeatureCollection(ini)
// gets the values for the points in the current img
var ft2 = img.reduceRegions(p601018, ee.Reducer.first(),30)
// gets the date of the img
var date = img.date().format()
// writes the date in each feature
var ft3 = ft2.map(function(f){return f.set("date", date)})
// merges the FeatureCollections
return inift.merge(ft3)
}
// Iterates over the ImageCollection
var newft = ee.FeatureCollection(withNDVI.iterate(fill, ft))

Google Earth Engine: Flatten a one-band ImageCollection into a multi-band single Image

I want to use supervised classification to classify a pattern that has a clear temporal pattern. For example, identifying stands of deciduous trees in a coniferous forest. NDVI would change overtime in the deciduous stands in a regular pattern that should be easily detectable. I assume there's an easy method to flatten the temporal dataset into a single image so that the bands in that image can be used in a classification algorithm. Maybe using .map(....)?
Here's some code to build the answer from:
var startDate = '2016-05-01';
var endDate = '2016-09-01';
var lng = -122.3424; var lat = 37.9344; //SF
var region = ee.Geometry.Point(lng, lat);
//Image Import
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(region)
.filterDate(startDate,endDate);
// NDVI temporal
var ndvi = l8.map(function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename("NDVI");
return ndvi;
});
Map.addLayer(ndvi,{},"NDVI Temporal"); // 8 images with 1 band
//NDVI FLATTENED??????? I want 1 image with 8 bands. The below code doesn't work...
var ndviFlat = ee.Image().addBands(ndvi.map(function(image){
var temp = image.select("NDVI");
return temp;
}));
From there, I will pass ndviFlat to .sampleRegions, which only works with Images not ImageCollections:
//Classification Model:
var points = ee.FeatureCollection([trainingPointsPos,trainingPointsNeg]).flatten();
var training = ndviFlat.sampleRegions({
collection: points,
properties: ['class'],
scale: 30
});
var trained = ee.Classifier.randomForest(20).train(training, 'class', bands);
classified = regLayers.select(bands).classify(trained);
Here's one way:
var startDate = '2016-05-01';
var endDate = '2016-09-01';
var lng = -122.3424;
var lat = 37.9344; //SF
var region = ee.Geometry.Point(lng, lat);
//Image Import
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(region)
.filterDate(startDate, endDate);
var empty = ee.Image();
// NDVI temporal
var ndvi = ee.Image(l8.iterate(function(image, previous) {
var name = ee.String('NDVI_').cat(image.id());
var ndvi = image.normalizedDifference(['B5', 'B4']).rename(name);
return ee.Image(previous).addBands(ndvi);
}, empty));
// Remove the annoying non-band
ndvi = ndvi.select(ndvi.bandNames().remove('constant'));
Map.centerObject(region, 13);
Map.addLayer(ndvi, {}, 'ndvi');

How can I have the percentage instead of the Frequency in Google Earth Engine?

I asked this question on GIS StackExchange, but no luck so far. I think that maybe it belongs here.
I used the following script :
// define the var
var Catchment = /* color: 98ff00 */geometry;
var landcover = ee.Image('users/roynahas/ESACCI-LC-L4-LCCS-Map-300m-P5Y-2010-v161_RECLASS').select('b1');
// Clip the image to the polygon geometry and add it to the map
var landcover_clip = landcover.clip(Catchment);
var sld_intervals =
'<RasterSymbolizer>' +
'<ColorMap type="intervals" extended="false" >' +
'<ColorMapEntry color="#FFFF00" quantity="1" label="Agriculture"/>' +
'<ColorMapEntry color="#00FF00" quantity="2" label="Grassland and Shrubland"/>' +
'<ColorMapEntry color="#008000" quantity="3" label="Forest"/>' +
'<ColorMapEntry color="#00FFFF" quantity="4" label="Flooded"/>' +
'<ColorMapEntry color="#FF00FF" quantity="5" label="Urban areas"/>' +
'<ColorMapEntry color="#808080" quantity="6" label="Bare areas"/>' +
'<ColorMapEntry color="#0000FF" quantity="7" label="Water"/>' +
'<ColorMapEntry color="#FFFFFF" quantity="8" label="Permanent snow and ice"/>' +
'</ColorMap>' +
'</RasterSymbolizer>';
Map.addLayer(landcover_clip.sldStyle(sld_intervals), {}, 'IGBP classification styled');
// Print out the frequency of landcover occurrence for the polygon.
var frequency = landcover.reduceRegion({
reducer:ee.Reducer.frequencyHistogram(),
geometry:Catchment,
scale:300
});
print('landcover frequency', frequency.get('b1'));
To get the following console output:
So my question is : How can I have a percentage instead of a frequency? or in other words : Is there a percentage equivalent to ee.Reducer.frequencyHistogram() ?
I got the answer on another forum. Here it is:
// Import variables
var globcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3"),
geometry = /* color: d63000 */ee.Geometry.Polygon(
[[[-71.466064453125, 48.763431137917955],
[-71.378173828125, 48.89000369970676],
[-72.674560546875, 49.38952445158216],
[-73.179931640625, 49.106241774469055],
[-73.575439453125, 48.27588152743497],
[-72.83935546875, 48.10743118848039],
[-71.4935302734375, 48.17341248658084],
[-71.455078125, 48.56024979174331],
[-71.5374755859375, 48.68370757165362]]]);
// Extract the landcover band
var landcover = globcover.select('landcover');
// Clip the image to the polygon geometry
var landcover_roi = landcover.clip(geometry);
// Add a map layer of the landcover clipped to the polygon.
Map.addLayer(landcover_roi);
// Print out the frequency of landcover occurrence for the polygon.
var frequency = landcover.reduceRegion({
reducer:ee.Reducer.frequencyHistogram(),
geometry:geometry,
scale:1000
});
var dict = ee.Dictionary(frequency.get('landcover'));
var sum = ee.Array(dict.values()).reduce(ee.Reducer.sum(),[0]).get([0]);
var new_dict = dict.map(function(k,v) {
return ee.Number(v).divide(sum).multiply(100);
});
print('Land Cover (%)',new_dict);
Of course, the inputs (the land cover image and polygon layer) can be different.

Center of polygon in gmap.net

I'm using Gmap.Get great mapping tools to develop an enterprise software. How to calculate center of polygon in Gmap.Net using polygon points?
Use following code to calculate center of polygon in Gmap.Net:
Private Function CalculateCenterOfPolygon(polyPoints As List(Of PointLatLng)) As PointLatLng
Dim centerPoint As New PointLatLng()
Dim sum As Integer = 0
Dim Lat As Double = 0
Dim Lng As Double = 0
For Each point As PointLatLng In polyPoints
sum += 1
Lat += point.Lat
Lng += point.Lng
Next
Lat = Lat / sum
Lng = Lng / sum
centerPoint.Lat = Lat
centerPoint.Lng = Lng
Return centerPoint
End Function
Calculate the RectLatLng with the polygon's points.
double lat = points.Max(item => item.Lat);
double lng = points.Min(item => item.Lng);
double height = lat - points.Min(item => item.Lat);
double width = points.Max(item => item.Lng) - lng;
var rect = new RectLatLng(lat, lng, width, height);
and rect.LocationMiddle is the center.

Resources