<div dir="ltr"><div>Hi</div><div><br></div><div>I am working on a GIS API that works on top of OpenLayers. </div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>In PostGIS, I do this:</div><div><br></div><div><span class="" style="white-space:pre">    </span>SELECT</div><div><span class="" style="white-space:pre">     </span>st_astext(st_transform(st_geomfromtext('POINT(50 0)', 4326), 900913)),</div><div><span class="" style="white-space:pre">     </span>st_astext(st_transform(st_geomfromtext('POINT(-60 -5)', 4326), 900913)),</div><div><span class="" style="white-space:pre">   </span>st_astext(st_transform(st_geomfromtext('POINT(-30 -30)', 4326), 900913)),</div><div><span class="" style="white-space:pre">  </span>ST_Area(</div><div><span class="" style="white-space:pre">           </span>ST_GeomFromText(</div><div><span class="" style="white-space:pre">                   </span>'POLYGON(</div><div><span class="" style="white-space:pre">                              </span>(</div><div><span class="" style="white-space:pre">                                  </span>50 0,</div><div><span class="" style="white-space:pre">                                      </span>-60 -5, </div><div><span class="" style="white-space:pre">                                  </span>-30 -30,</div><div><span class="" style="white-space:pre">                                   </span>50 0</div><div><span class="" style="white-space:pre">                               </span>)</div><div><span class="" style="white-space:pre">                  </span>)'</div><div><span class="" style="white-space:pre">             </span>), false</div><div><span class="" style="white-space:pre">   </span>) as area</div><div><br></div><div>I get these results:</div><div><br></div><div>    "POINT(5565974.53966368 -7.08115455161362e-10)";</div><div>    "POINT(-6679169.44759641 -557305.257274577)";</div><div>    "POINT(-3339584.72379821 -3503549.84350437)";</div><div>    19582793771831 // area</div><div><br></div><div>I introduce these three points in my test, like this:</div><div><br></div><div>    var points = [</div><div>        new OpenLayers.Geometry.Point(5565974.53966368, -7.08115455161362e-10),</div><div>        new OpenLayers.Geometry.Point(-6679169.44759641, -557305.257274577),</div><div>        new OpenLayers.Geometry.Point(-3339584.72379821, -3503549.84350437)</div><div>    ];</div><div>    var ring = new OpenLayers.Geometry.LinearRing(points);</div><div>    var polygon = new OpenLayers.Geometry.Polygon([ring]);</div><div><br></div><div>Then, I used the getArea() method from OpenLayers.Measure, but I got an area of: 17050040174394.607 sq. meters</div><div><br></div><div>According to PostGIS, the area of this polygon should be: 19582793771831 sq. meters.</div><div><br></div><div>It is a big difference.</div><div><br></div><div>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?</div><div><br></div><div>Thanks</div><div><br></div><div>PS: I can't publish the whole code here, because it is work related.</div><div><br></div><div>João Rodrigues</div><div><br></div></div>