calcArea: Calculate the Areas of Polygons

View source: R/PBSmapping.r

calcAreaR Documentation

Calculate the Areas of Polygons

Description

Calculate the areas of polygons found in a PolySet.

Usage

calcArea (polys, rollup = 3)

Arguments

polys

PolySet to use.

rollup

level of detail in the results; 1 = PIDs only, by summing all the polygons with the same PID, 2 = outer contours only, by subtracting holes from their parent, and 3 = no roll-up.

Details

If rollup equals 1, the results contain an area for each unique PID only. When it equals 2, they contain entries for outer contours only. Finally, setting it to 3 prevents roll-up, and they contain areas for each unique (PID, SID).

Outer polygons have positive areas and inner polygons negative areas. When polygons are rolled up, the routine sums the positive and negative areas and consequently accounts for holes.

If the PolySet's projection attribute equals "LL", the function projects the PolySet in UTM first. If the PolySet's zone attribute exists, it uses it for the conversion. Otherwise, it computes the mean longitude and uses that value to determine the zone. The longitude range of zone i is -186 + 6 i^\circ < x \le -180 + 6 i^\circ.

Value

PolyData with columns PID, SID (may be missing), and area. If the projection equals "LL" or "UTM", the units of area are square kilometres.

Author(s)

Nicholas M. Boers, Staff Software Engineer
Jobber, Edmonton AB
Last modified Rd: 2022-09-06

See Also

calcCentroid, calcLength, calcMidRange, calcSummary, locatePolys.

Examples

local(envir=.PBSmapEnv,expr={
  #--- load the data (if using R)
  if (!is.null(version$language) && (version$language == "R"))
    data(nepacLL,envir=.PBSmapEnv)
  #--- convert LL to UTM so calculation makes sense
  attr(nepacLL, "zone") <- 9
  nepacUTM <- convUL(nepacLL)
  #--- calculate and print the areas
  print(calcArea(nepacUTM))
})

PBSmapping documentation built on Sept. 30, 2024, 9:21 a.m.