Sfoglia il codice sorgente

vlib(pg): use temporary map in native format when output is simple features

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55409 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 anni fa
parent
commit
083ccea1c1
3 ha cambiato i file con 22 aggiunte e 7 eliminazioni
  1. 3 3
      lib/vector/Vlib/close.c
  2. 2 2
      lib/vector/Vlib/header_finfo.c
  3. 17 2
      lib/vector/Vlib/open.c

+ 3 - 3
lib/vector/Vlib/close.c

@@ -81,11 +81,11 @@ int Vect_close(struct Map_info *Map)
 	    Map->name, Map->mapset, Map->format, Map->level, Map->temporary);
 
     if (Map->temporary &&
-        (Map->fInfo.ogr.dsn || Map->fInfo.pg.db_name)) {
+        (Map->fInfo.ogr.dsn || Map->fInfo.pg.conninfo)) {
         /* transfer features for external output format */
         struct Map_info Out;
         
-        putenv("GRASS_VECTOR_OGR_DIRECT=1");
+        putenv("GRASS_VECTOR_EXTERNAL_DIRECT=1");
         if (-1 == Vect_open_new(&Out, Vect_get_name(Map), Vect_is_3d(Map))) {
             G_warning(_("Unable to create vector map <%s>"),
                       Vect_get_name(Map));
@@ -103,7 +103,7 @@ int Vect_close(struct Map_info *Map)
         Vect_build(&Out);
         
         Vect_close(&Out);
-        putenv("GRASS_VECTOR_OGR_DIRECT="); /* unset variable */
+        putenv("GRASS_VECTOR_EXTERNAL_DIRECT="); /* unset variable */
     }
     
     /* check for external formats whether to create a link */

+ 2 - 2
lib/vector/Vlib/header_finfo.c

@@ -180,8 +180,8 @@ const char *Vect_get_finfo_geometry_type(const struct Map_info *Map)
         res = PQexec(pg_info->conn, stmt);
         if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
             PQntuples(res) != 1) {
-            G_warning("%s\n%s", _("Unable to get feature type"),
-                      PQresultErrorMessage(res));
+            G_debug(1, "Unable to get feature type: %s",
+                    PQresultErrorMessage(res));
             return NULL;
         }
         ftype_tmp = G_store(PQgetvalue(res, 0, 0));

+ 17 - 2
lib/vector/Vlib/open.c

@@ -1200,7 +1200,7 @@ int map_format(struct Map_info *Map)
         struct Format_info_ogr *ogr_info;
         
         G_debug(2, " using OGR format");
-        if (getenv("GRASS_VECTOR_OGR_DIRECT")) {
+        if (getenv("GRASS_VECTOR_EXTERNAL_DIRECT")) {
             /* vector features are written directly to OGR layer */
             format = GV_FORMAT_OGR;
         }
@@ -1242,6 +1242,7 @@ int map_format(struct Map_info *Map)
             G_warning(_("OGR output also detected, using OGR"));
         }
         else {
+            int topology;
             FILE *fp;
             const char *p;
             
@@ -1249,7 +1250,6 @@ int map_format(struct Map_info *Map)
             struct Format_info_pg *pg_info;
             
             G_debug(2, " using PostGIS format");
-            format = GV_FORMAT_POSTGIS;
             fp = G_fopen_old("", def_file ? def_file : "PG", G_mapset());
             if (!fp) {
                 G_fatal_error(_("Unable to open PG file"));
@@ -1301,6 +1301,21 @@ int map_format(struct Map_info *Map)
             
             /* table name */
             Map->fInfo.pg.table_name = G_store(Map->name);
+
+            p = G_find_key_value("topology", key_val);
+            topology = p && G_strcasecmp(p, "yes") == 0;
+        
+            if (topology || getenv("GRASS_VECTOR_EXTERNAL_DIRECT")) {
+                /* vector features are written directly to PostGIS layer */
+                format = GV_FORMAT_POSTGIS;
+            }
+            else {
+                /* vector features are written to the temporary vector map
+                 * in the native format and when closing the map
+                 * transfered to output PostGIS layer */
+                format = GV_FORMAT_NATIVE;
+                Map->temporary = TRUE;
+            }
         }
     }