OpenLayers 3 - Wrong ScaleLine value with Gauss-Boaga projection - scale

I'm using openlayers 3 to render a map from a mapserver server. I need to use Gauss Boaga projection, so I defined:
var gbProjection = new ol.proj.Projection({
code: 'EPSG:3003',
extent: [1290650.93, 4192956.42, 2226749.10, 5261004.57],
units: 'm'
});
ol.proj.addProjection(gbProjection);
var mymap = new ol.Map({
controls: ol.control.defaults().extend(
[new ol.control.FullScreen(), new ol.control.ScaleLine({
units: 'metric'
})]),
layers: layers,
units: 'm',
target: 'mymap',
view: new ol.View({
projection: gbProjection,
center: [gbest, gbnord],
zoom: 9
})
});
I added the projection in the "view" field. Everything is working fine, I'm able to place my points on the map in the correct position. The only issue is I'm getting wrong values inside the ScaleLine, it seems the real scale multiplied by 100000 (I'm getting, say 50000 Km instead of 500 m). I can't figure out how to solve this.

include the proj4js library within your project:
https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.15/proj4.js
And then make ol3 aware about EPSG:3003 by adding this line:
Proj4js.defs["EPSG:3003"] = "+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=1500000 +y_0=0 +ellps=intl +units=m +no_defs";
Then do following to set the extent and get a reference to your projection.
//get a reference of your new projection
var gbProjection = ol.proj.get('EPSG:3003');
//set the extent
gbProjection.setExtent( [1290650.93, 4192956.42, 2226749.10, 5261004.57]);
The projection defininition may be found here
http://spatialreference.org/ref/epsg/monte-mario-italy-zone-1/proj4js/
Using this way your scale should be fine and you will also be able to do any tranformations.

Related

HERE MAP add new point in clicked place on polyline

I really beg about help because I'm trying to do some things for a few days, and I really don't know how. I want to do road manipulate by hold and drag . I think I need to start with adding new point in polyline geometry exaclly in the pointer place (or linestring, linstring points and polyline geometry seems to be almost the same). But it seems to be impossible.
Of course, there is no problem with getting coordinates, but adding this new coordinates to polyline or linestring in appropriate place.
There is no code, because every here map methods (pushPoints, setGeopetry) seems to be usless, and give points in the wrong place.
See please this example: https://demo.support.here.com/examples/v3/fleet - you can drag-n-drop there
and src code of it : https://demo.support.here.com/javascripts/examples/v3/fleet.js
Search there in the code the variable clipedPolyline and func clipPolyline:
var clipPolyline = function(polyline, viewportX, viewportY, bboxSize){
var pleft = viewportX - bboxSize,
pright = viewportX + bboxSize,
ptop = viewportY - bboxSize,
pbottom = viewportY + bboxSize,
coordLeftTop = map.screenToGeo(pleft, ptop),
coordRigthBottom = map.screenToGeo(pright, pbottom),
rect = new H.geo.Rect(coordLeftTop.lat,coordLeftTop.lng,coordRigthBottom.lat,coordRigthBottom.lng),
clipedPolyline = polyline.clip(rect);
return clipedPolyline;
};
Read please documentation for method clip on:
https://developer.here.com/documentation/maps/3.1.31.0/api_reference/H.map.Polyline.html#clip

How to filter a Google Earth Engine Image Collection by crs?

I have a script to download Sentinel-1 images from Google Earth Engine, which works perfectly over UK regions and other parts of Europe. However, when I try to run it for a region of Norway, the image returned is blurred. I think this is because within the ee.imagecollection some of the images have a different crs projection.
Hence, my question is how do I filter the images to remove images with the other crs? Here is an example of how it looks in Google Earth Engine:
Sentinel-1 image of area of Norway in Google Earth Engine
and here is how a print out of the image collection looks like in Google Earth Engine showing the two projections (see features 0 and 3 showing EPSG: 32632 and EPSG 32633):
Print out in Google Earth Engine of Norway image collection
My Google Earth Engine Script is included below. To replicate the problem replace the Norway geometry with a drawn polygon.
var year = 2021;
var region = 9;
var mth = 'October';
var mthno1 = 10;
var mthno2 = 11;
var endday1 = 18;
var endday2 = 18;
var geometry = ee.FeatureCollection("users/nfigbfr/Norway");
var s1c = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterBounds(geometry)
.filterDate(year+'-'+mthno1+'-'+endday1,year+'-'+mthno2+'-'+endday2)
.filter(ee.Filter.eq('transmitterReceiverPolarisation', ['VV','VH']))
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.map(function(image) {
var edge = image.lt(-30.0);
var maskedImage = image.mask().and(edge.not());
return image.updateMask(maskedImage);
});
print(s1c)
var img = s1c.mean();
print(img)
var img = img.addBands(img.select('VV').subtract(img.select('VH')).rename('Ratio'));
var img = img.select(['VV','VH','Ratio']).toFloat();
print(img);
var img_display = img.select(['VV','VH','Ratio']).clip(geometry);
Map.centerObject(geometry);
Map.addLayer(img_display, {min: -25, max: 0});
Export.image.toDrive({
image: img,
description: 'Norway_mean_'+mth+year,
folder: 'Sentinel_1',
crs: 'EPSG:32632',
scale: 10,
maxPixels: 1e13,
region: geometry
});
The crs is a property of individual bands, not the images. I also haven't been able to find out if/how we can access the band properties for filtering.
However, here is a workaround:
var target_crs = 'EPSG:32671'
var s1c = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterBounds(point)
.filterDate(year+'-'+mthno1+'-'+endday1,year+'-'+mthno2+'-'+endday2)
.filter(ee.Filter.eq('transmitterReceiverPolarisation', ['VV','VH']))
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.map(function(image) {
var edge = image.lt(-30.0);
var maskedImage = image.mask().and(edge.not());
return image.updateMask(maskedImage);
})
.map(function(img){
var crs = img.select(['VV']).projection().crs()
var myImageWithProperties = x.set({
crs: crs})
return ee.Image(myImageWithProperties)
;})
.filter(ee.Filter.eq('crs', target_crs));
I added a .map() function that grabs the projection code (EPSG) from the VV band and sets it as an image property. Then we can filter the collection based on this property.
I've tried this on Sentinel-2 and it works fine. Still curious if there is a simpler way, though.
PS: this question is better suited for https://gis.stackexchange.com

google.maps.geometry.spherical.computeOffset error (a.lat is not a function)

I wanted a latlng value near a particular distance. I went throught the documentation of google maps api v3.
Have a look at my code :
generateCirclepolygon(){
for (let location of this.pointsLocation) {
let LatLng:any = {
lat: parseFloat(location.lat),
lng: parseFloat(location.lng)
};
let newpoints = [];
var polypoint = google.maps.geometry.spherical.computeOffset(LatLng , 3000 , 0)
console.log(polypoint , 'point');
}
}
After runing this code im getting ERROR TypeError: a.lat is not a function.
I'm sending a LatLng object to that which has lat and lng values and they are numbers. 3000 is the distance in meters and 0 is heading (i.e 0 degrees in clock wise from north).
I want the latlng value from my point to 3000 meters towards north. My main aim is to draw a circular polygon around a point by repeating this to get an array of points.
Related questions:
Google maps a.lat is not a function
Google Maps API a.lat is not a function error
Per the documentation, the computeOffset method takes a google.maps.LatLng as an argument:
computeOffset(from, distance, heading[, radius])
Parameters:
from: LatLng
distance: number
heading: number
radius (optional): number
Return Value: LatLng
Returns the LatLng resulting from moving a distance from an origin in the specified heading (expressed in degrees clockwise from north).
You are providing a LatLngLiteral (which doesn't have a .lat method, it has a .lat property.
let LatLng:any = {
lat: parseFloat(location.lat),
lng: parseFloat(location.lng)
};
should be:
let LatLng:any = new google.maps.LatLng(
parseFloat(location.lat),
parseFloat(location.lng)
);

fitBounds(LatLngBounds) zooming fully out

I'm setting a map to fitBounds using this line
var bounds = new google.maps.LatLngBounds(fromLoc, theLoc);
console.log(bound);
map.fitBounds(bounds);
As you can see when that line runs the map fully zooms out despite the 2 LatLng's only being around 20 minutes drive away.
Anyone know how I can fix this?
When you do this:
var bounds = new google.maps.LatLngBounds(fromLoc, theLoc);
You are creating a google.maps.LatLngBounds with the southWest corner at fromLoc and the northEast corner at theLoc.
To make a bounds that contains those two locations, do this instead:
var bounds = new google.maps.LatLngBounds(); // empty bounds
bounds.extend(fromLoc);
bounds.extend(theLoc);
map.fitBounds(bounds);

Google Maps JS API Fit Bounds Not Working

I'm having a very strange problem with my Google Maps implementation. I am getting back an array from a REST service that gives me lat/lng and I am in turn using that information to put markers on the map and implement functionality.
That part works fine, it's when it comes to taking the markers output on the page and getting their bounds and zooming the map to them that I get to the problem. I have read several solutions and I have attempted implementing them to the best of my ability.
Here's my implementation:
// Reset the maps bounds
MapView.bounds = new google.maps.LatLngBounds(null);
// Get the new map bounds
for (var i=0, j=MapView.markers.length; i<j; i++){
var marker = MapView.markers[i],
lat = marker.position.lat(),
lng = marker.position.lng(),
latlng = new google.maps.LatLng(lat, lng);
MapView.bounds.extend(latlng);
};
// Set the map bounds to the new bounds
MapView.map.fitBounds(MapView.bounds);
Here is a list of the coordinates being used:
21.245445,-105.167631
41.887668,-87.622522
49.817492,15.472962
50.075538,14.4378
33.951611,-118.387578
41.887668,-87.622522
14.782827,-90.793702
33.741973,-78.817013
45.922225,-95.408973
28.320306,-81.422964
36.166667,-86.783333
-17.82922,31.053961
-8.708704,115.169616
41.901514,12.460774
-34.013717,23.054811
20.483443,-86.971039
34.933333,34.083333
6.428055,-9.429499
38.79142,-95.960607
43.771033,11.248001
46.271588,13.95641
33.773,-78.779504
40.789342,-3.249749
20.926822,-156.695125
46.271588,13.95641
18.853921,-71.300939
36.462205,-5.011611
25.788969,-80.226439
50.36809,8.73632
37.540667,126.948346
45.495992,-121.5879
14.782827,-90.793701
0,0
13,-76
20.431006,-86.908065
40.75694,-73.984872
64.143935,-21.934099
-17.816667,25.15
12.879721,121.774017
32.640054,-117.084196
-16.522046,28.850942
40.280559,22.50584
39.202686,-106.831683
36.122611,-115.170973
38.79142,-95.960607
18.126285,-65.440099
22.876396,-109.918562
30.36884,-86.324846
36.076518,-115.153343
36.0443,14.251222
41.894809,-87.624214
36.0443,14.251222
-34.035086,23.046469
36.42,25.431667
-17.82922,31.053961
20.696686,-105.292631
18.533333,-68.366667
42.407211,-71.382437
21.158964,-86.845937
9.748917,-83.753428
14.782827,-90.793701
34.852965,32.361479
34.939737,32.461585
34.052234,-118.243685
64.143935,-21.934099
35.369598,24.482727
52.407927,3.222711
47.497912,19.040235
21.158964,-86.845937
37.446719,25.328862
21.160386,-86.843338
39.770247,21.182861
36.124253,-115.168476
46.421684,15.856075
116.468401,39.947856
41.553221,-70.608589
43.706449,7.292265
39.415044,21.737618
21.158964,-86.845937
20.629559,-87.126904
36.832012,25.897065
50.075538,14.4378
8.87509,98.352656
57.702051,11.982304
-24.183889,29.012778
38.904253,-77.047904
0,0
-25.360413,27.09947
55.940209,-3.225319
36.286023,-5.27918
-3.386069,39.971999
20.749045,-105.31098
17.280151,-62.689038
21.040195,-104.358146
14.782827,-90.793702
20.696686,-105.292631
50.071287,14.397221
51.891877,-8.493827
Then I used those bounds to create a poly line to try and find out where the problem was, and the wierd part is even that is wrong, but the map isn't even zooming/panning to THOSE bounds.
Code for poly line:
var ne = MapView.bounds.getNorthEast();
var sw = MapView.bounds.getSouthWest();
var boundingBoxPoints = [
ne, new google.maps.LatLng(ne.lat(), sw.lng()),
sw, new google.maps.LatLng(sw.lat(), ne.lng()), ne
];
var boundingBox = new google.maps.Polyline({
path: boundingBoxPoints,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
boundingBox.setMap(MapView.map);
And a picture of the result (this is as the map loads, un-altered):
It will either load like that (if I'm lucky) or load with most of the trips out of the top of the map with only a couple showing and most of the map canvas gray.
I am a total loss right now, could somebody please point me in the right direction?

Resources