[R-sig-Geo] subdatasets in rgdal/raster

Michael Sumner mdsumner at gmail.com
Wed Oct 15 13:23:49 CEST 2014


Thanks Roger, I'm still hoping to be able to code at this level one day.

I have gone off half-cocked, confusing things. I can get SDS from
NetCDF and HDF files with GDALinfo() with no problems - I just had to
turn off returnScaleOffset, which I think has a confounding of nbands
and subdatasets - since a datasource with SDS has no bands, but I need
to explore this more to be sure.

Cheers, Mike.





On Wed, Oct 15, 2014 at 5:50 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Wed, 15 Oct 2014, Michael Sumner wrote:
>
>> Hello,
>>
>> As far as I know there's nothing in rgdal to determine existing
>> subdatasets (SDS) in HDF (or NetCDF for that matter).
>>
>> In raster, raster(x) will read from the first candidate *variable*,
>> and list the others with a warning, which is analogous to an SDS but
>> of course it's always providing this via ncdf/ncdf4 rather than via
>> rgdal.
>>
>> Is it true there's no way to find out SDS from HDF or NetCDF in rgdal?
>
>
> Because these formats are poorly organised (an XML tree describing the
> internal structure would be easy to parse, but self-descriptive metadata
> isn't usual here), GDALinfo() does not provide much.
>
> If you start by identifying the incantation used by command line gdalinfo to
> report the SDS metadata, then look at its source code, it should be possible
> to make some progress. I don't use either if I can help it, and do not have
> the necessary trial set of sample files. You'd need to find a robust route
> covering a wide range of files seen in the wild to allow for oddities in the
> ways things are organised. It is unfortunate to have to branch code on the
> selected driver, but here it is hard to avoid. Once GDALinfo is reporting
> the metadata in a predictable way, the other functions can be given
> appropriate argument values.
>
> Also consider looking at this from the point of view of rgdal2 in addition
> to rgdal; it could possibly be "closer" there and looking at both may make
> it easier to spot:
>
> https://github.com/thk686/rgdal2
>
> Contributions welcome!
>
> Roger
>
>
>>
>> I've not really explored this before much since compiling HDF was
>> unavailable to me. gdalUtils fills a gap but only by running the
>> installed command line tools, which obviously can be avoided with the
>> right features in rgdal/raster. I personally have always run the
>> command line tools and then jumped back to R (if I could).
>>
>> (The vector analogy in rgdal to listing SDS would be ogrListLayers).
>>
>> This is a missing capability in the raster package, somewhat disguised
>> because of the independent support for NetCDF. I guess hardly anyone
>> is using HDF? That's a shame since these R tools really help.  It's a
>> pretty complicated story all round and I keep re/discovering
>> interesting corners. If anyone is writing anything significant about
>> all this I'd be keen to be involved.
>>
>> Cheers, Mike.
>>
>>
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: Roger.Bivand at nhh.no
>



-- 
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list