Skip to content
Prev 7335 / 29559 Next

subsetting shapefile polygons with separate table criteria

# Subseting shapefile before merging tables - join table

I realised that deleting the polygon with does match wit the record is
not possible since, I can read the shapefile at all. But still I need
to know how to delete / subset polygons.

I think this is more workable.

1. Read shapefile polygons from foreststand.shp
2. Match harvest.dbf table with polygon ID foreststand.shp
3. Subset shapefile polygon that matches
4. Write subset into a new shapefile

~~~~~~~~~~~
getwd()
setwd('C:\\Down2\\R_forestmgt\\modelIII\\')

library(rgdal)
library(maptools)

#forest <- readOGR(".",  "ForestStand")

forest <- readShapePoly("ForestStand")

harvest< read.csv('forest_cut.csv')

#Match

index <- match(harvest$CROP_ID, forest$CROP_ID , nomatch = 0)

# subset polygon.
# use this index here for setting

mypoly <- subset(forest,            Index)

#Save shapefile
writeOGR(mypoly, ".", "ForestStandNew", "ESRI Shapefile")

~~~~~~~~~~~~

Any ideas how to do this?

Thanks in advance.

Noli