Computing area of given polygon (in vector format) lying between specified lines of latitude?

by jO.   Last Updated December 07, 2017 10:22 AM

I have species distributions (in vector format) and I would like to calculate how much of the area for a given species distribution is within certain lines of latitude, such as temperate and tropic zones.

Using the Wikipedia definition: The north temperate zone extends from the Tropic of Cancer (approximately 23.5° north latitude) to the Arctic Circle (approximately 66.5° north latitude). The south temperate zone extends from the Tropic of Capricorn (approximately 23.5° south latitude) to the Antarctic Circle (at approximately 66.5° south latitude).

Thus, the tropics would be between 23.5° south latitude and 23.5° north latitude.

For example, using this shapefile of the Atlantic Ocean (choose shapefile in the drop-down menue) plotted on a worldmap, one could easily calculate the total area of the Atlantic Ocean;


ao <- readOGR(getwd(), layer="iho")
aof <- fortify(world, region="name")

# Not necessary for the calculation per se, but still nice. Although not the best looking map
world <- map("worldHires", col="gray90", fill=T)

# Plot 
pp <- ggplot(data = world, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "grey50") +
geom_polygon(data = AO, aes(x = long, y = lat, group = group), fill = alpha("cyan", 0.5)) +

# Total area
gArea(SpatialPolygons([email protected]))
[1] 7512.821

But how could we restrict the calculation of the area to specified lines of latitude, e.g. tropic and temperate zones as defined above?

Any pointers on this would be highly appreciated, thanks!


enter image description here

Answers 1

You can use functions from the rgeos package to extract such regions (e.g. gIntersection, gDifference). I use gDifference in this example, because gIntersection returns a SpatialCollections object here:

# define rectangular region 
y_lim <- c(-1, 1)*23.5
rect_lim <- cbind(c(rep(bbox(ao)["x", ], each=2), bbox(ao)["x", 1]),
                  c(y_lim, rev(y_lim), y_lim[1]))

rect <- SpatialPolygons(list(Polygons(list(Polygon(rect_lim)), ID="1")))
proj4string(rect) <- proj4string(ao)

# compute difference between the two geometries
res <- gDifference(ao, rect)

plot(ao, axes=TRUE)
plot(res, border="red", lwd=2, add=TRUE)
plot(rect, col="#00FF0010", add=TRUE)


# area between 23.5° south latitude and 23.5° north latitude
gArea(SpatialPolygons([email protected])) - gArea(SpatialPolygons([email protected]))
# [1] 2355.3448

It is important to note that this area is in square degrees. You have to use spTransfrom with an appropriate projection (see @WHuber's comment below). gArea returns also a warning (you didn't fixed it, you used a workaround):

R> gArea(ao)
[1] 7513
Warning message:
In RGEOSMiscFunc(spgeom, byid, "rgeos_area") :
  Spatial object is not projected; GEOS expects planar coordinates
April 04, 2014 22:37 PM

Related Questions

Estimating area under polygon in QGIS?

Updated October 09, 2018 08:22 AM