CRS for the European Biogeographical Regions in R
On Sun, Feb 8, 2015 at 12:54 PM, Roland Kaiser <kardinal.eros at gmail.com> wrote:
Hi! Sorry for the confusion, I followed the link on the top the page "Note: new version is available!?. For some reason, this ZIP archive has a *.qpj instead of *.prj file. Of course, readOGR treats the *prj correctly, if present!
With the qpj file:
> r = readOGR(".","BiogeoRegions2011")
OGR data source with driver: ESRI Shapefile
Source: ".", layer: "BiogeoRegions2011"
with 12 features and 5 fields
Feature type: wkbPolygon with 2 dimensions
Fails:
> proj4string(r)
[1] NA
But if you simply rename the .qpj file as .prj then:
> file.rename("BiogeoRegions2011.qpj","BiogeoRegions2011.prj")
[1] TRUE
Maybe...
> r = readOGR(".","BiogeoRegions2011")
OGR data source with driver: ESRI Shapefile
Source: ".", layer: "BiogeoRegions2011"
with 12 features and 5 fields
Feature type: wkbPolygon with 2 dimensions
It all works:
> proj4string(r)
[1] "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000
+ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
Is a .qpj file a projection written by QGIS for some reason?
Barry
-Roli
Am 08.02.2015 um 12:37 schrieb Barry Rowlingson <b.rowlingson at lancaster.ac.uk>: On Sat, Feb 7, 2015 at 4:53 PM, Roland Kaiser <kardinal.eros at gmail.com> wrote:
# the projection information is given in the *.qpj file
I can't see a *.qpj file in that shapefile. There is a *.prj file which contains projection info.
# unfortunately, it is not read from the dataset by the OGR driver
The *.prj file **is** read when using readOGR:
r=readOGR(".","BiogeoRegions2011")
OGR data source with driver: ESRI Shapefile Source: ".", layer: "BiogeoRegions2011" with 12 features and 4 fields Feature type: wkbPolygon with 2 dimensions
proj4string(r)
[1] "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs" - that's a full projection specification, rather than an epsg code though, because that's what's in the file.
# we have do define it manually by specifing argument p4s
No we don't!
pg <- readOGR(dsn = "BiogeoRegions2011_shapefile",
layer = "BiogeoRegions2011", p4s = "+init=epsg:3035")
Is the .prj file text coding the same projection as epsg:3035? http://epsg.io/ says 3035 is: +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs So yes. But there's no need to specify it in readOGR since you have the .prj file. The maptools functions readShapeSpatial and friends ignore the .prj file - I don't know why they exist any more!
r2=readShapeSpatial("BiogeoRegions2011.shp")
proj4string(r2)
[1] NA Ouch. Barry