[GRASS-SVN] r39528 - grass/trunk/vector/v.out.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 16 11:09:17 EDT 2009


Author: martinl
Date: 2009-10-16 11:09:16 -0400 (Fri, 16 Oct 2009)
New Revision: 39528

Modified:
   grass/trunk/vector/v.out.ogr/args.c
   grass/trunk/vector/v.out.ogr/main.c
Log:
v.out.ogr: default feature type 'auto'


Modified: grass/trunk/vector/v.out.ogr/args.c
===================================================================
--- grass/trunk/vector/v.out.ogr/args.c	2009-10-16 09:40:21 UTC (rev 39527)
+++ grass/trunk/vector/v.out.ogr/args.c	2009-10-16 15:09:16 UTC (rev 39528)
@@ -8,6 +8,9 @@
     options->input = G_define_standard_option(G_OPT_V_INPUT);
 
     options->type = G_define_standard_option(G_OPT_V3_TYPE);
+    options->type->options = "point,line,boundary,centroid,area,face,kernel,auto";
+    options->type->answer = "auto";
+    
     options->type->label = _("Feature type(s)");
     options->type->description =
 	_("Combination of types is not supported "

Modified: grass/trunk/vector/v.out.ogr/main.c
===================================================================
--- grass/trunk/vector/v.out.ogr/main.c	2009-10-16 09:40:21 UTC (rev 39527)
+++ grass/trunk/vector/v.out.ogr/main.c	2009-10-16 15:09:16 UTC (rev 39528)
@@ -110,6 +110,67 @@
 	i++;
     }
 
+    /*
+        If no output type specified: determine one automatically.
+        Centroids, Boundaries and Kernels always have to be exported
+        explicitely, using the "type=" option.
+    */
+    if (!flags.new->answer) {
+	/* open input vector (topology required) */
+	Vect_set_open_level(2);
+	Vect_open_old(&In, options.input->answer, "");
+	
+	if (strcmp(options.type->answer, "auto") == 0) {
+	    G_debug(2, "Automatic type determination.");
+	    
+	    options.type->answers = G_malloc(sizeof(char*) * 10);
+	    G_zero(options.type->answers, sizeof(char *) * 10);
+	    num_types = 0;
+	    
+	    if (Vect_get_num_primitives (&In, GV_POINT) > 0) {
+		options.type->answers[num_types++] = G_store("point");
+		G_debug(3, "Adding points to export list.");
+	    }
+	    
+	    if (Vect_get_num_primitives (&In, GV_LINE) > 0 ) {
+		options.type->answers[num_types++] = G_store("line");
+		G_debug(3, "Adding lines to export list.");
+	    }
+	    
+	    if (Vect_get_num_areas (&In) > 0) {
+		options.type->answers[num_types++] = G_store("area");
+		G_debug(3, "Adding areas to export list.");
+	    }
+	    
+	    /*  Faces and volumes:
+		For now, volumes will just be exported as sets of faces.
+	    */
+	    if (Vect_get_num_primitives (&In, GV_FACE) > 0) {
+		options.type->answers[num_types++] = G_store("face");
+		G_debug(3, "Adding faces to export list.");
+	    }
+	    
+	    /* this check HAS TO FOLLOW RIGHT AFTER check for GV_FACE! */
+	    if ( Vect_get_num_volumes (&In) > 0) {
+		G_warning(_("Volumes will be exported as sets of faces"));
+		if (num_types == 0) {
+		    /* no other types yet? */
+		    options.type->answers[num_types++] = G_store("volume");
+		    G_debug(3, "Adding volumes to export list.");
+		} else {
+		    if (strcmp(options.type->answers[num_types-1], "face") != 0) {
+			/* only put faces on export list if that's not the case already */
+			options.type->answers[num_types++] = G_store("volume");
+			G_debug(3, "Adding volumes to export list.");
+		    }
+		}
+	    }
+	    
+	    if (num_types == 0)
+		G_fatal_error(_("Unable to determine input map's vector feature type(s)."));
+	}
+    }
+    
     /* check output feature type */
     otype = Vect_option_to_types(options.type);
 
@@ -176,85 +237,13 @@
 	name = options.layer->answer ? options.layer->answer : options.input->answer;
 	
 	create_ogr_layer(options.dsn->answer, options.format->answer, name,
-			 wkbtype, papszDSCO, papszLCO);
+			 wkbtype, (const char **) papszDSCO, (const char **) papszLCO);
 	
 	G_message(_("OGR layer <%s> created in datasource <%s> (format '%s')"),
 		  name, options.dsn->answer, options.format->answer);
 	exit(EXIT_SUCCESS);
     }
 
-    /* open input vector (topology required) */
-    Vect_set_open_level(2);
-    Vect_open_old(&In, options.input->answer, "");
-
-    /*
-        If no output type specified: determine one automatically.
-        Centroids, Boundaries and Kernels always have to be exported
-        explicitely, using the "type=" option.
-    */
-    if (!strcmp(options.type->answer, "auto" )) {
-        G_debug(2, "Automatic type determination." );
-
-        options.type->answers = G_malloc (sizeof(char*) * 100); /* should be big enough forever ;) */
-        for (i=0;i<100;i++) {
-            options.type->answers[i] = NULL;
-        }
-        num_types = 0;
-
-        if ( Vect_get_num_primitives ( &In, GV_POINT ) > 0 ) {
-            options.type->answers[num_types] = strdup ( "point" );
-            G_debug(3, "Adding points to export list." );
-            num_types ++;
-        }
-
-        if ( Vect_get_num_primitives ( &In, GV_LINE ) > 0 ) {
-            options.type->answers[num_types] = strdup ( "line" );
-            G_debug(3, "Adding lines to export list." );
-            num_types ++;
-        }
-
-        if ( Vect_get_num_primitives ( &In, GV_BOUNDARY ) !=
-             Vect_get_num_areas ( &In ) )
-        {
-            G_warning(_("Skipping all boundaries that are not part of an area."));
-        }
-
-        if ( Vect_get_num_areas ( &In ) > 0  ) {
-            options.type->answers[num_types] = strdup ( "area" );
-            G_debug(3, "Adding areas to export list." );
-            num_types ++;
-        }
-
-        /*  Faces and volumes:
-            For now, volumes will just be exported as sets of faces.
-        */
-        if ( Vect_get_num_primitives ( &In, GV_FACE ) > 0 ) {
-            options.type->answers[num_types] = strdup ( "face" );
-            G_debug(3, "Adding faces to export list." );
-            num_types ++;
-        }
-        /* this check HAS TO FOLLOW RIGHT AFTER check for GV_FACE! */
-        if ( Vect_get_num_volumes ( &In ) > 0 ) {
-            G_warning(_("Volumes will be exported as sets of faces."));
-            if ( num_types == 0 ) {
-                /* no other types yet? */
-                options.type->answers[num_types] = strdup ( "volume" );
-                G_debug(3, "Adding volumes to export list." );
-                num_types ++;
-            } else {
-                if ( strcmp ( options.type->answers[num_types-1], "face" ) ) {
-                    /* only put faces on export list if that's not the case already */
-                    options.type->answers[num_types] = strdup ( "volume" );
-                    G_debug(3, "Adding volumes to export list." );
-                    num_types ++;
-                }
-            }
-        }
-
-        if ( num_types == 0 )
-            G_fatal_error(_("Could not determine input map's feature type(s)."));
-    }
-
     if (flags.cat->answer)
 	donocat = 1;
     else



More information about the grass-commit mailing list