Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(sf)
- lat_lon <- data.frame(
- lat = c(86, 87, 88),
- lon = c(43, 44, 44.5)
- )
- lat_lon
- #> lat lon
- #> 1 86 43.0
- #> 2 87 44.0
- #> 3 88 44.5
- # Turn this into a geometry
- # EPSG 4326 is a standard coordinate reference system for lat-lon
- latlon_sf <- st_as_sf(lat_lon, coords = c("lon", "lat"), crs = 4326)
- # Convert to sinusoidal coordinates (in m) -- EPSG 54008
- latlon_sin <- st_transform(latlon_sf, st_crs(54008))
- latlon_sin
- #> Simple feature collection with 3 features and 0 fields
- #> geometry type: POINT
- #> dimension: XY
- #> bbox: xmin: 173463.1 ymin: 9555197 xmax: 335023.8 ymax: 9778579
- #> epsg (SRID): 54008
- #> proj4string: +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
- #> geometry
- #> 1 POINT (335023.8 9555197)
- #> 2 POINT (257204.5 9666887)
- #> 3 POINT (173463.1 9778579)
- # Note that the values are now weird and huge. That's because they are
- # in `m` from a reference point (lat = 0, lon = 0)
- # calculate the distance between all points
- st_distance(latlon_sin)
- #> Units: [m]
- #> [,1] [,2] [,3]
- #> [1,] 0.0 136126.5 275683.1
- #> [2,] 136126.5 0.0 139598.3
- #> [3,] 275683.1 139598.3 0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement