[Qgis-developer] Add ST_MakeValid functionality to QgsGeometry?

Larry Shaffer larrys at dakotacarto.com
Mon Sep 17 13:15:42 PDT 2012


Hi,

Recently there have been several labeling-related issues where the
conclusion is that a label is not shown because the geometry is
invalid (generally polygons). I noticed Sandro Santilli's work for
PostGIS 2.0 with the new ST_MakeValid function [0]. I'm no geometry
whiz, but it appears to be based solely off of GEOS (and some other
PostGIS internals).

What's the likelihood that the ST_MakeValid function could be ported
to QGIS?... ending up with something like:

bool QgsGeometry::makeValid()
Converts an invalid geometry to a list of valid representative geometries
Returns:  true on success and false otherwise

For labeling, this might allow for some invalid geometries to be
labeled, since labeling engine already creates duplicate temporary
feature geometries to send to PAL. I see it in the GUI as a checkbox
PAL layer option, like 'Attempt to fix invalid geometries,' that would
be off by default, since the fixing operation might slow labeling
down. This may also help to label some clipped (but invalid) polygons
around the perimeter of the visible extent, when clipping is used.

While my focus is labeling, I'm pretty sure there would be other
reasons to have a geometry fixing solution in QgsGeometry as well.
Sorry if this has already been discussed, or even implemented
somewhere in the source (if so where?).

I researched some other quick, on-the-fly geometry-fixing solutions,
but the only other option appeared to be 'prepair' [1]. The prepair
results look good [2], but it has an additional dependency on a much
larger library, CGAL [3] (12 MB).

[0] http://svn.osgeo.org/postgis/trunk/postgis/lwgeom_geos_clean.c
[1] https://github.com/tudelft-gist/prepair
[2] http://www.gdmc.nl/ledoux/pdfs/_12agile.pdf
[3] http://www.cgal.org

Regards,

Larry


More information about the Qgis-developer mailing list