reading .hdf files
It's not just the projection -- you need to know the upper left coordinates (or the full bounding box) and the pixel resolution, and set those as well. When you said you downloaded this from NOAA -- what is the main site describing the dataset? What are you trying to do with this data? gdalUtils:::gdalinfo() will give you a "fuller" set of metadata of the input data than rgdal:::GDALinfo does, just as a note. --j
On Fri, Mar 28, 2014 at 1:51 PM, dododave <dododave at gmail.com> wrote:
Yes, I checked the projection info from the newly converted tiff file, and it is blank. I even tried to set the projection with the command below to match my poly file; projection(rast) <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0" but this isn't right. I tried to use the GDALinfo command to extract the metadata, but that doesn't work either. The ftp site I downloaded the .hdf files from is run by the NOAA, and I found some info; Table 2 Description of File attributes (Meta data) Meta data tag Content GRID_ROWS Number of rows for data grid GRID_COLUMNS Number of columns for data grid START_LATITUDE_RANGE The latitude of the grid's northern edge END_LATITUDE_RANGE The latitude of the grid's southern edge START_LONGITUDE_RANGE The longitude of the grid's western edge END_LONGITUDE_RANGE The longitude of the grid's eastern edge PROJECTION Projection type But how do I view the metadata? Jonathan Greenberg-3 wrote
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 .ac
> wrote:
On Fri, Mar 28, 2014 at 4:11 PM, dododave <
dododave@
> 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@
-- 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@
, Gchat: jgrn307, Skype: jgrn3007
_______________________________________________ R-sig-Geo mailing list
R-sig-Geo@
-- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038p7586077.html Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ 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