# [R-sig-Geo] Calculate each polygon percentage inside a circles

Juan Tomas Sayago Gomez juantomas.sayago at gmail.com
Wed May 25 04:13:28 CEST 2016

```you should check the intersect function. I used it like in this function in
http://gis.stackexchange.com/questions/140504/extracting-intersection-areas-in-r

Juan

On Tue, May 24, 2016 at 9:17 PM ASANTOS via R-sig-Geo <
r-sig-geo at r-project.org> wrote:

> Dear members,
>
>         I will try to calculate each polygon percentage inside a circles
> given an arbitrary radius in a shapefile object with the code below and
> my output needs to be (Two first columns with center os circle
> coordinates and values of each polygon percentage):
>
> "pts\$x"   "pts\$y" "ID1" "ID2" "ID3" "ID4"
> 180486.1  330358.8  16.3   0.2  NA   17.3
> 179884.4  331420.8  88.3   NA   96.3 NA
> 179799.6  333062.5  25.3   22.3 0.5  NA
> ...
>
>       For this I try to do:
>
> #Packages
> require(shapefiles)
> require(rgdal)
> require(maptools)
> require(spatstat)
> require(berryFunctions)
>
>
> #Create 4 polygons (I create polygons because is more simple that given
> a shapefile in a post)
>
> sr1=Polygons(list(Polygon(cbind(c(180114, 180553, 181127, 181477,
> 181294, 181007, 180409,
>    180162, 180114), c(332349, 332057, 332342, 333250, 333558, 333676,
>    332618, 332413, 332349)))),'1')
> sr2=Polygons(list(Polygon(cbind(c(180042, 180545, 180553, 180314,
> 179955, 179142, 179437,
>    179524, 179979, 180042), c(332373, 332026, 331426, 330889, 330683,
>    331133, 331623, 332152, 332357, 332373)))),'2')
> sr3=Polygons(list(Polygon(cbind(c(179110, 179907, 180433, 180712,
> 180752, 180329, 179875,
>    179668, 179572, 179269, 178879, 178600, 178544, 179046, 179110),
>    c(331086, 330620, 330494, 330265, 330075, 330233, 330336, 330004,
>    329783, 329665, 329720, 329933, 330478, 331062, 331086)))),'3')
> sr4=Polygons(list(Polygon(cbind(c(180304, 180403,179632,179420,180304),
>    c(332791, 333204, 333635, 333058, 332791)))),'4')
>
> #Spatial Polygons
> sr=SpatialPolygons(list(sr1,sr2,sr3,sr4))
> srdf=SpatialPolygonsDataFrame(sr,
> data.frame(row.names=c('1','2','3','4'), PIDS=1:4))
>
> #Create shapefile
> writeOGR(srdf, getwd(), 'POLY', 'ESRI Shapefile')
>
> plot(contorno_line_X)
>
> #Create ~28 random points in my window
> contorno_line_spat <- as(contorno_line_X,"owin")
> pts <- rpoispp(lambda=0.000005, win=contorno_line_spat)
> points(pts, col="blue")
>
> #Set the radius for the plots
>
> #Draw the circles using berryFunctions package
> col=rgb(1,0.5,0,alpha=0.4), border=NA)
> #
>
> Now I'd like to calculate de polygon percentage around each point in a
> 600 meters radius. This is possible? There are any function for this?
>
> Thanks,
>
> Alexandre
>
> --
> ======================================================================
> Alexandre dos Santos
> Proteção Florestal
> IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso
> Campus Cáceres
> Caixa Postal 244
> Avenida dos Ramires, s/n
> Bairro: Distrito Industrial
> Cáceres - MT                      CEP: 78.200-000
> Fone: (+55) 65 8132-8112 (TIM)   (+55) 65 9686-6970 (VIVO)
>
>          alexandre.santos at cas.ifmt.edu.br
> Lattes: http://lattes.cnpq.br/1360403201088680
> OrcID: orcid.org/0000-0001-8232-6722
> Researchgate: https://www.researchgate.net/profile/Alexandre_Santos10
> ======================================================================
>
>
>         [[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

[[alternative HTML version deleted]]

```