]> granicus.if.org Git - postgis/commitdiff
Slightly simplify a loop setting projection parameters for gdal warp
authorSandro Santilli <strk@keybit.net>
Fri, 29 Aug 2014 16:37:02 +0000 (16:37 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 29 Aug 2014 16:37:02 +0000 (16:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12929 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_warp.c

index 10964c4ffa6fbbd8f93b724150ea33a10fd51f7a..50fb03350227fc2b25be268059a29ea40b407feb 100644 (file)
@@ -325,52 +325,17 @@ rt_raster rt_raster_gdal_warp(
                memset(arg->transform.option.item, 0, sizeof(char *) * (arg->transform.option.len + 1));
 
                for (i = 0; i < arg->transform.option.len; i++) {
-                       switch (i) {
-                               case 1:
-                                       if (arg->dst.srs != NULL)
-                                               arg->transform.option.item[i] = (char *) rtalloc(sizeof(char) * (strlen("DST_SRS=") + strlen(arg->dst.srs) + 1));
-                                       else
-                                               arg->transform.option.item[i] = (char *) rtalloc(sizeof(char) * (strlen("DST_SRS=") + 1));
-                                       break;
-                               case 0:
-                                       if (arg->src.srs != NULL)
-                                               arg->transform.option.item[i] = (char *) rtalloc(sizeof(char) * (strlen("SRC_SRS=") + strlen(arg->src.srs) + 1));
-                                       else
-                                               arg->transform.option.item[i] = (char *) rtalloc(sizeof(char) * (strlen("SRC_SRS=") + 1));
-                                       break;
-                       }
+                       const char *srs = i ? arg->dst.srs : arg->src.srs;
+                       const char *lbl = i ? "DST_SRS=" : "SRC_SRS=";
+                       size_t sz = sizeof(char) * (strlen(lbl) + 1);
+                       if ( srs ) sz += strlen(srs);
+                       arg->transform.option.item[i] = (char *) rtalloc(sz);
                        if (NULL == arg->transform.option.item[i]) {
                                rterror("rt_raster_gdal_warp: Could not allocation memory for transform options");
                                _rti_warp_arg_destroy(arg);
                                return NULL;
                        }
-
-                       switch (i) {
-                               case 1:
-                                       if (arg->dst.srs != NULL) {
-                                               snprintf(
-                                                       arg->transform.option.item[i],
-                                                       sizeof(char) * (strlen("DST_SRS=") + strlen(arg->dst.srs) + 1),
-                                                       "DST_SRS=%s",
-                                                       arg->dst.srs
-                                               );
-                                       }
-                                       else
-                                               sprintf(arg->transform.option.item[i], "%s", "DST_SRS=");
-                                       break;
-                               case 0:
-                                       if (arg->src.srs != NULL) {
-                                               snprintf(
-                                                       arg->transform.option.item[i],
-                                                       sizeof(char) * (strlen("SRC_SRS=") + strlen(arg->src.srs) + 1),
-                                                       "SRC_SRS=%s",
-                                                       arg->src.srs
-                                               );
-                                       }
-                                       else
-                                               sprintf(arg->transform.option.item[i], "%s", "SRC_SRS=");
-                                       break;
-                       }
+                       sprintf(arg->transform.option.item[i], "%s%s", lbl, srs ? srs : "");
                        RASTER_DEBUGF(4, "arg->transform.option.item[%d] = %s", i, arg->transform.option.item[i]);
                }
        }