You are on page 1of 2

PostGIS 1.5.

1 Manual
27 / 315

-- But in this example, PostGIS extends the definition of the OGC IsValid
-- by returning false if a LinearRing (start and end points are the same)
-- has less than 2 vertices.
gisdb=# SELECT
ST_IsValid(LINESTRING(0 0, 1 1)),
ST_IsValid(LINESTRING(0 0, 0 0));
st_isvalid | st_isvalid
------------+----------t
|
f

By default, PostGIS does not apply this validity check on geometry input, because testing for validity needs lots of CPU time for
complex geometries, especially polygons. If you do not trust your data sources, you can manually enforce such a check to your
tables by adding a check constraint:
ALTER TABLE mytable
ADD CONSTRAINT geometry_valid_check
CHECK (ST_IsValid(the_geom));

If you encounter any strange error messages such as "GEOS Intersection() threw an error!" or "JTS Intersection() threw an error!"
when calling PostGIS functions with valid input geometries, you likely found an error in either PostGIS or one of the libraries
it uses, and you should contact the PostGIS developers. The same is true if a PostGIS function returns an invalid geometry for
valid input.
Note
Strictly compliant OGC geometries cannot have Z or M values. The ST_IsValid() function wont consider higher dimensioned geometries invalid! Invocations of AddGeometryColumn() will add a constraint checking geometry dimensions,
so it is enough to specify 2 there.

4.3.6 Dimensionally Extended 9 Intersection Model (DE-9IM)


It is sometimes the case that the typical spatial predicates (ST_Contains, ST_Crosses, ST_Intersects, ST_Touches, ...) are
insufficient in and of themselves to adequately provide that desired spatial filter.

PostGIS 1.5.1 Manual


28 / 315

For example, consider a linear dataset representing a road network. It may be the task of a GIS analyst to identify all road
segments that cross each other, not at a point, but on a line, perhaps invalidating some business rule. In this case,
ST_Crosses does not adequately provide the necessary spatial filter since, for linear features, it returns true only where
they cross at a point.
One two-step solution might be to first perform the actual intersection (ST_Intersection) of pairs of road segments that
spatially intersect (ST_Intersects), and then compare the intersections ST_GeometryType with LINESTRING (properly
dealing with cases that return GEOMETRYCOLLECTIONs of [MULTI]POINTs, [MULTI]LINESTRINGs, etc.).
A more elegant / faster solution may indeed be desirable.

You might also like