Skip to main content
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

I'm looking to calculate the approximate distance in miles from a linestring.

[This post][1] 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. [1]: How do I calculate ST_Length in miles?How do I calculate ST_Length in miles?

I'm looking to calculate the approximate distance in miles from a linestring.

[This post][1] 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. [1]: How do I calculate ST_Length in miles?

I'm looking to calculate the approximate distance in miles from a linestring.

[This post][1] 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. [1]: How do I calculate ST_Length in miles?

Tweeted twitter.com/StackGIS/status/790177266097590276
edited title
Link
ahmadhanb
  • 41.4k
  • 5
  • 54
  • 109

calculating Calculating mileage from linestring

Removed tag prefix from question title as per Jeff Atwood style preference
Link
underdark
  • 84.5k
  • 22
  • 233
  • 415
Loading
added 503 characters in body
Source Link
Loading
removed intro and thanks
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65
Loading
Source Link
Loading