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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Sep 5 13:36:49 EDT 2009


Author: benducke
Date: 2009-09-05 13:36:49 -0400 (Sat, 05 Sep 2009)
New Revision: 38999

Modified:
   grass/trunk/vector/v.out.ogr/main.c
Log:
Fixed export of centroids only.
Added support for exporting kernels (as 3D points).
Added a stub for future volumes support (not visible to user yet).

Modified: grass/trunk/vector/v.out.ogr/main.c
===================================================================
--- grass/trunk/vector/v.out.ogr/main.c	2009-09-05 17:35:52 UTC (rev 38998)
+++ grass/trunk/vector/v.out.ogr/main.c	2009-09-05 17:36:49 UTC (rev 38999)
@@ -90,8 +90,7 @@
 
     in_opt = G_define_standard_option(G_OPT_V_INPUT);
 
-    type_opt = G_define_standard_option(G_OPT_V_TYPE);
-    type_opt->options = "point,kernel,centroid,line,boundary,area,face";
+    type_opt = G_define_standard_option(G_OPT_V3_TYPE);
     type_opt->answer = "line,boundary";
     type_opt->description =
 	_("Feature type. Combination of types is not supported "
@@ -576,7 +575,7 @@
 
 		OGR_G_AddGeometryDirectly(Ogr_geometry, ring);
 	    }
-	    else if (type == GV_POINT) {
+	    else if ((type == GV_POINT) || ((type == GV_CENTROID) && (otype & GV_CENTROID))) {
 		Ogr_geometry = OGR_G_CreateGeometry(wkbPoint);
 		OGR_G_AddPoint(Ogr_geometry, Points->x[0], Points->y[0],
 			       Points->z[0]);
@@ -751,7 +750,71 @@
 	}			/* for */
     }
 
+    /* Kernels */
+    if (otype & GV_KERNEL) {
+	G_message(_("Exporting %i kernels..."), Vect_get_num_kernels(&In));
+	for (i = 1; i <= Vect_get_num_lines(&In); i++) {
 
+	    G_percent(i, Vect_get_num_lines(&In), 1);
+
+	    type = Vect_read_line(&In, Points, Cats, i);
+	    G_debug(2, "line = %d type = %d", i, type);
+	    if (!(otype & type)) {
+		G_debug(2, "type %d not specified -> skipping", type);
+		fskip++;
+		continue;
+	    }
+
+	    Vect_cat_get(Cats, field, &cat);
+	    if (cat < 0 && !donocat) {	/* Do not export not labeled */
+		nocatskip++;
+		continue;
+	    }
+
+
+	    /* Geometry */
+	    if (type == GV_KERNEL) {
+            Ogr_geometry = OGR_G_CreateGeometry(wkbPoint);
+            OGR_G_AddPoint(Ogr_geometry, Points->x[0], Points->y[0],
+                    Points->z[0]);
+
+            Ogr_feature = OGR_F_Create(Ogr_featuredefn);
+
+            OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
+
+            /* Output one feature for each category */
+            for (j = -1; j < Cats->n_cats; j++) {
+            if (j == -1) {
+                if (cat >= 0)
+                continue;	/* cat(s) exists */
+            }
+            else {
+                if (Cats->field[j] == field)
+                cat = Cats->cat[j];
+                else
+                continue;
+            }
+
+                mk_att(cat, Fi, Driver, ncol, doatt, nocat_flag->answer, Ogr_feature);
+                OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
+            }
+            OGR_G_DestroyGeometry(Ogr_geometry);
+            OGR_F_Destroy(Ogr_feature);
+	    }
+	}
+    }
+
+    /*
+        TODO:   Volumes. Do not export kernels here, that's already done.
+                We do need to worry about holes, though.
+        NOTE: We can probably just merge this with faces export function.
+              Except for GRASS, which output format would know the difference?
+    */
+    if ((otype & GV_VOLUME)) {
+        G_message(_("Exporting %i volumes..."), Vect_get_num_volumes(&In));
+        G_warning(_("Export of volumes not implemented yet. Skipping."));
+    }
+
     OGR_DS_Destroy(Ogr_ds);
 
     Vect_close(&In);



More information about the grass-commit mailing list