Skip to content

adehabitat - data projection

1 message · Mathieu Basille

#
As previously highlighted by Kingsford and Tammy, you need to go through
the rgdal package, which handles projection systems in R (via the GDAL
library).

For example, say you have a data frame Toto with one column Lat, one
column Long giving coordinates from e.g. a GPS collar, and whatever
other columns. At the end you want the same data frame, but projected in
UTM zone 19 (datum NAD83). First you need to convert the data frame into
a SpatialPointsDataFrame (package sp)*:

coordinates(Toto) <- ~Long+Lat    # You provide the names of the columns

And then define the projection system:

proj4string(Toto) <- CRS("+proj=longlat +datum=WGS84")

Now, you need to know the parameters of you new projection. I find it
handy to look at the EPSG code of your projection, much easier to use
than the full series of parameters. First build the EPSG index:

EPSG <- make_EPSG()

Then you can search within it (here you need to adjust with what you're
looking for):

EPSG[grep("NAD83 / UTM zone 19", EPSG$note), ]

And finally, you can reproject using the EPSG code you found:

Toto <- spTransform(Toto, CRS("+init=epsg:26919"))

Now, you have a nice SpatialPointsDataFrame projected in the correct
projection system. If you want to use the points coordinates in home
range calculations, they are available with the function coordinates
again (which returns a matrix of coordinates):

Coord <- data.frame(coordinates(Toto))

Hope this helps,
Mathieu.


* I assumed you don't have NAs in the coordinates, otherwise you need to
adjust it a little bit to remove them (coordinates do not allow for NAs).


danik a ?crit :