[R-sig-Geo] Calculate the length of hail paths

St John Brown st_john_brown at yahoo.com
Mon Oct 27 15:49:48 CET 2014


Hello,

I am trying to calculate the the length of the trajectory of historic hail storms in the United States. I have written the R code to do this but my results do not seem valid. The majority of my results are around 14 meters which does not seem correct.

My data comes from the NOAA in the form of a shape file (hail.zip) [1]. When I read the shape file I have an object of class SpatialLinesDataframe. The individual lines represent the paths of the historic hail storms.

Below I have created an example SpatialLines object with lines from the original data and my method for calculating the path length. As you can see the results are around 14 meters. Am I calculating the distances correctly?

I appreciate any help!

[1] http://www.spc.noaa.gov/gis/svrgis/

library(sp)
library(geosphere)

#create example SpatialLines obj
myLines1 = Lines(list(Line(matrix(c(-519049.1, -519039.1, -736427.4, -736417.4), nrow=2, ncol=2))), ID="1")
myLines2 = Lines(list(Line(matrix(c(527165, 527175, 261338.5, 261348.5), nrow=2, ncol=2))), ID="2")
proj_str_lcc = CRS("+proj=lcc +lat_1=33 +lat_2=45 +lat_0=39 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0")
mySpLines = SpatialLines(list(myLines1,myLines2), proj4string=proj_str_lcc)

#calculate distance of line paths
proj.str.alb = CRS("+proj=longlat +datum=WGS84")
mySpLines_alb = spTransform(mySpLines, CRS=proj.str.alb)

res = lapply(slot(mySpLines_alb, "lines"), function(x) lapply(slot(x, "Lines"),function(y) slot(y, "coords")))

f = function(i){
  end_pnts = unlist(res[i],use.names = F)
  p1 = end_pnts[c(1,3)]
  p2 = end_pnts[c(2,4)]
  return(distCosine(p1,p2)) #meters
}

d = sapply(1:length(res), FUN=f)

> d
[1] 14.14557 14.21278 #meters



More information about the R-sig-Geo mailing list