[R-sig-Geo] Calculate areas of multiple polygones within multiple polygones

Dexter Locke dexter@|ocke @end|ng |rom gm@||@com
Mon Dec 20 12:58:53 CET 2021


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 using 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 using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list