[mapserver-commits] r7301 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Wed Jan 23 14:38:32 EST 2008


Author: tomkralidis
Date: 2008-01-23 14:38:32 -0500 (Wed, 23 Jan 2008)
New Revision: 7301

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/shp2img.c
   trunk/mapserver/shp2pdf.c
Log:
clean up usage text, check for invalid layers (#2066)



Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2008-01-23 17:46:49 UTC (rev 7300)
+++ trunk/mapserver/HISTORY.TXT	2008-01-23 19:38:32 UTC (rev 7301)
@@ -12,6 +12,9 @@
 
 Current Version (5.1-dev, SVN trunk):
 -------------------------------------
+
+- shp2img.c/shp2pdf.c: clean up usage text, check for invalid layers (#2066)
+
 - completed implementation of RFC24 (#2442, #2032)
 
 - mapwcs.c: require VERSION parameter for DescribeCoverage and GetCoverage (#2473)

Modified: trunk/mapserver/shp2img.c
===================================================================
--- trunk/mapserver/shp2img.c	2008-01-23 17:46:49 UTC (rev 7300)
+++ trunk/mapserver/shp2img.c	2008-01-23 19:38:32 UTC (rev 7301)
@@ -40,6 +40,9 @@
   char **layers=NULL;
   int num_layers=0;
 
+  int layer_found=0;
+  char *invalid_layer=NULL;
+
   char *outfile=NULL; /* no -o sends image to STDOUT */
 
   int iterations = 1;
@@ -62,6 +65,7 @@
 
   /* ---- check the number of arguments, return syntax if not correct ---- */
   if( argc < 3 ) {
+    fprintf(stdout, "\nPurpose: convert a mapfile to an image\n\n");
     fprintf(stdout,
             "Syntax: shp2img -m mapfile [-o image] [-e minx miny maxx maxy] [-s sizex sizey]\n"
             "               [-l \"layer1 [layers2...]\"] [-i format]\n"
@@ -229,6 +233,7 @@
 
     if(strcmp(argv[i],"-l") == 0) { /* load layer list */
       layers = msStringSplit(argv[i+1], ' ', &(num_layers));
+      layer_found=0;
 
       for(j=0; j<map->numlayers; j++) {
 	if(GET_LAYER(map, j)->status == MS_DEFAULT)
@@ -238,11 +243,21 @@
 	  for(k=0; k<num_layers; k++) {
 	    if(GET_LAYER(map, j)->name && strcmp(GET_LAYER(map, j)->name, layers[k]) == 0) {
 	      GET_LAYER(map, j)->status = MS_ON;
+              layer_found=1;
 	      break;
 	    }
+            else {
+              invalid_layer = strdup(layers[k]);
+            }
 	  }
 	}
       }
+      if (layer_found == 0) {
+        fprintf(stderr, "Layer (-l) %s not found\n", invalid_layer);
+        msCleanup();
+        exit(0);
+      }
+
       msFreeCharArray(layers, num_layers);
 
       i+=1;

Modified: trunk/mapserver/shp2pdf.c
===================================================================
--- trunk/mapserver/shp2pdf.c	2008-01-23 17:46:49 UTC (rev 7300)
+++ trunk/mapserver/shp2pdf.c	2008-01-23 19:38:32 UTC (rev 7301)
@@ -72,6 +72,9 @@
   char **layers=NULL;
   int num_layers=0;
 
+  int layer_found=0;
+  char *invalid_layer=NULL;
+
   char *outfile=NULL; /* no -o sends image to STDOUT */
 
   /* A4 Portrait */
@@ -86,7 +89,13 @@
 
   /* ---- check the number of arguments, return syntax if not correct ---- */
   if( argc < 3 ) {
-    fprintf(stdout,"Syntax: shp2pdf -m [mapfile] -o [pdf] -l [layers]\n" );
+    fprintf(stdout, "\nPurpose: convert a mapfile to a PDF document\n\n");
+    fprintf(stdout,"Syntax: shp2pdf -m [mapfile] -o [pdf] [-e minx miny maxx maxy] -l [layers] -t\n" );
+    fprintf(stdout,"  -m mapfile: Map file to operate on - required.\n" );
+    fprintf(stdout,"  -o pdf: output filename (stdout if not provided)\n");
+    fprintf(stdout,"  -e minx miny maxx maxy: extents to render\n");
+    fprintf(stdout,"  -l layers: layers to enable - make sure they are quoted and space seperated if more than one listed.\n" );
+    fprintf(stdout,"  -t : turn on transparency\n");
     exit(0);
   }
 
@@ -143,20 +152,31 @@
 
     if(strncmp(argv[i],"-l",2) == 0) { /* load layer list */
       layers = msStringSplit(argv[i+1], ' ', &(num_layers));
+      layer_found=0;
 
       for(j=0; j<map->numlayers; j++) {
-    if(GET_LAYER(map, j)->status == MS_DEFAULT)
-      continue;
-    else {
-      GET_LAYER(map, j)->status = MS_OFF;
-      for(k=0; k<num_layers; k++) {
-        if(strcmp(GET_LAYER(map, j)->name, layers[k]) == 0) {
-          GET_LAYER(map, j)->status = MS_ON;
-          break;
+        if(GET_LAYER(map, j)->status == MS_DEFAULT)
+          continue;
+        else {
+          GET_LAYER(map, j)->status = MS_OFF;
+          for(k=0; k<num_layers; k++) {
+            if(strcmp(GET_LAYER(map, j)->name, layers[k]) == 0) {
+              GET_LAYER(map, j)->status = MS_ON;
+              layer_found=1;
+              break;
+            }
+            else {
+              invalid_layer = strdup(layers[k]);
+            }
+          }
         }
       }
-    }
+      if (layer_found == 0) {
+        fprintf(stderr, "Layer (-l) %s not found\n", invalid_layer);
+        msCleanup();
+        exit(0);
       }
+
       msFreeCharArray(layers, num_layers);
 
       i+=1;



More information about the mapserver-commits mailing list