0

I ST_Dwithin the function returns TRUE if the geometry A is completely inside B. I happen to have many polygons (representing regions) and need to know which streets are within each of these polygons. But it has some streets that hath part in a region and part in another. Which function is most appropriate to select postgis geometries that have any part inside another?

1
  • ESRI has nice graphical examples here and here of spatial relationships. They even have a few for some ST functions, but I haven't found a resource that covers all of those in the postgis docs.
    – Chris W
    Commented Jun 3, 2014 at 20:03

2 Answers 2

1

I would use the function ST_Intersects

1

Intersects means the same as "not Disjoint" and it selects also roads which only touch the polygon boundary at one or more points. Roads touching the area polygon at one point are not uncommon because roads are often split as municipality borders because the name is changing or just because of how the data are maintained. I would say that correct results for roads and polygons comes if roads are selected by using

WHERE ST_Covers='TRUE' OR ST_Crosses='TRUE'

ST_Covers is different than ST_Contains because it selects also those roads which are exactly following the border (also = Touches). That might be the right thing to do in this case. As a result those roads will belong to both of the neighbouring areas. Amusing blog about this is at http://lin-ear-th-inking.blogspot.fi/2007/06/subtleties-of-ogc-covers-spatial.html

Edit: If you do not want to select the roads which run along the border, the same result as with ST_Contains OR ST_Crosses comes from

ST_Intersects AND NOT ST_Touches

The DE-9IM model is good reading http://en.wikipedia.org/wiki/DE-9IM and PostGIS documentation has nice images but for each function on a separate page like http://postgis.net/docs/ST_Touches.html and http://postgis.net/docs/ST_Crosses.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.