Guest User

Untitled

a guest
Jan 12th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. # Load Libraries ----------------------------------------------------------
  2.  
  3. library('sf')
  4.  
  5. # Test data ---------------------------------------------------------------
  6.  
  7. points.df <- data.frame(
  8. 'x' = c(-53.50000, -54.15489, -54.48560, -52.00000, -52.57810, -49.22097, -48.00000),
  9. 'y' = c(-38.54859, -41.00000, -38.80000, -38.49485, -38.00000, -40.50000, -37.74859)
  10. )
  11.  
  12.  
  13. line.df <- data.frame(
  14. 'x' = c(-54.53557, -52.00000, -50.00000, -48.00000, -46.40190),
  15. 'y' = c(-39.00000, -38.60742, -38.08149, -38.82503, -37.00000)
  16. )
  17.  
  18. # Create 'sf' objects -----------------------------------------------------
  19.  
  20. points.sf <- st_as_sf(points.df, coords = c("x", "y"))
  21.  
  22. st_crs(points.sf) <- st_crs(4326) # assign crs
  23. points.sf <- st_transform(points.sf, crs = 32721) # transform
  24.  
  25. line.sf <- st_sf(id = 'L1', st_sfc(st_linestring(as.matrix(line.df), dim = "XY")))
  26. st_crs(line.sf) <- st_crs(4326) # assign crs
  27. line.sf <- st_transform(line.sf, crs = 32721) # transform
  28.  
  29.  
  30. # Plots -------------------------------------------------------------------
  31.  
  32. xmin <- min(st_bbox(points.sf)[1], st_bbox(line.sf)[1])
  33. ymin <- min(st_bbox(points.sf)[2], st_bbox(line.sf)[2])
  34. xmax <- max(st_bbox(points.sf)[3], st_bbox(line.sf)[3])
  35. ymax <- max(st_bbox(points.sf)[4], st_bbox(line.sf)[4])
  36.  
  37. plot(points.sf, pch = 19, xlab = "Longitude", ylab = "Latitude",
  38. xlim = c(xmin,xmax), ylim = c(ymin,ymax), graticule = st_crs(4326), axes = TRUE)
  39.  
  40. plot(line.sf, col = "#C72259", add = TRUE)
  41. text(st_coordinates(points.sf), as.character(1:7), pos = 3)
Add Comment
Please, Sign In to add comment