[R-sig-Geo] map projections with sp data

Michael Sumner mdsumner at gmail.com
Fri Mar 16 01:28:27 CET 2012


spTransform in the rgdal package will do this very simply. You just
need the source metadata set on the original object, and spTransform
handles the rest.

>From the help page:

require(rgdal)
scot_BNG <- readOGR(system.file("vectors", package = "rgdal")[1], "scot_BNG")
     scot_LL <- spTransform(scot_BNG, CRS("+proj=longlat +datum=WGS84"))

## metadata is already correctly set
proj4string(scot_BNG)
## [1] " +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000
+y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy
+towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894"


class(scot_BNG)  ## "SpatialPolygonsDataFrame"

## transform (from whatever the current CRS is to any other supported
PROJ.4 CRS)
scot_LL <- spTransform(scot_BNG, CRS("+proj=longlat +datum=WGS84"))

mapproject (in package mapproj I assume) is a much more raw interface
for transforming from long/lat, and you might as well use ?project
from rgdal which also can do the inverse. If you cannot install rgdal
that's another story, but it's trivial on Windows (because of work by
the maintainers and the R Core Team), and well documented for other
platforms.

Cheers, Mike.


On Fri, Mar 16, 2012 at 11:15 AM, Jonathan Callahan
<jonathan at mazamascience.com> wrote:
> I am looking for a way to reproject data that exists in a
> SpatialPolygonsDataFrame. (I think it's the same data as in the rworldmap
> package.)
>
> I am quite familiar with mapproject() which works well the maps and mapdata
> packages and am hoping there is an equivalent to mapproject() that could
> work with SpatialPolygons data.
>
> Or is there a simple way to get the x an y data arrays out of the
> SpatialPolygons?
>
> Thanks in advance,
>
> Jon
>
> --
> Jonathan Callahan, PhD
> Mazama Science
> 206-708-5028
> mazamascience.com
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list