colin colin - 3 months ago 10
R Question

Convert normal latitiude/longitude to Alber's Equal Area in R

I have a data set,

dat
, in R with coordiantes in WGS84. that looks like this (
dput
output below)

dat <- structure(list(latitude = c(46.414597, 46.137664, 46.567187,
45.730901, 43.379185, 46.657572), longitude = c(-86.030373, -85.990492,
-87.954285, -87.674475, -86.226577, -89.807461), mat = c(5.21999979019165,
5.55999994277954, 4.03000020980835, 5.40000009536743, 8.3100004196167,
4.30000019073486), map = c(824.52001953125, 822.77001953125,
806.900024414062, 780.510009765625, 885.940002441406, 912.789978027344
)), .Names = c("latitude", "longitude", "mat", "map"), row.names = c(NA,
-6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x10200fd78>)

latitude longitude mat map
1: 46.41460 -86.03037 5.22 824.52
2: 46.13766 -85.99049 5.56 822.77
3: 46.56719 -87.95428 4.03 806.90
4: 45.73090 -87.67448 5.40 780.51
5: 43.37918 -86.22658 8.31 885.94
6: 46.65757 -89.80746 4.30 912.79


I use the
sp
package to make this a spatial points data frame:

require(sp)
dat.sp <- SpatialPointsDataFrame(c(dat[,c('longitude','latitude')]), data = dat)


How can I convert these coordinates to the Alber's equal area projection?

Answer
library(sp)
dat.sp <- as.data.frame(dat)
dat.sp <- SpatialPointsDataFrame(c(dat.sp[,c('longitude','latitude')]), data = dat.sp)

library(mapproj)
mapproject(dat.sp$longitude,dat.sp$latitude,projection ="albers", par=c(39,49))
$x
[1]  0.0224144915  0.0230045456 -0.0006617149  0.0027256535  0.0211352166 -0.0227947615

$y
[1] -0.9929906 -0.9978269 -0.9905721 -1.0052115 -1.0462001 -0.9887275

$range
[1] -0.02279476  0.02300455 -1.04620005 -0.98872752

$error
[1] 0

Note that I set the parameters kind of randomly in this example and you'll want to choose ones that make sense for you. You can find more information here and there's an example in the documentation as well.