Length (meters) of a line_string

40 views
Skip to first unread message

Greg Scarich

unread,
Mar 4, 2018, 8:13:23 PM3/4/18
to RGeo-Users
Is there an RGeo method for calculating the length of a line_string? I mean the length in meters (or any other unit), not the number of characters which is what the length method usually returns.

Barrett Clark

unread,
Mar 5, 2018, 1:35:24 PM3/5/18
to RGeo-Users
No. It doesn't look like that is implemented. You can use ST_Length from PostGIS for that: https://postgis.net/docs/ST_Length.html

SELECT <FIELDS>, ST_Length(linestring_column) AS line_length FROM SOME_TABLE;

In a Rails application (in a model) you could create a method (or maybe a scope) to wrap that up and present it as an attribute on the object.

~Barrett

Greg

unread,
Mar 5, 2018, 1:53:44 PM3/5/18
to rgeo-...@googlegroups.com
Thank you for responding. Since my line_string is written a geojson, I would have to sort that part out. So for now manual calculation is easier. 

If I understand correctly the linestring_column would have to be a geometry.

My geojson looks like this: {"type":"LineString","coordinates":[[-118.25573325622828,34.045980983930036],[-118.2428586529568,34.03517030952861],[-118.20938468445094,34.049394594819795],[-118.21710944641383,34.03517030952861]]} so something thinks it’s a line_string, but not SQL.

--
You received this message because you are subscribed to a topic in the Google Groups "RGeo-Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rgeo-users/AYV4BeyYa6o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rgeo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages