[R-sig-eco] adehabitat - data projection

Mathieu Basille basille at biomserv.univ-lyon1.fr
Wed Feb 3 21:40:12 CET 2010


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 :
> I'm just starting to use adehabitat to do home range calculations, and I'm
> wondering if there is a simple way to convert my xy coordinates (which are
> in decimal degrees) to UTMs or kilometers. The demo(homerange) already has
> their coordinates listed in kilometers, so I'm not quite sure how to get to
> that step.
> 
> Another option would be to project my data. There is a package called
> mapproj, but I also am not sure how that works. I usually work with GIS so R
> is new to me. Any help is appreciated. Thank you.

-- 

~$ whoami
Mathieu Basille, Post-Doc

~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec

~$ info
http://ase-research.org/basille

~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.



More information about the R-sig-ecology mailing list