[R-sig-Geo] Changing the units of shape file areas
laanders
laanders at nps.edu
Sat Mar 29 21:09:34 CET 2014
Hello!
I've been working with Philippine shape files I found at:
http://www.philgis.org/freegisdata.htm
Specifically, I've been looking at the barangay level shape files. I'm
trying to get the area of each barangay so I can bet the population density
and plot a heat map. Unfortunately, I don't understand the units of these
areas.
Here's the R code I'm using to get the areas:
###########################
BarangaysPlot <- readOGR("~/Barangays", layer = "Barangays”)
ZCB <- BarangaysPlot[BarangaysPlot$NAME_2=="Zamboanga City”,] ## Subsetting
the shape file to get ZamboCity
sapply(slot(ZCB, "polygons"), slot, "area”) ## Get the areas
[1] 1.392389e-04 1.946191e-04 7.702360e-05 2.711882e-03 4.610627e-05
5.659337e-05
[7] 6.926905e-05 5.678706e-05 8.203009e-04 1.639304e-03 1.336925e-03
4.909287e-03
###########################
Since the areas are so small, I thought maybe there were either holes in the
shape files or I am dealing with the degree coordinate system. The
coordinates are planar, so we're good there. So to see if there were holes
I used the code provided by Dr. Bivand in an earlier post, I found there
were no holes. According to the website, the current projection for these
shape files is WGS 1984. So I then looked at spTransform() using the code I
mentioned earlier by Dr. Bivand.
###########################
## epsg for WGS 1984 is 4326
ZCBareas <- spTransform(ZCB, CRS("+init=epsg:4326"))
## Gives some “non-simple polygon objects"
sapply(slot(ZCBareas, "polygons"), function(x) length(slot(x, "Polygons")))
## Gives any holes in the polygons; there are none
sapply(slot(ZCBareas, "polygons"), function(x) {
xi <- slot(x, "Polygons")
any(sapply(xi, slot, "hole"))
})
## Gives the same areas as before
sapply(slot(ZCBareas, "polygons"), slot, "area”)
###########################
Again, I'm just trying to find the areas in a unit I can understand to apply
to population densities.
Any help would be much appreciated!!
Lew
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Changing-the-units-of-shape-file-areas-tp7586083.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list