Il 2026-04-03 13:14 Even Rouault ha scritto:
> Conclusion: use ST_Area(geometry_column, TRUE) to get an accurate
> surface value.
>
This is a really brilliant tip to get around all the problems associated
with
calculating areas on projected maps.
Unfortunately, however, this is not entirely correct; precise area
calculation
is only possible for geometries with geographic coordinates (lat/long),
otherwise
you'll only get NULL results... and unfortunately the ISTAT dataset is
only
available in UTM zone 32 (32632).
However, we can start from this idea of yours to arrive at a more
precise
measurement of the rounding and approximation effects.
SELECT AddGeometryColumn('com_istat', 'utm33', 32633, 'MultiPolygon',
'XY');
UPDATE com_istat SET utm33 = ST_Transform(geometry, 32633);
SELECT AddGeometryColumn('com_istat', 'wgs84', 4326, 'MultiPolygon',
'XY');
UPDATE com_istat SET wgs84 = ST_Transform(geometry, 4326);
We now have _three_ geometries for each Italian municipality: one
in UTM32, the other in UTM33, and the last in WGS84 (lat/long).
At this point we are going to create a temporary table to simplify
all subsequent processing.
CREATE TEMPORARY TABLE tmp_com AS
SELECT a.cod_reg, b.den_reg, b.shape_area / 1000000.0 AS km2_istat,
Sum(ST_Area(a.geometry)) / 1000000.0 AS km2_utm32,
Sum(ST_Area(a.utm33)) / 1000000.0 AS km2_utm33,
Sum(ST_Area(a.wgs84, 1)) / 1000000.0 AS km2_wgs84
FROM com_istat AS a
JOIN reg01012026_wgs84 AS b ON (a.cod_reg = b.cod_reg)
GROUP BY b.cod_reg;
SELECT cod_reg, den_reg, km2_istat,
km2_wgs84, km2_istat - km2_wgs84 AS delta_wgs84,
((km2_istat - km2_wgs84) / km2_istat) * 1000.0 AS pp1000
FROM tmp_com
ORDER BY Abs(pp1000);
This query allows us to calculate the deviations (delta_wgs84)
between the areas pre-calculated by ISTAT (km2_istat) and those
calculated precisely on the ellipsoid (km2_wgs84).
pp1000 expresses the deviations measured in parts per thousand.
cod_reg den_reg km2_istat, km2_wgs84 delte pp1000
===============================================================
8 Emilia-Romagna 22501.812507 22502.360540 -0.548032 -0.024355
2 Valle d'Aosta/Vallée
d'Aoste 3260.842686 3262.229805 -1.387119 -0.425387
5 Veneto 18355.235547 18346.877457 8.358090 0.455352
9 Toscana 22989.803182 23001.511283 -11.708102 -0.509274
3 Lombardia 23863.088101 23879.663973 -16.575872 -0.694624
20 Sardegna 24108.538923 24127.219345 -18.680422 -0.774847
1 Piemonte 25386.727822 25409.160789 -22.432967 -0.883649
10 Umbria 8464.202686 8453.978601 10.224085 1.207921
7 Liguria 5417.622796 5424.316400 -6.693604 -1.235524
12 Lazio 17239.366235 17211.739254 27.626982 1.602552
6 Friuli-Venezia Giulia 7933.295957 7920.509615 12.786342 1.611731
11 Marche 9346.018846 9328.998834 17.020012 1.821098
4 Trentino-Alto
Adige/Südtirol 13604.704803 13636.064846 -31.360043 -2.305088
13 Abruzzo 10831.715370 10797.363923 34.351447 3.171376
19 Sicilia 25835.308181 25930.360374 -95.052193 -3.679158
14 Molise 4460.562761 4440.700726 19.862035 4.452809
15 Campania 13675.723739 13609.395288 66.328451 4.850087
16 Puglia 19542.704452 19421.180192 121.524260 6.218395
17 Basilicata 10073.185398 9992.880163 80.305235 7.972179
18 Calabria 15219.297663 15084.790192 134.507471 8.837955
As we can see, all regions show some deviations, for the reasons
that Even has excellently explained.
And as we expected, the imperfections become more and more noticeable
going from west to east and moving away from the central meridian
of the UTM32 zone.
But there's one more interesting thing to note: these are, in any
ase, reasonable approximations of a few thousandths, acceptable
for many purposes.
very last step.
SELECT cod_reg, den_reg, km2_istat, km2_utm32,
km2_istat - km2_utm32 AS delta_utm32
FROM tmp_com;
This last query compares the regional area values pre-calculated by
ISTAT with those calculated by ST_Area on the UTM 32 zone (planar).
cod_reg den_reg km2_istat km2_utm32 delta_umt32
=========================================================
1 Piemonte 25386.727822 25386.727822 -1.408989e-08
2 Valle d'Aosta/Vallée d'Aoste 3260.842686 3260.842686 -3.830337e-09
3 Lombardia 23863.088101 23863.088101 -1.921217e-08
4 Trentino-Alto Adige/Südtirol 13604.704803 13604.704803 -3.208697e-09
5 Veneto 18355.235547 18355.235547 -2.498200e-08
6 Friuli-Venezia Giulia 7933.295957 7933.295957 4.753019e-09
7 Liguria 5417.622796 5417.622796 4.206413e-09
8 Emilia-Romagna 22501.812507 22501.812507 -1.953958e-08
9 Toscana 22989.803182 22989.803182 3.995228e-08
10 Umbria 8464.202686 8464.202686 -3.961759e-09
11 Marche 9346.018846 9346.018846 7.275958e-12
12 Lazio 17239.366235 17239.366235 1.511944e-08
13 Abruzzo 10831.715370 10831.715370 -1.650005e-08
14 Molise 4460.562761 4460.562761 -2.679371e-09
15 Campania 13675.723739 13675.723739 -3.937203e-08
16 Puglia 19542.704452 19542.704452 2.940942e-08
17 Basilicata 10073.185398 10073.185398 6.308255e-09
18 Calabria 15219.297663 15219.297663 -4.676622e-08
19 Sicilia 25835.308181 25835.308181 -4.383764e-09
20 Sardegna 24108.538923 24108.538923 -3.599780e-08
We continue to have discrepancies, but this time they are truly
infinitesimal, less than 1 part per million.
These are the discrepancies attributable to different roundings
(different software, different hardware).
We are now able to answer Andrea's question about the relative
contribution of approximation errors due to coordinate
transformation and floating-point arithmetic roundings.
- both effects exist, but they have very different impacts.
- Unavoidable approximations with planar projections typically
count for 1 part in a thousand discrepamciea.
- Rounding errors in floating-point arithmetic are much smaller,
typically less than parts per million.
bye Sandro