[R-sig-Geo] Converting shapefile from gridded to lat/ lng

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Jan 20 09:25:19 CET 2014


On Mon, Jan 20, 2014 at 8:10 AM, Pascal Oettli <kridox at ymail.com> wrote:

> crs.ll <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
> crs.tmerc <- "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717
> +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs"
>
> authoritiesMap.TMERC <- readShapePoly("LAD_Pop_EngWales2011",
> proj4string=CRS(crs.tmerc))

proj4string(authorities.Map) = CRS(crs.tmerc) # surely?

> authoritiesMap.LL <- spTransform(authoritiesMap.TMERC, CRS(crs.ll))

If you use readOGR from package:rgdal *and* your shapefile comes with
the correct .prj file (in the same folder with the .shp and .dbf) then
the spatial polygons object will already have the correct CRS assigned
to it and you can skip half these steps. Something like:

map = readOGR(".","LAD_Pop_EngWales2011")
mapLL = spTransform(map, CRS("+init=epsg:4326"))

 - epsg code 4326 is the lat-long system as used by GPS. epsg code
27700 is the UK national grid format which might be what you original
file is, or something else entirely! Anyway, if you've got a .prj
file, its a two-liner.



More information about the R-sig-Geo mailing list