1

I am trying to get the length of a line between two selected points. The points reside in table subs and are utilizing srid 4236.

I can verify the selection exists...

SELECT id, name, geom FROM subs where  name = 'DALLAM COUNTY'or name = 'DALHART';

Which returns the expected results...

enter image description here

However when I try to construct line with the same selection I get empty results?

SELECT ST_Length(ST_Transform(ST_MakeLine(geom), 4236)) FROM
    subs where  name = 'DALLAM COUNTY'or name = 'DALHART';

The sql returns empty results.

enter image description here

What am I missing?

2 Answers 2

1

It seems you are attempting to find the distance between two geometries in the same table. Try this:

SELECT ST_Distance(a.geom::geography, b.geom::geography) AS dist_m
FROM subs a, subs b
WHERE a.name='DALLAM COUNTY' AND b.name='DALHART';

The result from ST_Distance will be the minimum distance of a geodesic between the two geometries in metres.

2
  • This worked for me. Thank you for commenting. Out of curiosity why meters? Is there anyway of casting to feet directly or should I just multiply the result? Commented Feb 24, 2017 at 16:01
  • Metres are fumdimental SI units of length; divide by 0.3048 to get feet.
    – Mike T
    Commented Feb 24, 2017 at 20:57
0

From your screenshot it looks as though your geometry is of type multipoint, so naturally it doesn't have a length.

It also appears that the transform is unnecessary as the data is already in 4326 projection.

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.