]> granicus.if.org Git - postgis/commitdiff
Added handling of subdatasets coming from NetCDF, HDF4 and HDF5.
authorBborie Park <bkpark at ucdavis.edu>
Mon, 9 Apr 2012 22:44:02 +0000 (22:44 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 9 Apr 2012 22:44:02 +0000 (22:44 +0000)
Associated ticket is #1761.

git-svn-id: http://svn.osgeo.org/postgis/trunk@9620 b70326c6-7e19-0410-871a-916f4a2858ee

raster/loader/raster2pgsql.c

index f7d52caf6cdc677d3988b001ff59a72123490a5f..89ffa61c242e7389e34dce9d1e9e8261948100a4 100644 (file)
@@ -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) {