Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. library(sf)
  2.  
  3. lat_lon <- data.frame(
  4. lat = c(86, 87, 88),
  5. lon = c(43, 44, 44.5)
  6. )
  7.  
  8. lat_lon
  9. #> lat lon
  10. #> 1 86 43.0
  11. #> 2 87 44.0
  12. #> 3 88 44.5
  13.  
  14. # Turn this into a geometry
  15. # EPSG 4326 is a standard coordinate reference system for lat-lon
  16. latlon_sf <- st_as_sf(lat_lon, coords = c("lon", "lat"), crs = 4326)
  17.  
  18. # Convert to sinusoidal coordinates (in m) -- EPSG 54008
  19. latlon_sin <- st_transform(latlon_sf, st_crs(54008))
  20. latlon_sin
  21. #> Simple feature collection with 3 features and 0 fields
  22. #> geometry type: POINT
  23. #> dimension: XY
  24. #> bbox: xmin: 173463.1 ymin: 9555197 xmax: 335023.8 ymax: 9778579
  25. #> epsg (SRID): 54008
  26. #> proj4string: +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
  27. #> geometry
  28. #> 1 POINT (335023.8 9555197)
  29. #> 2 POINT (257204.5 9666887)
  30. #> 3 POINT (173463.1 9778579)
  31. # Note that the values are now weird and huge. That's because they are
  32. # in `m` from a reference point (lat = 0, lon = 0)
  33.  
  34. # calculate the distance between all points
  35. st_distance(latlon_sin)
  36. #> Units: [m]
  37. #> [,1] [,2] [,3]
  38. #> [1,] 0.0 136126.5 275683.1
  39. #> [2,] 136126.5 0.0 139598.3
  40. #> [3,] 275683.1 139598.3 0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement