[R-sig-Geo] Help on extract function

Sean O'Riordain seanpor at acm.org
Sat Feb 12 14:05:36 CET 2011


Hi Rahul,

First look at
  str(polygon, max.level=2)
to understand how a shapefile is represented in R, then have a look at
  str(polygon at data)
which is a dataframe - you can add a new column to this dataframe like...
  polygon at data$newcolumn <- 1:nrow(polygon at data)
i.e you can treat this dataframe like any other as long as you're in
read-only mode or just adding columns... if you add rows or delete
rows or modify ID fields then beware!!! these rows are linked to the
actual polygons held elsewhere as arrays... don't touch for the moment
I'd suggest! :-)

then you can save out the shape file again...

cheers
Sean
Dublin
Ireland


On 12 February 2011 05:16, Rahul Raj <rahulosho at gmail.com> wrote:
> Dear all,
>
> I am using the command "extract(raster, polygon)".
>> I want to run this command in loop to extract the raster cells values by
> polygon number in each iteration.
>> I also want to attach one attribute column to shape file and write the
> shape file with added attribute.
> Please help me how can I do this in R
>
> Quick reply is highly appreciated and Thanks in advance
>
> Rahul Raj
> Indian Institute of Remote Sensing, India.
>
>        [[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
>



More information about the R-sig-Geo mailing list