Skip to content
Back to formatted view

Raw Message

Message-ID: <f7bd71731001062243p144707b8m23a5c4cd9314b3d5@mail.gmail.com>
Date: 2010-01-07T06:43:49Z
From: Noli Sicad
Subject: 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