I'm looking to calculate the approximate distance in miles from a linestring.
This post recommends using ST_Transform
in conjunction with the State Plane coordinate system for my area. In my case, I need to do this for many areas across the US, not just one. Is there a simpler way to calculate mileage without a need for the state-specific SRID?
For some context, I'm calculating the distance in mileage for dog walks. That means that the calculation doesn't need to 100% accurate, but being fairly close is a must. I do have the address for each walk available, which means I could use it to get the state-specific SRID, but I'd prefer to do it an automated fashion rather than having to build a lookup system on my own.
UPDATE
I'm running Postgres v9.5 and PostGIS v2.2.1.
The coordinates
column is of type GEOMETRY
and is in the 4326
coordinate system.
I've started with the following query:
select
appointment_id,
(
ST_Length(
ST_Transform(
ST_Makeline(coordinates ORDER BY captured_at),
2877
)
) / 5280
) as distance
from path
where appointment_id = '38f6f1e3-d865-5a57-b87b-597d3f68f405'
group by appointment_id;
As mentioned above, I'm using some code from the example in the referenced post.