[OpenLayers-Users] distances in spherical mercator
Bill Thoen
bthoen at gisnet.com
Thu Mar 19 14:21:21 EDT 2009
Alessio,
I think you can just use the planar distances because the google SRS is
a projected coordinate system and the coordinate units are meters..
Whether it's very accurate over long distances I don't know. I doubt it,
but t might not be too far off depending on your needs. Google
coordinates certainly won't work with Vincenty because that expects
coordinates in decimal degrees.
- Bill Thoen
Alessio Di Lorenzo wrote:
> Hi all,
>
> I'm using the measurement tool in an application that uses google maps as
> base.
> My problem is that the measurement tool calculate the planar distance
> (instead geodesic)...
>
> I tried to use the Util.distVincenty and it works (very good) only if my map
> projection is 4326.
>
> Snippet:
>
> function calcVincenty(geometry) {
> var dist = 0;
> for (var i = 1; i < geometry.components.length; i++) {
> var first = geometry.components[i-1];
> var second = geometry.components[i];
> dist += OpenLayers.Util.distVincenty(
> {lon: first.x, lat: first.y},
> {lon: second.x, lat: second.y}
> );
> }
> return dist;
> }
>
>
> function handleMeasurements(event) {
>
> var geometry = event.geometry;
> var units = event.units;
> var order = event.order;
> var measure = event.measure;
> var element = document.getElementById('output_misure');
> var out = "";
> if(order == 1) {
>
> if (map.getProjection()== "EPSG:4326") {
> out += "Distanza: " + calcVincenty(geometry).toFixed(3)+ " " + units;
>
> } else {
> out += "Distanza: " + measure.toFixed(3)+ " " + units;
> }
> } else {
> if (map.getProjection() == "EPSG:4326") {
> out += "Area: " +
> (OpenLayers.Util.approxPolyAreaOnSphere(geometry)/1000000.0).toFixed(3)+ " "
> + units + "q";
> } else {
> out += "Area: " + measure.toFixed(3) + " " + units + "q";
> }
> }
> element.innerHTML = out;
> }
>
>
> If I apply the calcVincenty function to the 900913 projection I get enormous
> distance errors...
> Is there a way to measure geodesic distances (and areas) also for 900913
> projected maps?
>
> Thx in advance, alessio
>
More information about the Users
mailing list