[OpenLayers-Users] How to validate OpenLayers area calculation using PostGIS?
João Rodrigues
joaorodr84 at gmail.com
Tue Sep 23 09:14:00 PDT 2014
Hi
I am working on a GIS API that works on top of OpenLayers.
I have a feature that calculates the area of a drawn polygon. I have tested
it on the browser and the areas I got, appear to be correct. For example, I
have measured some country areas and they matched the real areas
approximately.
Surely, I have to run some unit tests to prove that the area calculations
are correct. I use PostGIS to generate the area value, but I get completely
different results than the ones from OpenLayers.
In PostGIS, I do this:
SELECT
st_astext(st_transform(st_geomfromtext('POINT(50 0)', 4326), 900913)),
st_astext(st_transform(st_geomfromtext('POINT(-60 -5)', 4326), 900913)),
st_astext(st_transform(st_geomfromtext('POINT(-30 -30)', 4326), 900913)),
ST_Area(
ST_GeomFromText(
'POLYGON(
(
50 0,
-60 -5,
-30 -30,
50 0
)
)'
), false
) as area
I get these results:
"POINT(5565974.53966368 -7.08115455161362e-10)";
"POINT(-6679169.44759641 -557305.257274577)";
"POINT(-3339584.72379821 -3503549.84350437)";
19582793771831 // area
I introduce these three points in my test, like this:
var points = [
new OpenLayers.Geometry.Point(5565974.53966368,
-7.08115455161362e-10),
new OpenLayers.Geometry.Point(-6679169.44759641, -557305.257274577),
new OpenLayers.Geometry.Point(-3339584.72379821, -3503549.84350437)
];
var ring = new OpenLayers.Geometry.LinearRing(points);
var polygon = new OpenLayers.Geometry.Polygon([ring]);
Then, I used the getArea() method from OpenLayers.Measure, but I got an
area of: 17050040174394.607 sq. meters
According to PostGIS, the area of this polygon should be: 19582793771831
sq. meters.
It is a big difference.
I understand hat the getGeodesicArea method gives only an approximation of
the real geodesic area, but I get results that are too different. Is there
a correction we could do in the getArea method? How could I calculate the
area with more accuracy?
Thanks
PS: I can't publish the whole code here, because it is work related.
João Rodrigues
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140923/d86bfb87/attachment.html>
More information about the Users
mailing list