0

I have a large rasterstack of about 500 objects. I want to sample easch object with the use of a SpatialPointDataframe and then export the results as file.csv. I have tried the following but within the SpatialPointDataframe I get a large matrix of the extracted values and I can not export it. It might be something basic, but I can not see it.

Any ideas how to solve this?

points$twsx<-extract(largerasterstack,points)
writeOGR(obj=points, dsn=".", layer="extracted", driver="ESRI Shapefile") 

Error in writeOGR(obj = points, dsn = ".", layer = "extracted", driver = "ESRI Shapefile") : 
  Can't convert columns of class: matrix; column names: twsx
1

You need to use cbind to add the returned matrix from a stack-point overlay as multiple columns to your point data frame:

> extract(s,spd)
      layer.1 layer.2 layer.3
 [1,]     626     626     626
 [2,]     554     554     554
...
> spd = cbind(spd, extract(s,spd))
> writeOGR(spd,"/tmp","foo","ESRI Shapefile")
> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.