1

I have two rasters images and a base shapefile. I am using the extract function to extract pixel values that are positioned in the 809 polygons of my shapefiled. Both of the rasters are outside of my area of interest so they will return null values. They have the same CRS. However, one of them doesn't return me null values and gives me instead this error:

Error in names(x) <- value : 'names' attribute [4] must be the same length as the vector [0]

Code that results in null values:

shp=shapefile("E:/SUO-PUO/Ostalo/Sentinel/Potencijalna_rjesenja/R/Azo_plohe_33N_buffer30m")

image1=raster("G:/GIS/R20/S2A_USER_MSI_L2A_TL_SGS__20160317T153554_A003837_T32TQR_B05_20m.tif")

pixel_values1=(na.omit(extract(snimka1,azo_plohe, cellnumbers=TRUE, weights=TRUE)))

pixel_values1

:0 rows

Code that results in error:

  shp=shapefile("E:/SUO-PUO/Ostalo/Sentinel/Potencijalna_rjesenja/R/Azo_plohe_33N_buffer30m")

image2=raster("G:/GIS/R20/S2A_USER_MSI_L2A_TL_SGS__20160317T153554_A003837_T33TVJ_B04_20m.tif.tif")

pixel_values2=(na.omit(extract(snimka1,azo_plohe, cellnumbers=TRUE, weights=TRUE)))

pixel_values2


Error in names(x) <- value : 'names' attribute [4] must be the same length as the vector [0]
5.
`colnames<-`(`*tmp*`, value = nms)
4.
.local(x, y, ...)
3.
extract(snimka1, azo_plohe, cellnumbers = TRUE, weights = TRUE, df = TRUE)
2.
extract(snimka1, azo_plohe, cellnumbers = TRUE, weights = TRUE, df = TRUE)
1.
na.omit(extract(snimka1, azo_plohe, cellnumbers = TRUE, weights = TRUE, df = TRUE))

I do not see why the image gets the error. I do know that if I remove the

df=TRUE

I will not get the error and will get a list of 809 null values for each raster. But the thing is I really need to use (atleast I think I do) the df=TRUE which is crucial for the rest of my code (so if you could please take that as granted?).

  • I doubt we can help without your data. – Spacedman Nov 8 '17 at 14:24
  • I can input the str(image) in the edit, or send the images to mail if anyone is interested (each image around 50 mbs)? Or if you have another suggestion? – davor korman Nov 8 '17 at 14:39
  • minimally you should add the output from "summary" on your raster and shapefile objects to the question, and a plot of the raster with the shapefile on top. Also, the error is coming from na.omit so unwrap that and see what is coming out of extract. – Spacedman Nov 8 '17 at 16:04

Your Answer

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

Browse other questions tagged or ask your own question.