[postgis-devel] ST_MakeValid and geometry fixing

Paul Ramsey pramsey at cleverelephant.ca
Tue Apr 27 12:11:13 PDT 2021

As discussed on the geos-devel list, there is now a second option for geometry repair in the GEOS code base, and I have just merged a patch that exposes it in PostGIS, for testing and evaluation about whether we want to make it the default.

CREATE OR REPLACE FUNCTION ST_MakeValid(geom geometry, params text)
    RETURNS geometry
    AS 'MODULE_PATHNAME', 'ST_MakeValid'

    The "params" argument can be used to supply an options
    string to select the method to use for building valid geometry.
    The options string is in the format "key1=value2 key2=value2".

* The "method" key has two values. "linework" is the original
        algorithm, and builds valid geometries by first extracting all lines,
        noding that linework together, then building a value output from the
        linework. "structure" is an algorithm that distinguishes between
        interior and exterior rings, building new geometry by unioning
        exterior rings, and then differencing all interior rings.
  * The "keepcollapsed" is only valid for the "structure" algorithm,
        and takes a value of "true" or "false". When set to "false",
        geometry components that collapse to a lower dimensionality,
        for example a one-point linestring would be dropped.

Interested in folks running them side-by-side and seeing what the results are like.

We are also cooking up a third (or maybe just an enhancement to the current structure method) method that does not accept the shell/hole categorizations of the input, but instead revalidates them using containment rules. This might result in the ultimate "tastes good" validated output. 


More information about the postgis-devel mailing list