Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining the area of Shapefiles

Tags:

r

geospatial

How can one determine the area of a shapefile?

When I use summary(data), it gives the area, but then I have no idea what the area of each shapefile polygons are.

Also, can the area be converted to meters?

like image 365
user3511534 Avatar asked Apr 12 '14 23:04

user3511534


2 Answers

# load the rgeos library
library(rgeos)

# make a polygon (borrowed from ref manual for package)
sample_poly <- readWKT("POLYGON((0 1,0.95 0.31,0.59 -0.81,-0.59 -0.81,-0.95 0.31,0 1))")

# and calculate the area
gArea(sample_poly)
[1] 2.3803
like image 184
Gary Weissman Avatar answered Oct 24 '22 02:10

Gary Weissman


data@polygons[[1]]@Polygons[[1]]@area
data@polygons[[2]]@Polygons[[1]]@area

Will give you areas of the first and second polygons, you can figue a for loop to give you all or show us the names with:

names(data)
like image 31
FFI Avatar answered Oct 24 '22 03:10

FFI