[MapServer-users] Polygon area : cannot get the correct unit(e.g. square meters)
Philippe Ghesquiere
philippe.ghesquiere at airbus.com
Fri Jun 27 00:49:01 PDT 2025
Dear all,
I didn't find a way to compute polygon areas in square meters.
As a workaround, I decided to add a new column in my GPKG database, with
the pre-calculated area :
ogr2ogr -append Output.gpkg Input.gpkg MyPolygonLayer -sql "select *,
ST_Area(geom, 1) as SURFACE_M2 from MyPolygonLayer" -nln MyPolygonLayer
I can now use the new attribute in my mapserver file :
LABEL
TEXT " surf=[SURFACE_M2] m2"
...
END
Philippe
On Wed, Jun 18, 2025 at 10:54 AM Philippe Ghesquiere <
philippe.ghesquiere at airbus.com> wrote:
> Dear all,
>
> I want to display the area of a polygon, for example :
> POLYGON((45.179 1.94,45.179 1.95,45.182 1.95,45.182 1.94,45.179 1.94))
>
> I cannot get the area either in m^2 or deg^2.
> Am I missing something ?
> Below are some tests I went through.
>
> 1) Area measured with QGIS :
> Ellispsoïdal
> square degrees : 0.00003 deg²
> square meters : 369063.9 m²
>
> Cartesian
> square degrees : 0.00003 deg²
> square meters : 371759.7 m²
>
> 2) Area displayed with mapserver
> 2.1) based on attribute [shape]
> LABEL
> TEXT (" surf=" + tostring(area([shape]), "%.1f") )
> ...
> END
>
> The area value depends on zoom level : the more I zoom in, the higher the
> area value.
> It turns out that the area is expressed in pixel^2
>
> 2.2) based on hard coded polygon
> LABEL
> TEXT ("surf=" + tostring(area(fromText('POLYGON ((45.179 1.94,45.179
> 1.95,45.182 1.95,45.182 1.94,45.179 1.94))')), "%.10f") )
> ...
> END
> The area value is exactly what I would expect (deg^2) : 0.00003
>
> 3) Conversion from deg^2 to m^2
> The relationship is :
> * Surf_m ~ Surf_deg * (R * pi/180)^2
> * R ~ 6378137 (the earth radius in meters)
>
> which yields to :
> Surf_m ~ 371760.8 m^2
>
The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other than the addressee. Access to this e-mail by anyone else is unauthorised.
If you are not the intended recipient, please notify Airbus immediately and delete this e-mail.
Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately.
All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20250627/414544d3/attachment-0001.htm>
More information about the MapServer-users
mailing list