Tuesday, 18 August 2015

shapefile - Understanding unit of area sizes calculated via rgeos::gArea?


I'm interested in finding the unit for the obtained area size of the polygons without refererring to the externally available documentation.



A suite of shapefiles is imported as follows:


tmpDir <- tempdir()

tmpFle <- tempfile(fileext = ".zip")
download.file(url = "https://borders.ukdataservice.ac.uk/ukborders/easy_download/prebuilt/shape/infuse_rgn_2011_clipped.zip",
destfile = tmpFle,
method = "wget")
unzip(zipfile = tmpFle, exdir = tmpDir)
shpsUK <- rgdal::readOGR(dsn = tmpDir,
layer = tools::file_path_sans_ext(dir(tmpDir)[3]))

Area sizes


oldScipen <- getOption("scipen")

options(scipen = 999)
format(summary(rgeos::gArea(shpsUK, byid = TRUE)),
big.mark = ",")
options(scipen = oldScipen)

which produces:


            Min.          1st Qu.           Median             Mean          3rd Qu.             Max. 
" 1,573,530,067" "13,003,803,228" "15,411,419,165" "14,492,421,008" "19,085,426,561" "23,851,569,172"

Can I determine the units of the obtained figures without referring to external documentation that may be available on the sources shapefiles?




Answer



The shapefiles you downloaded have projection information included in the .prj file:


PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]]

After loading in R, you can get a summary of spatial information which gives you that information and more:


>summary(shpsUK)

Object of class SpatialPolygonsDataFrame
Coordinates:
min max

x 82672.0 655604.7
y 5337.9 657534.1
Is projected: TRUE
proj4string :
[+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]
Data attributes:
geo_label geo_code
East Midlands :1 E12000001:1
East of England:1 E12000002:1

London :1 E12000003:1
North East :1 E12000004:1
North West :1 E12000005:1
South East :1 E12000006:1
(Other) :3 (Other) :3

The units are in metres (+units=m).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...