62278

R - Calculate distance between two points along a polyline

Question:

In R - I have imported a polyline shapefile that is not straight (represents a winding interstate highway) into the environment. I have read a .csv file that contains points (latitude/longitude in decimal degrees) into the environment. All of those points lie along the polyline.

If I take two random points I can calculate the "as the crow flies" distance between them using great circle distance calculation. But what is needed is distance traveled along the polyline. See reference image:

<a href="https://i.stack.imgur.com/zhorb.png" rel="nofollow">https://i.stack.imgur.com/zhorb.png</a>

Is anyone aware of an R package that can calculate the distance between two lat/lon points along a polyline?

Answer1:

Package PBSmapping has a calcLength function which directly calculates the length of a polyline or polygon (in what it terms a PolySet). The package can import ESRI shapefiles as well, if your shapefile is in that format.

Example of a simple polyline:

line = read.table(text = "X, Y, POS, PID 37.772, -122.214, 1, 1 21.291, -157.821, 2, 1 -18.142, 178.431, 3, 1 -27.467, 153.027, 4, 1", header = TRUE, sep = ",") library(PBSmapping) pline = as.PolySet(line, projection = 1) calcLength(pline) PID length 1 1 404.8539 plotLines(pline)

<a href="https://i.stack.imgur.com/ff5cZ.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/ff5cZ.png" data-original="https://i.stack.imgur.com/ff5cZ.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Recommend

  • Azure blobs and thumbnails
  • UINavigationItem title label set width?
  • html spacing inside the table
  • Pointlabels not displaying when data point is at maximum
  • How do you directly upgrade ASP.NET MVC1 to MVC3?
  • Prevent top-level menu link in Wordpress admin menu from working
  • Summarize a data.table with unreliable data
  • Removing path from a zip file using python
  • How do you directly upgrade ASP.NET MVC1 to MVC3?
  • Showing less then 1% on the BootStrap progress bar
  • Normalize concatenated Excel data
  • MVC4 ActionLink syntax for use with hidden text box values
  • What is the exact way of using regex_iterator in C++?
  • Geometry shader doesn't do anything when fed GL_POINTS
  • Parse returned C# list in AJAX success function
  • angularjs ng-bind-html html input part missing
  • How do I properly code a javascript property and method using the 'prototype' function?
  • how to calculate distance between two points in google maps?
  • Circle movement upon rectangle Collision
  • MATLAB - Classification output
  • SQL Server re-calculate or not?
  • Stitching 2 images (OpenCV)
  • Receive mouse move even cursor is outside control
  • SQL - Select lowest values with group by and order by?
  • Cypher - matching two different possible paths and return both
  • Is it possible to define rest argument in OCaml?
  • C# fibonacci function returning errors
  • Reading a file into a multidimensional array
  • RxJava debounce by arbitrary value
  • Object and struct member access and address offset calculation
  • Using a canvas object in a thread to do simple animations - Java
  • Hardware Accelerated Image Scaling in windows using C++
  • one Local Olampyad Questions on Informatic in 2011
  • Magento Fatal error: Maximum execution error solution, on WAMP
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Date difference with leap year
  • Is possible to count alias result on mysql
  • Incrementing object id automatically JS constructor (static method and variable)
  • Hazelcast - OperationTimeoutException