reading .hdf files
I want to follow up with this -- I confirmed Barry's suspicion that
that file you sent above ("GVIX_NL_G16_C07_NVI_Y2005_P26.hdf") has no
projection information (or bounding box or pixel resolution), so there
is no way to do the extract unless that is fixed. Run a:
gdalinfo("GVIX_NL_G16_C07_NVI_Y2005_P26.hdf")
and you'll see there is not a properly set projection -- the .tif,
thus, also doesn't have any projection info. This is an issue with
the input file, not with any of our functions. You will need to set
your own projection, bounding box, and pixel sizes on the raster via
e.g. ?projection, ?res, ?extent
What are these files? Are they satellite data? Do you know if there
is another source for them that may have the information set
"properly"?
--j
On Fri, Mar 28, 2014 at 11:38 AM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
On Fri, Mar 28, 2014 at 4:11 PM, dododave <dododave at gmail.com> wrote:
I am now able to convert the hdf files into GeoTiffs. I have a follow-up question though. I now need to extract the mean ndvi value from within a polygon overlaid on that GeoTiff. The issue I am having is that the code is returning NULL when I do.
rast <- raster("2011_P01.tif")
mean.ndvi <- extract(rast, poly, fun=mean)
mean.ndvi
[[1]] NULL Here is the output when I call rast;
rast
class : RasterLayer dimensions : 904, 2500, 2260000 (nrow, ncol, ncell) resolution : 1, 1 (x, y) extent : 0, 2500, 0, 904 (xmin, xmax, ymin, ymax) coord. ref. : NA data source : /Volumes/GOLONDRINA/tiff/2011_P01.tif names : X2011_P01 values : -32768, 32767 (min, max) Help appreciated!
Are you sure your polygon is in the right place?
r=raster()
r[]=runif(180*360)
pts=data.frame(x=c(-50,50,50,-50,-50),y=c(-50,-50,50,50,-50))
poly = SpatialPolygons(list(Polygons(list(Polygon(pts)),ID=1)))
extract(r,poly,fun=mean)
[1] 0.4997085
- so that;s all good, but if I move the polygon way off the raster:
poly2 = SpatialPolygons(list(Polygons(list(Polygon(pts+200)),ID=1)))
extract(r,poly2,fun=mean)
[[1]]
NULL
I get what you're getting. Check your polygon coordinates and CRS string
is correct...
Barry
[[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
Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007