7

According to Wikipedia,

The predicates Contains and Within have subtle aspects to their definition which are contrary to intuition. For example,[10] a line L which is completely contained in the boundary of a polygon P is not considered to be contained in P. This quirk can be expressed as "Polygons do not contain their boundary". This issue is caused by the final clause of the Contains definition above: "at least one point of the interior of B lies in the interior of A". For this case, the predicate Covers has more intuitive semantics (see definition), avoiding boundary considerations.

If Polygons do not Contain their boundaries, do linestrings ever "contain" points?

7

At least according to PostGIS, a LINESTRING does CONTAIN the constituent point along the string, but it does not CONTAIN the terminal points,

-- false
SELECT ST_Contains(
  ST_MakeLine(ST_MakePoint(0,0), ST_MakePoint(1,1)),
  ST_MakePoint(1,1)
);

-- true
SELECT ST_Contains(
  ST_MakeLine(ST_MakePoint(0,0), ST_MakePoint(1,1)),
  ST_MakePoint(0.5,0.5)
);

While ST_Intersects will return true for both.

  • If you have a multipoint, with one point on the line and the other at the extremity, the line would contains the multipoint... but not if both are on the extremities (nor if one is clearly outside of the line) – JGH Sep 5 '18 at 17:56
  • 1
    just adding: terminal points are considered to be the boundary of a line, and contains requires at least one point of the interior to intersect the interior of the other - not given for a point on the lines boundary. I used the DE-9IM a lot, out of personal interest and for ultimate control of what relation is to be checked...its a little intense, each time again if not fully concentrated, but it's worth to give it a good read. all relation functions are, of course, only wrappers around this model, and the relation concepts are mostly standardized, e.g. the way contains is interpreted. – ThingumaBob Sep 5 '18 at 20:17
  • the interior of a geometry is always of the expected dimension, the boundary of one lesser. except for points, where both predicates fall on the same entity...thus, a point can contain a point... – ThingumaBob Sep 5 '18 at 20:28
  • no, pardon me, I think that might even be true for points, where per definition there is a null-dimensional border...when I got the time, I'll back all this up with references and add an informative answer. hope I find that time... – ThingumaBob Sep 5 '18 at 20:54
  • SELECT ST_Contains( ST_MakePoint(0,0), ST_MakePoint(0,0) ); returns true. – Evan Carroll Sep 5 '18 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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