[GRASS-SVN] r51411 - grass/trunk/vector/v.external
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Apr 13 09:15:14 EDT 2012
Author: martinl
Date: 2012-04-13 06:15:13 -0700 (Fri, 13 Apr 2012)
New Revision: 51411
Modified:
grass/trunk/vector/v.external/main.c
Log:
v.external: add debug message (GRASS_VECTOR_OGR)
untabify
Modified: grass/trunk/vector/v.external/main.c
===================================================================
--- grass/trunk/vector/v.external/main.c 2012-04-13 12:57:52 UTC (rev 51410)
+++ grass/trunk/vector/v.external/main.c 2012-04-13 13:15:13 UTC (rev 51411)
@@ -52,92 +52,94 @@
G_add_keyword("OGR");
G_add_keyword("PostGIS");
module->description = _("Creates a new pseudo-vector map as a link to an OGR-supported layer "
- "or a PostGIS feature table.");
+ "or a PostGIS feature table.");
parse_args(argc, argv,
- &options, &flags);
+ &options, &flags);
use_ogr = TRUE;
+ G_debug(1, "GRASS_VECTOR_OGR defined? %s",
+ getenv("GRASS_VECTOR_OGR") ? "yes" : "no");
if(options.dsn->answer &&
G_strncasecmp(options.dsn->answer, "PG:", 3) == 0) {
- /* -> PostgreSQL */
+ /* -> PostgreSQL */
#if defined HAVE_OGR && defined HAVE_POSTGRES
- if (getenv("GRASS_VECTOR_OGR"))
- use_ogr = TRUE;
- else
- use_ogr = FALSE;
+ if (getenv("GRASS_VECTOR_OGR"))
+ use_ogr = TRUE;
+ else
+ use_ogr = FALSE;
#else
#ifdef HAVE_POSTGRES
- if (getenv("GRASS_VECTOR_OGR"))
- G_warning(_("Environment variable GRASS_VECTOR_OGR defined, "
- "but GRASS is compiled with OGR support. "
- "Using GRASS-PostGIS data driver instead."));
- use_ogr = FALSE;
+ if (getenv("GRASS_VECTOR_OGR"))
+ G_warning(_("Environment variable GRASS_VECTOR_OGR defined, "
+ "but GRASS is compiled with OGR support. "
+ "Using GRASS-PostGIS data driver instead."));
+ use_ogr = FALSE;
#else /* -> force using OGR */
- G_warning(_("GRASS is not compiled with PostgreSQL support. "
- "Using OGR-PostgreSQL driver instead of native "
- "GRASS-PostGIS data driver."));
- use_ogr = TRUE;
+ G_warning(_("GRASS is not compiled with PostgreSQL support. "
+ "Using OGR-PostgreSQL driver instead of native "
+ "GRASS-PostGIS data driver."));
+ use_ogr = TRUE;
#endif /* HAVE_POSTRES */
#endif /* HAVE_OGR && HAVE_POSTGRES */
}
#ifdef HAVE_OGR
if (use_ogr)
- OGRRegisterAll();
+ OGRRegisterAll();
#endif
if (flags.format->answer) {
- /* list formats */
- list_formats(stdout);
- exit(EXIT_SUCCESS);
+ /* list formats */
+ list_formats(stdout);
+ exit(EXIT_SUCCESS);
}
/* be friendly, ignored 'PG:' prefix for PostGIS links */
dsn = NULL;
if (options.dsn->answer) {
- if (!use_ogr) {
- int i, length;
-
- length = strlen(options.dsn->answer);
- dsn = (char *) G_malloc(length - 3);
- for (i = 3; i < length; i++)
- dsn[i-3] = options.dsn->answer[i];
- dsn[length-3] = '\0';
- }
- else {
- dsn = G_store(options.dsn->answer);
- }
+ if (!use_ogr) {
+ int i, length;
+
+ length = strlen(options.dsn->answer);
+ dsn = (char *) G_malloc(length - 3);
+ for (i = 3; i < length; i++)
+ dsn[i-3] = options.dsn->answer[i];
+ dsn[length-3] = '\0';
+ }
+ else {
+ dsn = G_store(options.dsn->answer);
+ }
}
if (flags.list->answer || flags.tlist->answer) {
- /* list layers */
- if (!dsn)
- G_fatal_error(_("Required parameter <%s> not set"), options.dsn->key);
- list_layers(stdout, dsn, NULL,
- flags.tlist->answer ? TRUE : FALSE,
- use_ogr, NULL);
- exit(EXIT_SUCCESS);
+ /* list layers */
+ if (!dsn)
+ G_fatal_error(_("Required parameter <%s> not set"), options.dsn->key);
+ list_layers(stdout, dsn, NULL,
+ flags.tlist->answer ? TRUE : FALSE,
+ use_ogr, NULL);
+ exit(EXIT_SUCCESS);
}
/* define name for output */
if (!options.output->answer)
- output = options.layer->answer;
+ output = options.layer->answer;
else
- output = options.output->answer;
+ output = options.output->answer;
/* get layer index */
ilayer = list_layers(NULL, dsn, options.layer->answer,
- FALSE, use_ogr, &is3D);
+ FALSE, use_ogr, &is3D);
if (ilayer == -1) {
- G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
+ G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
}
G_debug(2, "layer '%s' was found", options.layer->answer);
if (G_find_vector2(output, G_mapset()) && !G_check_overwrite(argc, argv)) {
- G_fatal_error(_("option <%s>: <%s> exists."),
- options.output->key, output);
+ G_fatal_error(_("option <%s>: <%s> exists."),
+ options.output->key, output);
}
/* create new vector map */
@@ -150,46 +152,46 @@
/* Vect_open_new created 'head', 'coor', 'hist'
-> delete 'coor' and create 'frmt' */
sprintf(buf, "%s/%s/%s/%s/coor", G_location_path(), G_mapset(),
- GV_DIRECTORY, output);
+ GV_DIRECTORY, output);
G_debug(2, "Delete '%s'", buf);
if (unlink(buf) == -1) {
- Vect_delete(output);
- G_fatal_error(_("Unable to delete '%s'"), buf);
+ Vect_delete(output);
+ G_fatal_error(_("Unable to delete '%s'"), buf);
}
/* create frmt file */
sprintf(buf, "%s/%s", GV_DIRECTORY, output);
fd = G_fopen_new(buf, GV_FRMT_ELEMENT);
if (fd == NULL) {
- Vect_delete(output);
- G_fatal_error("Unable to create file '%s'", buf);
+ Vect_delete(output);
+ G_fatal_error("Unable to create file '%s'", buf);
}
if (!use_ogr) {
- char *table_name, *schema_name;
-
- get_table_name(options.layer->answer, &table_name, &schema_name);
-
- fprintf(fd, "FORMAT: postgis\n");
- fprintf(fd, "CONNINFO: %s\n", dsn);
- if (schema_name)
- fprintf(fd, "SCHEMA: %s\n", schema_name);
- fprintf(fd, "TABLE: %s\n", table_name);
+ char *table_name, *schema_name;
+
+ get_table_name(options.layer->answer, &table_name, &schema_name);
+
+ fprintf(fd, "FORMAT: postgis\n");
+ fprintf(fd, "CONNINFO: %s\n", dsn);
+ if (schema_name)
+ fprintf(fd, "SCHEMA: %s\n", schema_name);
+ fprintf(fd, "TABLE: %s\n", table_name);
- G_free(table_name);
- G_free(schema_name);
+ G_free(table_name);
+ G_free(schema_name);
}
else {
- fprintf(fd, "FORMAT: ogr\n");
- fprintf(fd, "DSN: %s\n", dsn);
- fprintf(fd, "LAYER: %s\n", options.layer->answer);
+ fprintf(fd, "FORMAT: ogr\n");
+ fprintf(fd, "DSN: %s\n", dsn);
+ fprintf(fd, "LAYER: %s\n", options.layer->answer);
}
fclose(fd);
if (!flags.topo->answer) {
- Vect_open_old(&Map, output, G_mapset());
- Vect_build(&Map);
- Vect_close(&Map);
+ Vect_open_old(&Map, output, G_mapset());
+ Vect_build(&Map);
+ Vect_close(&Map);
}
G_done_msg(_("Link to vector map <%s> created."), output);
More information about the grass-commit
mailing list