[Bug] - Fix the edge cases of invalid geometries from sources
Error case in EI test runs:
- One building from Microsoft in
UKRremains invalid after parsingGeometryRule. Furthermore, the 3D geometry extruded bygeometryis also at the risk of being invalid. The EI error log is:
RuleError: ['UpsertBuildingRule' failed with arguments:...
...
psycopg2.errors.InternalError: Polygon is invalid: ring 0 self intersects: ...
Checked through Microsoft_buildings and found ~20 errorneous cases after running ST_Buffer(ST_GeomFromText(ST_AsText(geometry), 4326), 0) as GeometryRule. Apparently, it fails to repair the raw geometry_wkt.
Solutions:
- Use the
ST_MakeValid()to repair geometries. The cases that cannot be fixed byST_Buffer()can be fixed byST_MakeValid(). - Add validity check rule for geometry before upserting. Since there is no validity check function for 3D geometry in PostGIS, then the check is limited to 2D geometry. If the processed 2D geometry stays as invalid, the 3D geometry extruded from 2D will run into problems too, and the process should be cancelled. In this way, some egde cases can be fixed.
Edited by Danijel Schorlemmer