[OSM-dev] invalid geometry in planet_polygon

nimix melchiormoos at gmail.com
Tue Aug 24 17:37:07 BST 2010

Stefan de Konink-3 wrote:
> The index is never used... and how do I know? Because I actually tried
> it...

Your right if you want to do a ... WHERE St_IsValid(geom) query, the planner
don't uses the index because 99% of geometries are valid, so an index scan
seems to be useless. In that case I made postgres use the index by double
negation, but that only works fast if there are few invalid geometries:

SELECT * FROM planet_osm_polygon WHERE NOT osm_id IN(SELECT osm_id FROM
planet_osm_polygon WHERE NOT ST_IsValid(geom));

If the table is very lage there might be an other index that is used to
access the rows anyway to whitch you can add the ST_IsValid(geom) filter
CREATE INDEX idx_ploygon_geom_with_valid ON planet_osm_polygon USING gist
(way) WHERE ST_IsValid(way);

This would speedup queries like ...WHERE way && geometry AND
View this message in context: http://gis.638310.n2.nabble.com/invalid-geometry-in-planet-polygon-tp5454655p5457602.html
Sent from the Developer Discussion mailing list archive at Nabble.com.

More information about the dev mailing list