Distance between two geometries using OPENSCALE functions

93 views
Skip to first unread message

Ani Alamo

unread,
Jan 9, 2014, 10:35:44 AM1/9/14
to opensca...@googlegroups.com
Hi guys!
In my ActionScript project I use the org.openscales.geometry classes:

var dp:ProjProjection = new ProjProjection("EPSG:4326");
var point0:org.openscales.geometry.Point = new org.openscales.geometry.Point(71.2087, 45.2714, dp);
var point1:org.openscales.geometry.Point = new org.openscales.geometry.Point(66.39, 42.3739, dp);

Using postgis functions I obtained the distance between both points: 
select st_distance_spheroid(
  'SRID=4326;POINT(71.2087 45.2714)'::geometry,
  'SRID=4326;POINT(66.39 42.3739)'::geometry, 
  'SPHEROID["WGS 84",6378137,298.257223563]') AS d;

503730.75294813 (meters) = 503kms

*************************
Then I've tried this calculation in ACTION SCRIPT:


var dist:Number = point0.distanceTo(point1)
This gives me this value: 5.622755

How can I convert this value ¿degress? to meters???



I've tried this code, because I understood that 1 DEGREE is equals to 111.11 Kms.

dist = point0.distanceTo(point1) * 111.11;
This gives me this value:  624.744  This is wrong!!!!!

Finally I've tried this code:
dist = point0.distanceTo(point1) / 111.11;
This gives me this value:  1524123  This is wrong!!!!!

How can I get a right distance between two geometries (two points, one point and a linestring,....) in OPENSCALES?

thanks!!!!!

Hermes David

unread,
Mar 26, 2014, 9:40:04 AM3/26/14
to opensca...@googlegroups.com
I dont know if you already got your answer, but I will answer anyway. You are messing things up. For instance, you cant measure distance or área with angular units. Its illogical, since distance and area are linear measures. You must first convert both geometries to a linear coordinate system. 
Every projected coordinate system has its own characteristics and error margin, so you must choose the one that best fit your interests. For small distances (within 6 degrees I suggest you take a look on UTM) or you could use a world projection. 

After that, all you have to do is measure distance. 
For points use Pythagorean theorem. 
For line and point, you must find the nearest point on the line and measure the points distance. To find the nearest point, use the line equation and find its perpendicular that passes through the point, find the intersection point of this 2 axis. If this intersection point is out of the line than get the line nearest vertex.
For polygon and point find the nearest side and with it apply the same logic as line and point.

For this measure step ther are lots of code and libraries to do the job. The important step is to project the coordinates and everything will be fine.

I wish I could help,
Hermes David Junior
Reply all
Reply to author
Forward
0 new messages