[gdal-dev] proper way to get area of a lon/lat polygon

Javier Jimenez Shaw j1 at jimenezshaw.com
Fri Sep 18 00:31:12 PDT 2020


The documentation of AssignSpatialReference says:

"Any existing spatial reference is replaced, but under no circumstances
does this result in the object being reprojected. It is just changing the
interpretation of the existing geometry."

You have to reproject the polygon coordinates to actually have the polygon
in that CRS.

.___ ._ ..._ .. . ._.  .___ .. __ . _. . __..  ... .... ._ .__
Entre dos pensamientos racionales
hay infinitos pensamientos irracionales.



On Fri, 18 Sep 2020 at 06:49, Mikhail Kruk <meshko at gmail.com> wrote:

> Hi!
> I am a complete GIS newbie so please bear with me...
>
> I am trying to get the area of a polygon specified in lon,lat pairs in
> some reasonable units, like sq kilometers.  My quest so far is documented
> here:
>
>
> https://gis.stackexchange.com/questions/374428/default-geo-spatial-reference-system-in-gdal-ogr
>
> but basically I came to the conclusion that when people talk about an area
> of something on Earth they really mean the area of a projection (am i right
> about that?) and so i need to specify a projection before getting a
> meaningful area.  So i ended up with this code:
>
> wkt = "POLYGON ((lon1 lat1, lon2 lat2, lon3 lat3))"
> poly = ogr.CreateGeometryFromWkt(wkt)
> sr = osr.SpatialReference()
> sr.SetWellKnownGeogCS("NAD83")
> sr.SetProjCS("SRS_PT_TRANSVERSE_MERCATOR")
> poly.AssignSpatialReference(sr)
> poly.GetArea()
>
> and yet I get back a value which seems to be calculated in square degrees.
>
> Thanks!
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200918/9e4aba57/attachment.html>


More information about the gdal-dev mailing list