From b2237a8b55ea4cdfdf77882326dc804cce60524a Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Mon, 9 Apr 2012 22:44:02 +0000 Subject: [PATCH] Added handling of subdatasets coming from NetCDF, HDF4 and HDF5. Associated ticket is #1761. git-svn-id: http://svn.osgeo.org/postgis/trunk@9620 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/loader/raster2pgsql.c | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/raster/loader/raster2pgsql.c b/raster/loader/raster2pgsql.c index f7d52caf6..89ffa61c2 100644 --- a/raster/loader/raster2pgsql.c +++ b/raster/loader/raster2pgsql.c @@ -323,6 +323,37 @@ chartrim(const char *input, char *remove) { return rtn; } +static int +isSubDataset(const char *fn) { + char *ptr; + + if (fn == NULL) + return 0; + + /* find colon */ + ptr = strchr(fn, ':'); + if (ptr == NULL) + return 0; + + /* substring search */ + /* NetCDF */ + ptr = strstr(fn, "NETCDF:"); + if (ptr - fn == 0) + return 2; + + /* HDF4 */ + ptr = strstr(fn, "HDF4"); + if (ptr - fn == 0) + return 3; + + /* HDF5 */ + ptr = strstr(fn, "HDF5:"); + if (ptr - fn == 0) + return 4; + + return 1; +} + static void usage() { printf(_("RELEASE: %s GDAL_VERSION=%d (r%d)\n"), POSTGIS_LIB_VERSION, POSTGIS_GDAL_VERSION, POSTGIS_SVN_REVISION); @@ -2410,8 +2441,11 @@ main(int argc, char **argv) { rtdealloc_config(config); exit(1); } - /* at least two files, see if last is table */ - else if (config->rt_file_count > 1) { + /* + at least two files, see if last is table + subdataset check (NetCDF, HDF4, HDF5, etc) + */ + else if (config->rt_file_count > 1 && !isSubDataset(config->rt_file[config->rt_file_count - 1])) { fp = fopen(config->rt_file[config->rt_file_count - 1], "rb"); /* unable to access file, assume table */ @@ -2470,6 +2504,10 @@ main(int argc, char **argv) { /* check that all files are touchable */ for (i = 0; i < config->rt_file_count; i++) { + /* subdatasets are not tested, let GDAL deal with it */ + if (isSubDataset(config->rt_file[i])) + continue; + fp = fopen(config->rt_file[i], "rb"); if (fp == NULL) { -- 2.40.0