[GRASS-SVN] r45184 - grass/trunk/vector/v.external
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 25 14:03:18 EST 2011
Author: martinl
Date: 2011-01-25 11:03:18 -0800 (Tue, 25 Jan 2011)
New Revision: 45184
Modified:
grass/trunk/vector/v.external/args.c
grass/trunk/vector/v.external/main.c
Log:
v.external: dsn/layer required, check overwrite
Modified: grass/trunk/vector/v.external/args.c
===================================================================
--- grass/trunk/vector/v.external/args.c 2011-01-25 18:35:13 UTC (rev 45183)
+++ grass/trunk/vector/v.external/args.c 2011-01-25 19:03:18 UTC (rev 45184)
@@ -12,38 +12,41 @@
options->dsn->key = "dsn";
options->dsn->type = TYPE_STRING;
options->dsn->gisprompt = "old_file,file,dsn";
- options->dsn->label = _("OGR data source name");
+ options->dsn->label = _("Name of input OGR data source");
options->dsn->description = _("Examples:\n"
- "\t\tESRI Shapefile: directory containing shapefiles\n"
- "\t\tMapInfo File: directory containing mapinfo files\n"
- "\t\tPostGIS database: \"PG:dbname=<database>\"");
- options->dsn->guisection = _("Data source");
+ "\t\tESRI Shapefile: directory containing a shapefile\n"
+ "\t\tMapInfo File: directory containing a mapinfo file\n"
+ "\t\tPostGIS database: PG:dbname=<database>");
+ options->dsn->required = YES;
options->layer = G_define_option();
options->layer->key = "layer";
options->layer->type = TYPE_STRING;
options->layer->required = NO;
options->layer->multiple = NO;
- options->layer->label = _("OGR layer name");
+ options->layer->label = _("Name of input OGR layer");
options->layer->description = _("Examples:\n"
"\t\tESRI Shapefile: shapefile name\n"
"\t\tMapInfo File: mapinfo file name\n"
"\t\tPostGIS database: table name");
- options->layer->guisection = _("Data source");
+ options->layer->required = YES;
+ options->layer->key_desc = "name";
options->output = G_define_standard_option(G_OPT_V_OUTPUT);
options->output->required = NO;
- options->output->description = _("Name for GRASS vector map");
+ options->output->description = _("Name for output GRASS vector map");
flags->format = G_define_flag();
flags->format->key = 'f';
flags->format->description = _("List supported OGR formats and exit");
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 dsn and exit");
+ flags->layer->description = _("List available OGR layers in given data source and exit");
flags->layer->guisection = _("Print");
+ flags->layer->suppress_required = YES;
flags->topo = G_define_flag();
flags->topo->key = 'b';
Modified: grass/trunk/vector/v.external/main.c
===================================================================
--- grass/trunk/vector/v.external/main.c 2011-01-25 18:35:13 UTC (rev 45183)
+++ grass/trunk/vector/v.external/main.c 2011-01-25 19:03:18 UTC (rev 45184)
@@ -8,7 +8,7 @@
*
* PURPOSE: Create a new vector as a link to OGR layer (read-only)
*
- * COPYRIGHT: (C) 2003-2010 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).
@@ -40,7 +40,8 @@
int ilayer, is3D;
char buf[GPATH_MAX];
-
+ const char *output;
+
G_gisinit(argv[0]);
module = G_define_module();
@@ -68,12 +69,10 @@
}
if (!options.output->answer)
- G_fatal_error(_("Required parameter <%s> not set"), options.output->key);
+ output = options.layer->answer;
+ else
+ output = options.output->answer;
- if (!options.layer->answer)
- G_fatal_error(_("Required parameter <%s> not set"), options.layer->key);
-
-
ilayer = list_layers(NULL, options.dsn->answer, options.layer->answer, &is3D);
if (ilayer == -1) {
G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
@@ -81,24 +80,29 @@
G_debug(2, "layer '%s' was found", options.layer->answer);
- Vect_open_new(&Map, options.output->answer, is3D);
+ if (G_find_vector2(output, G_mapset()) && !G_check_overwrite(argc, argv)) {
+ G_fatal_error(_("option <%s>: <%s> exists."),
+ options.output->key, output);
+ }
+
+ Vect_open_new(&Map, output, is3D);
Vect_hist_command(&Map);
Vect_close(&Map);
/* Vect_open_new created 'head', 'coor', 'hist' -> delete 'coor' and create 'frmt' */
sprintf(buf, "%s/%s/vector/%s/coor", G_location_path(), G_mapset(),
- options.output->answer);
+ output);
G_debug(2, "Delete '%s'", buf);
if (unlink(buf) == -1) {
- Vect_delete(options.output->answer);
+ Vect_delete(output);
G_fatal_error(_("Unable to delete '%s'"), buf);
}
/* Create frmt */
- sprintf(buf, "%s/%s", GV_DIRECTORY, options.output->answer);
+ sprintf(buf, "%s/%s", GV_DIRECTORY, output);
fd = G_fopen_new(buf, GV_FRMT_ELEMENT);
if (fd == NULL) {
- Vect_delete(options.output->answer);
+ Vect_delete(output);
G_fatal_error("Unable to open file '%s'", buf);
}
@@ -109,12 +113,12 @@
fclose(fd);
if (!flags.topo->answer) {
- Vect_open_old(&Map, options.output->answer, G_mapset());
+ Vect_open_old(&Map, output, G_mapset());
Vect_build(&Map);
Vect_close(&Map);
}
- G_done_msg(_("Link to vector map <%s> created."), options.output->answer);
+ G_done_msg(_("Link to vector map <%s> created."), output);
exit(EXIT_SUCCESS);
}
More information about the grass-commit
mailing list