How to divide polygon in R? -


i have shapefile of amazonas state (brazil) , other 6 biggest rivers in state (negro, solimões, amazonas, madeira, purus , juruá). want divide state using rivers, interfluvial areas (madeira-purus, purus-juruá, etc). want final 6 regions delimited rivers, each region different polygon. how do that?

enter image description here

i'm finding "clipping" algorithms, , give me area of rivers inside state, , that's not want.

following @jbaums comment, used gdifference, package rgeos:

intflv <- gdifference(state,rivers) 

but since "state" has 1 polygon, intflv became spatialpolygons object 1 polygon, made of thousands of sub-polygons. work better in gis software, wanted object thousands of polygons, each single sub-polygon. did:

l <- list() total <- length(intflv@polygons[[1]]@polygons) (i in 1:total) {     print(paste(i,total,sep="/"))     flush.console()     p <- intflv@polygons[[1]]@polygons[[i]]     l[[length(l)+1]] <- polygons(list(p),i) } sp <- spatialpolygons(l) d <- data.frame(ids=1:total) intflv1 <- spatialpolygonsdataframe(sp,data=d) writeogr(intflv1,"shp","intflv","esri shapefile") 

the result (after keeping biggest areas):

enter image description here


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -