[R-sig-Geo] Deleting shapefile polygon with no attribute / record

Noli Sicad nsicad at gmail.com
Thu Jan 7 05:31:15 CET 2010


# Deleting shapefile polygons that doesn't much with record in the
merge dbf file

I want to do:
1. Delete polygons that doesn't have a match with record in joined /
merge table of the shapefile.
    (Done transpose and merging - joined to one-to-one relationship already.)
2. Create a subset of the polygon and save shapefile or just save the
revise shapefile
3. Open in shapefile in QGIS and do spplot.

~~~~~~~~~~~~~~
from 1 to 93 polygon
   if table ID == polygon_ID then print("Polygon OK")
       else delete the polygon

How do I delete the polygon and save?

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

library(rgdal)

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

forest.dat <- slot(forest, "data") <------ is this necessary?
xlength<-nrow(forest.dat)

for (i in 1:xlength)
       if (forest.dat$ID[x] == forest[ID[x] {print("Polygon OK")
	} else { Delele Polygon}	

writeOGR(forest, ".", "ForestStandNew", "ESRI Shapefile")
~~~~~~~~~~~~~~~~~

The script above doesn't run because I don't know how to delete
polygons. Any ideas how to do this?


Thanks in advance.

Noli



More information about the R-sig-Geo mailing list