1

I tried

select st_astext(geom) from table where st_pointn(geom, 1) = st_pointn(geom, 2)

But I get some results which don't match the criteria. For example: LINESTRING(-117.1642086 34.2779308,-117.1642145 34.2779305)

Why do I get the wrong answer for that query?

(I have since changed my query to use st_length).

1 Answer 1

1

It seems that it is not correct to compare geometries with "=" operator but you must use "ST_Equals" instead. This is your original case:

SELECT ST_ASText(st_pointn(foo.geom, 1)), ST_AsText(st_pointn(foo.geom, 2)) from (
SELECT ST_GeomFromText('LINESTRING(-117.1642086 34.2779308,-117.1642145 34.2779305)') as geom
) foo
where st_pointn(foo.geom, 1) = st_pointn(foo.geom, 2);


"POINT(-117.1642086 34.2779308)";"POINT(-117.1642145 34.2779305)"

Odd result which seems to suggest the different points are equal. However, result from this query with ST_Equals gives an empty result:

SELECT ST_ASText(st_pointn(foo.geom, 1)) as point1, ST_AsText(st_pointn(foo.geom, 2)) as point2 from (
SELECT ST_GeomFromText('LINESTRING(-117.1642086 34.2779308,-117.1642145 34.2779305)') as geom
) foo
where ST_Equals(st_pointn(foo.geom, 1), st_pointn(foo.geom, 2))

Your Answer

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

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