[GRASS-SVN] r53185 - grass/trunk/vector/v.out.postgis

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 16 03:56:32 PDT 2012


Author: martinl
Date: 2012-09-16 03:56:32 -0700 (Sun, 16 Sep 2012)
New Revision: 53185

Modified:
   grass/trunk/vector/v.out.postgis/local_proto.h
   grass/trunk/vector/v.out.postgis/main.c
   grass/trunk/vector/v.out.postgis/options.c
Log:
v.out.postgis: parameter `schema` removed
               keep syntax synchronized with `v.out.ogr`


Modified: grass/trunk/vector/v.out.postgis/local_proto.h
===================================================================
--- grass/trunk/vector/v.out.postgis/local_proto.h	2012-09-16 10:00:25 UTC (rev 53184)
+++ grass/trunk/vector/v.out.postgis/local_proto.h	2012-09-16 10:56:32 UTC (rev 53185)
@@ -4,7 +4,7 @@
 #include <grass/vector.h>
 
 struct params {
-    struct Option *input, *layer, *dsn, *olayer, *schema;
+    struct Option *input, *layer, *dsn, *olayer;
 };
 
 struct flags {

Modified: grass/trunk/vector/v.out.postgis/main.c
===================================================================
--- grass/trunk/vector/v.out.postgis/main.c	2012-09-16 10:00:25 UTC (rev 53184)
+++ grass/trunk/vector/v.out.postgis/main.c	2012-09-16 10:56:32 UTC (rev 53185)
@@ -28,6 +28,7 @@
     struct flags flags;
     
     int ret, field;
+    char *schema, *olayer;
     struct Map_info In, Out;
     
     G_gisinit(argv[0]);
@@ -47,9 +48,31 @@
         exit(EXIT_FAILURE);
 
     /* if olayer not given, use input as the name */
-    if (!params.olayer->answer)
-        params.olayer->answer = G_store(params.input->answer);
+    schema = NULL;
+    if (!params.olayer->answer) {
+        olayer = G_store(params.input->answer);
+    }
+    else {
+        /* check for schema */
+        char **tokens;
+
+        tokens = G_tokenize(params.olayer->answer, ".");
+        if (G_number_of_tokens(tokens) == 2) {
+            schema = G_store(tokens[0]);
+            olayer = G_store(tokens[1]);
+        }
+        else {
+            olayer = G_store(params.olayer->answer);
+        }
+        
+        G_free_tokens(tokens);
+    }
     
+    /* if schema not defined, use 'public' */
+    if (!schema)
+        schema = "public";
+    G_debug(1, "Database schema: %s", schema);
+    
     /* open input for reading */
     ret = Vect_open_old2(&In, params.input->answer, "", params.layer->answer);
     if (ret == -1)
@@ -60,11 +83,11 @@
                   params.input->answer);
     
     /* create output for writing */
-    create_pgfile(params.dsn->answer, params.schema->answer, flags.topo->answer ? TRUE : FALSE);
+    create_pgfile(params.dsn->answer, schema, flags.topo->answer ? TRUE : FALSE);
     
-    if (-1 == Vect_open_new(&Out, params.olayer->answer, Vect_is_3d(&In)))
+    if (-1 == Vect_open_new(&Out, olayer, Vect_is_3d(&In)))
         G_fatal_error(_("Unable to create PostGIS layer <%s>"),
-                      params.olayer->answer);
+                      olayer);
     
     /* define attributes */
     field = Vect_get_field_number(&In, params.layer->answer);
@@ -73,15 +96,24 @@
 
     /* create PostGIS layer */
     create_table(&In, &Out);
-
+    
+    if (flags.topo->answer) 
+        Vect_build_partial(&Out, GV_BUILD_NONE); /* upgrade level to 2 */
+    
     /* copy vector features */
     if (Vect_copy_map_lines_field(&In, field, &Out) != 0)
         G_fatal_error(_("Copying features failed"));
     
-    Vect_build(&Out);
+    Vect_close(&In);
     
-    Vect_close(&In);
+    if (Vect_build(&Out) != 1)
+        G_fatal_error(_("Building %s topology failed"),
+                      flags.topo->answer ? "PostGIS" : "pseudo");
+
+    G_done_msg(_("Feature table <%s> created in database <%s>."),
+               Vect_get_finfo_layer_name(&Out), Vect_get_finfo_dsn_name(&Out));
+    
     Vect_close(&Out);
-    
+
     exit(EXIT_SUCCESS);
 }

Modified: grass/trunk/vector/v.out.postgis/options.c
===================================================================
--- grass/trunk/vector/v.out.postgis/options.c	2012-09-16 10:00:25 UTC (rev 53184)
+++ grass/trunk/vector/v.out.postgis/options.c	2012-09-16 10:56:32 UTC (rev 53185)
@@ -19,13 +19,6 @@
     params->dsn->description =
         _("Starts with 'PG' prefix, eg. 'PG:dbname=grass'");
     
-    params->schema = G_define_option();
-    params->schema->key = "schema";
-    params->schema->type = TYPE_STRING;
-    params->schema->required = NO;
-    params->schema->description = _("Database schema");
-    params->schema->answer = "public";
-    
     params->olayer = G_define_option();
     params->olayer->key = "olayer";
     params->olayer->type = TYPE_STRING;



More information about the grass-commit mailing list