0

I have a LINESTRING made of two points start point and end point in spatialite.

UPDATE points SET road_geometry = GeomFromText('LINESTRING(24.889142 67.196188, 
24.889673 67.196579)',4326) where name='name';

and Now, I want to check that if any other point is within that line string or how far the point is from the LINESTRING.

1 Answer 1

2

Use either ST_Distance or PtDistWithin (see documentation). With the former you can test for the distance of your points and then select based on some distance criteria.

If you are wanting to test whether a point lies exactly on your line you could try doing an Intersection or use ST_Contains. My only hesitation with these approaches is that, because a point has no area or length, normal rounding errors within floating point coordinates may give false negatives, so ST_Distance and then a selection based on some acceptable threshold may be better in this case.

5
  • ST_Intersects finds also if point lies exactly on line. The SQL functions link is good now but this one stays up-to-date automatically gaia-gis.it/gaia-sins/spatialite-sql-latest.html
    – user30184
    Nov 3, 2014 at 8:56
  • st_intersects works fine when point lies exactly on line, but what when the point is few metres away from line?Maybe I also have to check for distance or there is any other approach....the linestring is actually a road and i want to know that if the user is on the road or not.
    – Ahmed
    Nov 3, 2014 at 9:06
  • Hence my comment about floating point rounding. Note that in my reply I advocate ST_Distance for your use-case. Nov 3, 2014 at 9:20
  • what if i create a buffer around the point and then check for intersection?Which approach is better?
    – Ahmed
    Nov 3, 2014 at 10:05
  • It depends on what you want to do after you have found your points. Nov 3, 2014 at 10:25

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.