[OpenLayers-Users] distances in spherical mercator
Alessio Di Lorenzo
alessio.dilorenzo at gmail.com
Fri Mar 20 05:48:30 EDT 2009
Hi Bill and thanks for the answer,
I solved with this Tim Shaub's patch
http://trac.openlayers.org/attachment/ticket/1819/geodesic.patch
ciao, alessio
Bill Thoen wrote:
>
> 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
>>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
--
View this message in context: http://n2.nabble.com/distances-in-spherical-mercator-tp2503670p2507944.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list