On Wed, 22 Jan 2025 08:21:51 -0800 (PST), Antonio Valanzano wrote:
> I have a table with polygons and one of this is invalid.
>
> When I try to repair this geometry
>
> I receive this message:
> SQL error: russia_poligoni.geometry violates Geometry constraint
> [geom-type or SRID not allowed]
>
Hi Antonio,
Peter has already given a complete and very detailed answer:
1. repairing an invalid polygon is not a strictly deterministic
science, it's rather a subtle art largely based on empirical
criteria.
2. there are several algorithms, none perfect but all useful
and interesting in their own way.
3. it's not a problem that admits a single exact and precise
solution; each algorithm gives a different answer, it's up
to you to choose the one you think is best (or least bad)
on a case-by-case basis.
That said: if SpatiaLite reports an error when you try to update
the geometry by replacing the invalid one with the repaired one,
the most likely thing is that the "repair" algorithm you are
using has changed the class of the geometry.
A concrete example:
SELECT GeometryType(
GeomFromText(
'POLYGON((0 0, 1 0, 0 1, 1 1, 0 0))'
)):
---------------------------------
POLYGON
SELECT GeometryType(
ST_MakeValid(
GeomFromText(
'POLYGON((0 0, 1 0, 0 1, 1 1, 0 0))'
)));
---------------------------------
MULTIPOLYGON
In these cases it's still possible to recover the repaired
geometry, it just requires a little more work.
In any case you must always first check what kind of
geometry was created by the "repair" algorithm to then
decide the best approach on a case-by-case basis.
Repairing invalid polygons is not a silver bullet to
be fired blindly, it's rather a kind of surgical
operation that requires extreme attention to all
details, always keeping in mind that each case is
different from all the others and that there are
never fixed rules.
bye Sandro