Skip to main content
Tweeted twitter.com/StackGIS/status/728508994155876352
removed thanks
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

I have a problem to check if a Linestring contains a Point. I consider the straight line y = 0.1 x , and take by it a segment l='Linestring( 0 0 , 4 0.4 )' and a Point p on segment l, p = 'Point(1.5 0.15)'. If I check ST_Contains(l,p) the result is false and the distance ST_Distance(l,p) is near to zero, but this is wrong because the Point is on the Linestring. If I try with p= 'Point(2 0.2)' the result is right.

What is the problem?

Thanks so much.

WITH 
     l AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     p AS (
       SELECT ST_GeomFromText('Point(1.5 0.15)') AS geom                     -- point on the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_Intersection(p.geom,l.geom)) as ST_Intersection,
        ST_Distance(p.geom,l.geom),
        ST_Contains(l.geom,p.geom),
        ST_Intersects(p.geom,l.geom),
        ST_AsText(ST_Line_Interpolate_Point(l.geom,1.5/4)) as ST_Substring       -- point in position 1.5/4 of l 
 FROM l,p

Result 1

EDIT: My origin problem was: LineString L1 contains Linestring L2 but if I do ST_SymDifference(l1.geom,l2.geom) the result is incorrect.

WITH 
     l1 AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     l2 AS (
       SELECT ST_GeomFromText('LineString(0 0 , 1.5 0.15)') AS geom             -- segment of the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_SymDifference(l1.geom,l2.geom)) as ST_Intersection     
 FROM l1,l2

Result 2

I have a problem to check if a Linestring contains a Point. I consider the straight line y = 0.1 x , and take by it a segment l='Linestring( 0 0 , 4 0.4 )' and a Point p on segment l, p = 'Point(1.5 0.15)'. If I check ST_Contains(l,p) the result is false and the distance ST_Distance(l,p) is near to zero, but this is wrong because the Point is on the Linestring. If I try with p= 'Point(2 0.2)' the result is right.

What is the problem?

Thanks so much.

WITH 
     l AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     p AS (
       SELECT ST_GeomFromText('Point(1.5 0.15)') AS geom                     -- point on the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_Intersection(p.geom,l.geom)) as ST_Intersection,
        ST_Distance(p.geom,l.geom),
        ST_Contains(l.geom,p.geom),
        ST_Intersects(p.geom,l.geom),
        ST_AsText(ST_Line_Interpolate_Point(l.geom,1.5/4)) as ST_Substring       -- point in position 1.5/4 of l 
 FROM l,p

Result 1

EDIT: My origin problem was: LineString L1 contains Linestring L2 but if I do ST_SymDifference(l1.geom,l2.geom) the result is incorrect.

WITH 
     l1 AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     l2 AS (
       SELECT ST_GeomFromText('LineString(0 0 , 1.5 0.15)') AS geom             -- segment of the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_SymDifference(l1.geom,l2.geom)) as ST_Intersection     
 FROM l1,l2

Result 2

I have a problem to check if a Linestring contains a Point. I consider the straight line y = 0.1 x , and take by it a segment l='Linestring( 0 0 , 4 0.4 )' and a Point p on segment l, p = 'Point(1.5 0.15)'. If I check ST_Contains(l,p) the result is false and the distance ST_Distance(l,p) is near to zero, but this is wrong because the Point is on the Linestring. If I try with p= 'Point(2 0.2)' the result is right.

What is the problem?

WITH 
     l AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     p AS (
       SELECT ST_GeomFromText('Point(1.5 0.15)') AS geom                     -- point on the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_Intersection(p.geom,l.geom)) as ST_Intersection,
        ST_Distance(p.geom,l.geom),
        ST_Contains(l.geom,p.geom),
        ST_Intersects(p.geom,l.geom),
        ST_AsText(ST_Line_Interpolate_Point(l.geom,1.5/4)) as ST_Substring       -- point in position 1.5/4 of l 
 FROM l,p

Result 1

EDIT: My origin problem was: LineString L1 contains Linestring L2 but if I do ST_SymDifference(l1.geom,l2.geom) the result is incorrect.

WITH 
     l1 AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     l2 AS (
       SELECT ST_GeomFromText('LineString(0 0 , 1.5 0.15)') AS geom             -- segment of the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_SymDifference(l1.geom,l2.geom)) as ST_Intersection     
 FROM l1,l2

Result 2

added 649 characters in body
Source Link
Jkr
  • 61
  • 4

I have a problem to check if a Linestring contains a Point. I consider the straight line y = 0.1 x , and take by it a segment l='Linestring( 0 0 , 4 0.4 )' and a Point p on segment l, p = 'Point(1.5 0.15)'. If I check ST_Contains(l,p) the result is false and the distance ST_Distance(l,p) is near to zero, but this is wrong because the Point is on the Linestring. If I try with p= 'Point(2 0.2)' the result is right.

What is the problem?

Thanks so much.

WITH 
     l AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     p AS (
       SELECT ST_GeomFromText('Point(1.5 0.15)') AS geom                     -- point on the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_Intersection(p.geom,l.geom)) as ST_Intersection,
        ST_Distance(p.geom,l.geom),
        ST_Contains(l.geom,p.geom),
        ST_Intersects(p.geom,l.geom),
        ST_AsText(ST_Line_Interpolate_Point(l.geom,1.5/4)) as ST_Substring       -- point in position 1.5/4 of l 
 FROM l,p

ResultResult 1

EDIT: My origin problem was: LineString L1 contains Linestring L2 but if I do ST_SymDifference(l1.geom,l2.geom) the result is incorrect.

WITH 
     l1 AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     l2 AS (
       SELECT ST_GeomFromText('LineString(0 0 , 1.5 0.15)') AS geom             -- segment of the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_SymDifference(l1.geom,l2.geom)) as ST_Intersection     
 FROM l1,l2

Result 2

I have a problem to check if a Linestring contains a Point. I consider the straight line y = 0.1 x , and take by it a segment l='Linestring( 0 0 , 4 0.4 )' and a Point p on segment l, p = 'Point(1.5 0.15)'. If I check ST_Contains(l,p) the result is false and the distance ST_Distance(l,p) is near to zero, but this is wrong because the Point is on the Linestring. If I try with p= 'Point(2 0.2)' the result is right.

What is the problem?

Thanks so much.

WITH 
     l AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     p AS (
       SELECT ST_GeomFromText('Point(1.5 0.15)') AS geom                     -- point on the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_Intersection(p.geom,l.geom)) as ST_Intersection,
        ST_Distance(p.geom,l.geom),
        ST_Contains(l.geom,p.geom),
        ST_Intersects(p.geom,l.geom),
        ST_AsText(ST_Line_Interpolate_Point(l.geom,1.5/4)) as ST_Substring       -- point in position 1.5/4 of l 
 FROM l,p

Result

I have a problem to check if a Linestring contains a Point. I consider the straight line y = 0.1 x , and take by it a segment l='Linestring( 0 0 , 4 0.4 )' and a Point p on segment l, p = 'Point(1.5 0.15)'. If I check ST_Contains(l,p) the result is false and the distance ST_Distance(l,p) is near to zero, but this is wrong because the Point is on the Linestring. If I try with p= 'Point(2 0.2)' the result is right.

What is the problem?

Thanks so much.

WITH 
     l AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     p AS (
       SELECT ST_GeomFromText('Point(1.5 0.15)') AS geom                     -- point on the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_Intersection(p.geom,l.geom)) as ST_Intersection,
        ST_Distance(p.geom,l.geom),
        ST_Contains(l.geom,p.geom),
        ST_Intersects(p.geom,l.geom),
        ST_AsText(ST_Line_Interpolate_Point(l.geom,1.5/4)) as ST_Substring       -- point in position 1.5/4 of l 
 FROM l,p

Result 1

EDIT: My origin problem was: LineString L1 contains Linestring L2 but if I do ST_SymDifference(l1.geom,l2.geom) the result is incorrect.

WITH 
     l1 AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     l2 AS (
       SELECT ST_GeomFromText('LineString(0 0 , 1.5 0.15)') AS geom             -- segment of the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_SymDifference(l1.geom,l2.geom)) as ST_Intersection     
 FROM l1,l2

Result 2

Source Link
Jkr
  • 61
  • 4

PostGIS - Linestring doesn't contain a Point - Problem

I have a problem to check if a Linestring contains a Point. I consider the straight line y = 0.1 x , and take by it a segment l='Linestring( 0 0 , 4 0.4 )' and a Point p on segment l, p = 'Point(1.5 0.15)'. If I check ST_Contains(l,p) the result is false and the distance ST_Distance(l,p) is near to zero, but this is wrong because the Point is on the Linestring. If I try with p= 'Point(2 0.2)' the result is right.

What is the problem?

Thanks so much.

WITH 
     l AS (
           SELECT ST_GeomFromText('Linestring( 0 0 ,  4 0.4 )') AS geom          -- segment of the straight line y = 0.1 x
       ),
     p AS (
       SELECT ST_GeomFromText('Point(1.5 0.15)') AS geom                     -- point on the straight line y = 0.1 x
       )
       
 SELECT ST_AsText(ST_Intersection(p.geom,l.geom)) as ST_Intersection,
        ST_Distance(p.geom,l.geom),
        ST_Contains(l.geom,p.geom),
        ST_Intersects(p.geom,l.geom),
        ST_AsText(ST_Line_Interpolate_Point(l.geom,1.5/4)) as ST_Substring       -- point in position 1.5/4 of l 
 FROM l,p

Result