[R-sig-Geo] Incorrect area coming from raster

Robert J. Hijmans r.hijmans at gmail.com
Fri Jun 10 03:15:36 CEST 2016


Alex,

You should provide a full reproducible example. You can get the
boundaries via raster::getData, and you can create a raster in memory.
Your script should also indicate the packages you use.
To get the area of the polygons, I would do

library(raster)
nga <- getData('GADM', country='NGA', level=1)
area(nga)

Robert

On Thu, Jun 9, 2016 at 1:16 PM, Alex Fitz <afitz at email.wm.edu> wrote:
> Hi All,
>
> Currently I am using a raster of the gridded world population (GWPv4) to calculate density in Nigeria.  I also have the Nigeria shapefiles from GADM.  I am having an issue with the area’s that are being calculated because they are slightly off for each state/lga in Nigeria.  The approach I am taking is the following code:
>
> pop_world_2005 is my raster the the population of the entire world
> states is my shapefile containing the state boundaries
>
> state_crop_05 <- crop(pop_world_2005, states, df = FALSE)
> area_05 <- raster::area(state_crop_05)
> state_area_05 <- extract(area_05, states, df = TRUE)
>
>
> I think aggregated the data from my extract to check the area’s again known area’s and they seemed to be slightly incorrect with some much more incorrect than others. Here’s the code I used to join the names with the area based on their state ID.
>
> state_area_totals_15 <- aggregate(. ~ ID, state_area_15, sum)
> state_df <- as.data.frame(states)
> state_names_area <- left_join(x = state_df, y = state_area_totals_15, by = c("ID" = "ID"))
>
>
>
> I’m wondering if the shapefiles I downloaded from GADM could be the issue (Different version than those used in GWPv4.  When I some the total population of the country it appears to be correct/very close to correct so it seems to be incorrectly assigning the values to certain states.  Any help would be appreciated in figuring out where the issue is coming from.
>
> Thanks so much,
> Alex Fitz
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list