Skip to content
Prev 5738 / 29559 Next

Calculating area of polygons

Thanks Roger,

Works a treat.

Wesley
On Thu, 14 May 2009, Wesley Roberts wrote:

            
The areas are calculated when the Polygon objects are created - they are 
used internally for ordering the painting of the polygons, largest first):

library(rgdal)
scot_BNG <- readOGR(system.file("vectors", package = "rgdal")[1],
   "scot_BNG")
summary(scot_BNG)
getClass("Polygon")
areas <- sapply(slot(scot_BNG, "polygons"), function(x) sapply(slot(x,
  "Polygons"), slot, "area"))
str(areas)

areas is a list - each member is the vector of areas for rings belonging 
to the Polygons objects. You may also need to access the "hole" slot to 
see which "are" seen as holes for your data.

The areas are OK for planar coordinates, but only for these - for plotting 
the values, although not correct, are adequate for plot ordering.

Hope this helps,

Roger
-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no