daydayup
daydayup

Reputation: 2317

how to check if two points are on the same line in postgis

I have extracted the geometries of all intersections and I want to find all the connections (such as intersection one is connected to intersections two, three, four, five). I was thinking about achieving this by checking if two intersections (points) are on the same LineString. Does anybody know if this is a good way to do so? Is there any functions to call to check if two points are on the same line? Thank you

Upvotes: 0

Views: 1277

Answers (1)

user464502
user464502

Reputation: 2373

If the two points (or any number of points) are in a Multipoint you can use ST_Contains(Linestring, Multipoint) which will return true

if and only if no points of B lie in the exterior of A, and at least one point of the interior of B lies in the interior of A.

http://postgis.net/docs/manual-2.1/ST_Contains.html

You will need to collect up your pairs into multipoints first, which will be a number of multipoints proportional to n^2 if you want to test all possible pairwise sets, which could be prohibitive. In that case, I would generate a table matching up points to each linestring that contains them, and then aggregating that table grouping by linestring.

See also http://postgis.net/docs/manual-2.1/ST_Relate.html for a more general test of spatial relationships between objects.

Upvotes: 1

Related Questions