Area calculation in R
We can very easily calculate the area of all of the features of a polygon using gArea(). We use this to calculate the area, in square kilometers, of different districts in Bangladesh. First, we transform the area using spTransform() to Universal Transverse Mercator (UTM) with units in meters; this will make it easy to have the area in square kilometers. We'll use the reprojected map of Bangladesh with UTM in gArea() and use an additional argument, byid = TRUE, so that it computes the area for all unique features (in this case, districts). Now, as gArea() returns in square units of whatever unit in which the map was fetched, we'll get square meters returned by gArea(). So, divide this by 1,000 square to get square kilometers: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access