Hello every one! I am trying to compute the area of buildings inside neighbourhoods. I have a shapefile with the buildings and one with the neighbourhoods. I want to know the built-up area per neighbourhood but I do not understand how to procede. I already compute the areas of each neighbourhood and I reach to attribute at each neighbourhood the buildings which are within. I created a field "batcount" in the neighbourhoods shapefile. However I do not have the geometries of the buildings in this shapefile and I do not know how to procede in order to find the area of the buildings in each neighbourhood. Here is the code I used to join the two shapefiles in order to count the number of buildings in each neighbourhood. bat_count_iris <- st_join(bat, neighbourhoods) %>% st_set_geometry(NULL) %>% group_by(CODE_NEIGHBOURHOOD) %>% tally() %>% select(CODE_NEIGHBOURHOOD, batcount = n) bat_in_iris <- left_join(CODE_NEIGHBOURHOOD, bat_count_iris, by = 'CODE_NEIGHBOURHOOD') %>% mutate(batcount = ifelse(is.na(batcount), 0, batcount)) Do you have any clue of how I can compute the areas of the buildings in each neighbourhood? Have a great day, Basile. Sent with [ProtonMail](https://protonmail.com) Secure Email.
Calculate areas of multiple polygones within multiple polygones
2 messages · basile.lenormand, Dexter Locke
Hi Basile,
I'm not sure I fully understand the question. How does a shapefile of the
buildings not have geometry?
Do you want the area of building per neighborhood, their counts, or both?
bat_neigh_int <- bat %>%
mutate(bat_area = st_area(.)) %>% # adds area to input file, may want to
change units.
st_join(. # add neighborhood identifier
"CODE_NEIGHBOURHOOD" via spatial join
, neighborhoods
, join = st_intersects # check the help, you may want st_within
or to try both ways
, left = TRUE)
buil_area_per_neigh <- bat_neigh_int %>%
st_drop_geometry() %>%
group_by(CODE_NEIGHBOURHOOD) %>%
summarise(neigh_build_area = sum(bat_area) # gets the area of buildings
in each neighborhood
, build_count = sum(n())) # counts the
buildings in each neighborhood
Then join buil_area_per_neigh back to neighborhoods with left_join
Does this help? Again I am a little confused about the intended outcome.
Best, Dexter
On Mon, Dec 20, 2021 at 6:45 AM basile.lenormand via R-sig-Geo <
r-sig-geo at r-project.org> wrote:
Hello every one! I am trying to compute the area of buildings inside neighbourhoods. I have a shapefile with the buildings and one with the neighbourhoods. I want to know the built-up area per neighbourhood but I do not understand how to procede. I already compute the areas of each neighbourhood and I reach to attribute at each neighbourhood the buildings which are within. I created a field "batcount" in the neighbourhoods shapefile. However I do not have the geometries of the buildings in this shapefile and I do not know how to procede in order to find the area of the buildings in each neighbourhood. Here is the code I used to join the two shapefiles in order to count the number of buildings in each neighbourhood. bat_count_iris <- st_join(bat, neighbourhoods) %>% st_set_geometry(NULL) %>% group_by(CODE_NEIGHBOURHOOD) %>% tally() %>% select(CODE_NEIGHBOURHOOD, batcount = n) bat_in_iris <- left_join(CODE_NEIGHBOURHOOD, bat_count_iris, by = 'CODE_NEIGHBOURHOOD') %>% mutate(batcount = ifelse(is.na(batcount), 0, batcount)) Do you have any clue of how I can compute the areas of the buildings in each neighbourhood? Have a great day, Basile. Sent with [ProtonMail](https://protonmail.com) Secure Email. [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo