[GRASS-SVN] r47998 - in grass/trunk/vector: v.external v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 31 07:35:55 EDT 2011


Author: martinl
Date: 2011-08-31 04:35:54 -0700 (Wed, 31 Aug 2011)
New Revision: 47998

Modified:
   grass/trunk/vector/v.external/args.c
   grass/trunk/vector/v.external/list.c
   grass/trunk/vector/v.external/local_proto.h
   grass/trunk/vector/v.external/main.c
   grass/trunk/vector/v.in.ogr/main.c
Log:
v.external + v.in.ogr: flag to list also feature types


Modified: grass/trunk/vector/v.external/args.c
===================================================================
--- grass/trunk/vector/v.external/args.c	2011-08-31 10:58:21 UTC (rev 47997)
+++ grass/trunk/vector/v.external/args.c	2011-08-31 11:35:54 UTC (rev 47998)
@@ -42,12 +42,19 @@
     flags->format->guisection = _("Print");
     flags->format->suppress_required = YES;
 
-    flags->layer = G_define_flag();
-    flags->layer->key = 'l';
-    flags->layer->description = _("List available OGR layers in given data source and exit");
-    flags->layer->guisection = _("Print");
-    flags->layer->suppress_required = YES;
+    flags->list = G_define_flag();
+    flags->list->key = 'l';
+    flags->list->description = _("List available OGR layers in data source and exit");
+    flags->list->guisection = _("Print");
+    flags->list->suppress_required = YES;
 
+    flags->tlist = G_define_flag();
+    flags->tlist->key = 't';
+    flags->tlist->description = _("List available OGR layers including feature types "
+				  "in datatsource and exit");
+    flags->tlist->guisection = _("Print");
+    flags->tlist->suppress_required = YES;
+
     flags->topo = G_define_flag();
     flags->topo->key = 'b';
     flags->topo->description = _("Do not build topology");
@@ -55,15 +62,3 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 }
-
-void get_args(const struct _options *options, const struct _flags *flags,
-	      char **dsn, char **layer, char **output,
-	      int *list_format, int *list_layers, int *topo)
-{
-    *dsn    = options->dsn->answer;
-    *layer  = options->layer->answer;
-    *output = options->output->answer;
-    *list_format = flags->format->answer ? 1 : 0;
-    *list_layers = flags->layer->answer ? 1 : 0;
-    *topo        = flags->topo-> answer ? 1 : 0;
-}

Modified: grass/trunk/vector/v.external/list.c
===================================================================
--- grass/trunk/vector/v.external/list.c	2011-08-31 10:58:21 UTC (rev 47997)
+++ grass/trunk/vector/v.external/list.c	2011-08-31 11:35:54 UTC (rev 47998)
@@ -17,7 +17,7 @@
     }
 }
 
-int list_layers(FILE *fd, const char *dsn, const char *layer, int *is3D)
+int list_layers(FILE *fd, const char *dsn, const char *layer, int print_types, int *is3D)
 {
     int i, ret;
     int nlayers;
@@ -46,15 +46,18 @@
     for (i = 0; i < nlayers; i++) {
 	Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
 	Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
+	Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
 	layer_name = (char *) OGR_FD_GetName(Ogr_featuredefn);
 
-	if (fd)
-	    fprintf(fd, "%s\n", layer_name);
-	
+	if (fd) {
+	    if (print_types)
+		fprintf(fd, "%s (%s)\n", layer_name, OGRGeometryTypeToName(Ogr_geom_type));
+	    else
+		fprintf(fd, "%s\n", layer_name);
+	}
 	if (layer)
 	    if (strcmp(layer_name, layer) == 0) {
 		if (is3D) {
-		    Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
 		    switch(Ogr_geom_type) {
 		    case wkbPoint25D: case wkbLineString25D: case wkbPolygon25D:
 		    case wkbMultiPoint25D: case wkbMultiLineString25D: case wkbMultiPolygon25D:

Modified: grass/trunk/vector/v.external/local_proto.h
===================================================================
--- grass/trunk/vector/v.external/local_proto.h	2011-08-31 10:58:21 UTC (rev 47997)
+++ grass/trunk/vector/v.external/local_proto.h	2011-08-31 11:35:54 UTC (rev 47998)
@@ -6,18 +6,15 @@
 };
 
 struct _flags {
-    struct Flag *format, *layer, *topo;
+    struct Flag *format, *list, *tlist, *topo;
 };
 
 /* args.c */
 void parse_args(int, char **,
 		struct _options *, struct _flags*);
-void get_args(const struct _options *, const struct _flags *,
-	      char **, char **, char **,
-	      int *, int *, int *);
 
 /* list.c */
 void list_formats(FILE *);
-int list_layers(FILE *, const char *, const char *, int *);
+int list_layers(FILE *, const char *, const char *, int, int *);
 
 #endif

Modified: grass/trunk/vector/v.external/main.c
===================================================================
--- grass/trunk/vector/v.external/main.c	2011-08-31 10:58:21 UTC (rev 47997)
+++ grass/trunk/vector/v.external/main.c	2011-08-31 11:35:54 UTC (rev 47998)
@@ -61,10 +61,12 @@
 	exit(EXIT_SUCCESS);
     }
 
-    if (flags.layer->answer) {
+    if (flags.list->answer || flags.tlist->answer) {
 	if (!options.dsn->answer)
 	    G_fatal_error(_("Required parameter <%s> not set"), options.dsn->key);
-	list_layers(stdout, options.dsn->answer, NULL, NULL);
+	list_layers(stdout, options.dsn->answer, NULL,
+		    flags.tlist->answer ? TRUE : FALSE,
+		    NULL);
 	exit(EXIT_SUCCESS);
     }
 
@@ -73,7 +75,8 @@
     else
 	output = options.output->answer;
     
-    ilayer = list_layers(NULL, options.dsn->answer, options.layer->answer, &is3D);
+    ilayer = list_layers(NULL, options.dsn->answer, options.layer->answer,
+			 FALSE, &is3D);
     if (ilayer == -1) {
 	G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
     }

Modified: grass/trunk/vector/v.in.ogr/main.c
===================================================================
--- grass/trunk/vector/v.in.ogr/main.c	2011-08-31 10:58:21 UTC (rev 47997)
+++ grass/trunk/vector/v.in.ogr/main.c	2011-08-31 11:35:54 UTC (rev 47998)
@@ -9,12 +9,11 @@
  *
  * PURPOSE:      Import OGR vectors
  *
- * COPYRIGHT:    (C) 2003 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2003, 2011 by the GRASS Development Team
  *
- *               This program is free software under the
- *               GNU General Public License (>=v2).
- *               Read the file COPYING that comes with GRASS
- *               for details.
+ *               This program is free software under the GNU General
+ *               Public License (>=v2).  Read the file COPYING that
+ *               comes with GRASS for details.
  *
  * TODO: - make fixed field length of OFTIntegerList dynamic
  *       - several other TODOs below
@@ -55,7 +54,7 @@
 	struct Option *snap, *type, *outloc, *cnames;
     } param;
     struct _flag {
-	struct Flag *list, *no_clean, *z, *notab,
+	struct Flag *list, *tlist, *no_clean, *z, *notab,
 	    *region;
 	struct Flag *over, *extend, *formats, *tolower, *no_import;
     } flag;
@@ -93,6 +92,8 @@
     OGRGeometryH Ogr_geometry, Ogr_oRing, poSpatialFilter;
     OGRSpatialReferenceH Ogr_projection;
     OGREnvelope oExt;
+    OGRwkbGeometryType Ogr_geom_type;
+
     int OFTIntegerListlength;
 
     char *output;
@@ -209,11 +210,17 @@
 
     flag.list = G_define_flag();
     flag.list->key = 'l';
-    flag.list->description =
-	_("List available layers in data source and exit");
+    flag.list->description = _("List available OGR layers in data source and exit");
     flag.list->suppress_required = YES;
     flag.list->guisection = _("Print");
 
+    flag.tlist = G_define_flag();
+    flag.tlist->key = 't';
+    flag.tlist->description = _("List available OGR layers including feature types "
+			       "in data source and exit");
+    flag.tlist->suppress_required = YES;
+    flag.tlist->guisection = _("Print");
+
     flag.formats = G_define_flag();
     flag.formats->key = 'f';
     flag.formats->description = _("List supported formats and exit");
@@ -326,21 +333,25 @@
     available_layer_names =
 	(char **)G_malloc(navailable_layers * sizeof(char *));
 
-    if (flag.list->answer)
-	G_message(_("Data source contains %d layers:"),
-		  navailable_layers);
-
+    if (flag.list->answer || flag.tlist->answer)
+	G_message(_("Data source <%s> (format '%s') contains %d layers:"),
+		  param.dsn->answer,
+		  OGR_Dr_GetName(OGR_DS_GetDriver(Ogr_ds)), navailable_layers);
     for (i = 0; i < navailable_layers; i++) {
 	Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
 	Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
+	Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
+	
 	available_layer_names[i] =
 	    G_store((char *)OGR_FD_GetName(Ogr_featuredefn));
 
-	if (flag.list->answer) {
+	if (flag.tlist->answer)
+	    fprintf(stdout, "%s (%s)\n", available_layer_names[i],
+		    OGRGeometryTypeToName(Ogr_geom_type));
+	else if (flag.list->answer)
 	    fprintf(stdout, "%s\n", available_layer_names[i]);
-	}
     }
-    if (flag.list->answer) {
+    if (flag.list->answer || flag.tlist->answer) {
 	fflush(stdout);
 	exit(EXIT_SUCCESS);
     }



More information about the grass-commit mailing list