fiboa / cli

CLI for fiboa (validation, inspection, schema and file creation, etc.)
https://pypi.org/project/fiboa-cli/
Apache License 2.0
0 stars 7 forks source link

`converter`: Add option to calculate area and perimeter if missing #21

Closed m-mohr closed 4 days ago

m-mohr commented 6 months ago

@cholmes wrote in #38:

When working with the converter I was thinking that area and perimeter should be pretty easy to calculate from the geometry.

It seems like you could potentially do them with geopandas, maybe fitting into the template? But it could also be nice to just have them be top-level 'convert' options, to just automatically add them based on the geometry.

See also - https://github.com/fiboa/specification/issues/28#issuecomment-2095121587 could be nice to have the validator check this as well.

Validator check issue: #10

m-mohr commented 5 months ago

At first I also thought this is easy and shapely already has the length and area properties, but they are unitless. Here it depends on the projection though, e.g. the area might also be given in square degrees insteasd of square meters, you need to consider holes, and sometime you even get negative areas. So we may convert to WGS84 for the area, but is that always good? It will be somewhat inaccurate compared to the native CRS (and pyproj is quite a heavy dependency).

See also https://stackoverflow.com/questions/23697374/calculate-polygon-area-in-planar-units-e-g-square-meters-in-shapely

cholmes commented 5 months ago

Oh yeah, I remember hitting on some of the inaccuracies of area calculations with different projections when I was working with google buildings. Ended up with this code - you need to project to something better to calculate the area.

Just came across: https://gis.stackexchange.com/questions/337035/epsg-codes-for-projections-to-use-when-computing-the-area-of-global-polygon-sets which I appreciate and don't remember at the time.

I do think it'd be nice to give some option that's opt-in, that may have some caveats. But first key step seems to be to have the validator be good at checking this - since having the area calculated wrong may be a problem with other data.

m-mohr commented 5 days ago

PR: https://github.com/fiboa/cli/pull/114