3

I used extract() function to get remote sensing image cell value.The same code to process tif file produce error message. Code as follows:

r1 <- raster("2000_2605_1.1_km_monthly_NDVI.tif")
polygon_mus <- extent(c(107, 111, 37, 40))
cell <- extract(r1, polygon_mus)

This *.tif is a output file from MODI hdf file with MRT. The process result is as follow:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function extent?for signature ?NULL"?

Where is the error? I seem to be missing it.

  • Did you check if polygon_mus and r1 overlay? (e.g. by plotting both together) – Iris May 23 '16 at 15:29
  • Unfortunatly, I can only guess without a reproducable example (stackoverflow.com/questions/5963269/…). – Iris May 23 '16 at 15:29
  • Ha~It's amazing~Thanks for your help Iris – Iris May 24 '16 at 1:32
  • The problem is overlay error, but now I have some problems to make them have same extent.I am a student ,so I have too much to learn. – Iris May 24 '16 at 1:47
1

Your raster and your polygon do not overlap. If they do:

> r1 = raster(extent(c(107,110,38,40)))
> polygon_mus <- extent(c(107, 111, 37, 40))
> cell <- extract(r1, polygon_mus)

Then that works. If they don't:

> r1 = raster(extent(c(112,114,38,40)))
> cell <- extract(r1, polygon_mus)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘extent’ for signature ‘"NULL"’

I get your error message. Check the extent(r1) to see where it is. I'll bet it doesn't overlap the extent you defined in polygon_mus.

| improve this answer | |
  • The r1 is a rasterlayer with coordinate,but the polygon_mus is a custom extent class without any coordinate.I try to reproject polygon_mus to the same project with r1,but got error message : Error in rgdal::rawTransform(projfrom, projto, nrow(xy), xy[, 1], xy[, : no arguments in initialization list – Iris May 24 '16 at 1:43
  • Thank you very much! I found the polygon_mus's extent as follow: > polygon_mus class : Extent xmin : 107 xmax : 111 ymin : 37 ymax : 40 **but, the extent of r1 is **> extent(r1) class : Extent xmin : 8895604 xmax : 10007555 ymin : 3335852 ymax : 4447802 – Iris May 24 '16 at 1:44

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.