1

I have two tables one called test lines and other points called testepoint with some geometries drawn in QGIS to test my sql. Are as in the image below:

QGIS

I want to select the points that inteceptam a row, the result should return me the id of these three points:

Selected

This is my sql that returns no records:

 Select testepoint."id" 
 FROM
 testepoint
inner JOIN
 teste
 ON ST_Intersects(teste.geom, testepoint.geom)

Can anyone help me on what I might be doing wrong? I drew the shapes in QGIS using Google Streets layer based on EPSG: 3857 and carried in PostGIS


I ran the sql:

 Select testepoint."id"
FROM
testepoint
inner JOIN
teste
ON ST_DWithin(teste.geom, testepoint.geom, 1)
WHERE
teste."id"= 1 

The result:

result

But I need this order: 1,2,4 The order of alignment.

order

underdark
84.9k22 gold badges237 silver badges419 bronze badges
asked May 6, 2014 at 13:51

1 Answer 1

2

It's probably because the points don't exactly intersect the line. I'd modify your query to use a distance based search with a very small search distance. Something like this should work:

Select testepoint."id" 
FROM
testepoint
inner JOIN
teste
ON ST_DWithin(teste.geom, testepoint.geom, 1)

Where the "1" represents the largest acceptable distance from the line you want, in whichever units the table's coordinate system uses.

answered May 6, 2014 at 23:00
3
  • Very good ndawson! Your tip worked, but I noticed something: I need the points listed in order of the direction in which the line was drawn. Below is the image that best illustrates my goal. Commented May 7, 2014 at 12:29
  • Add an "ORDER BY ST_Line_Locate_Point(teste.geom, testepoint.geom)". That should order it by ascending distance from the start of the line. Commented May 7, 2014 at 12:35
  • The error: [Err] ERROR: line_locate_point: 1st arg is not a line So I consulted the geometry type of table test (which contains the lines) using ST_GeometryType (Geomagnetic) function and returned ST_MultiLineString. Commented May 7, 2014 at 13:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.