You are on page 1of 2

PostGIS 1.5.

1 Manual
207 / 315

Examples
SELECT ST_AsText(ST_PointOnSurface(POINT(0 5)::geometry));
st_astext
-----------POINT(0 5)
(1 row)
SELECT ST_AsText(ST_PointOnSurface(LINESTRING(0 5, 0 10)::geometry));
st_astext
-----------POINT(0 5)
(1 row)
SELECT ST_AsText(ST_PointOnSurface(POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))::geometry));
st_astext
---------------POINT(2.5 2.5)
(1 row)
SELECT ST_AsEWKT(ST_PointOnSurface(ST_GeomFromEWKT(LINESTRING(0 5 1, 0 0 1, 0 10 2))));
st_asewkt
---------------POINT(0 0 1)
(1 row)

See Also
ST_Centroid, ST_Point_Inside_Circle

7.8.35 ST_Relate
Name
ST_Relate Returns true if this Geometry is spatially related to anotherGeometry, by testing for intersections between the
Interior, Boundary and Exterior of the two geometries as specified by the values in the intersectionMatrixPattern. If no intersectionMatrixPattern is passed in, then returns the maximum intersectionMatrixPattern that relates the 2 geometries.

Synopsis
boolean ST_Relate(geometry geomA, geometry geomB, text intersectionMatrixPattern);
text ST_Relate(geometry geomA, geometry geomB);

Description
Version 1: Takes geomA, geomB, intersectionMatrix and Returns 1 (TRUE) if this Geometry is spatially related to anotherGeometry, by testing for intersections between the Interior, Boundary and Exterior of the two geometries as specified by the values
in the intersectionMatrixPattern.
This is especially useful for testing compound checks of intersection, crosses, etc in one step.
Do not call with a GeometryCollection as an argument

Note
This is the "allowable" version that returns a boolean, not an integer. This is defined in OGC spec

PostGIS 1.5.1 Manual


208 / 315

Note
This DOES NOT automagically include an index call. The reason for that is some relationships are anti e.g. Disjoint. If
you are using a relationship pattern that requires intersection, then include the && index call.

Version 2: Takes geomA and geomB and returns the DE-9IM (dimensionally extended nine-intersection matrix)

Note
Do not call with a GeometryCollection as an argument

not in OGC spec, but implied. see s2.1.13.2


Both Performed by the GEOS module
This method implements the OpenGIS Simple Features Implementation Specification for SQL 1.1. s2.1.1.2 // s2.1.13.3
This method implements the SQL/MM specification. SQL-MM 3: 5.1.25

Examples
--Find all compounds that intersect and not touch a poly (interior intersects)
SELECT l.* , b.name As poly_name
FROM polys As b
INNER JOIN compounds As l
ON (p.the_geom && b.the_geom
AND ST_Relate(l.the_geom, b.the_geom,T********));
SELECT ST_Relate(ST_GeometryFromText(POINT(1 2)), ST_Buffer(ST_GeometryFromText(POINT(1
2)),2));
st_relate
----------0FFFFF212

SELECT ST_Relate(ST_GeometryFromText(LINESTRING(1 2, 3 4)), ST_GeometryFromText( LINESTRING(5 6, 7 8)));


st_relate
----------FF1FF0102

SELECT ST_Relate(ST_GeometryFromText(POINT(1 2)), ST_Buffer(ST_GeometryFromText(POINT(1


2)),2), 0FFFFF212);
st_relate
----------t

SELECT ST_Relate(ST_GeometryFromText(POINT(1 2)), ST_Buffer(ST_GeometryFromText(POINT(1


2)),2), *FF*FF212);
st_relate
----------t

You might also like