Browse Source

v.edit: fix `tool=create` for PostGIS data driver

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@51128 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 years ago
parent
commit
dc25334d99
2 changed files with 21 additions and 12 deletions
  1. 3 2
      lib/vector/Vlib/open_pg.c
  2. 18 10
      vector/v.edit/main.c

+ 3 - 2
lib/vector/Vlib/open_pg.c

@@ -246,8 +246,9 @@ int V1_open_new_pg(struct Map_info *Map, const char *name, int with_z)
 	    }
 	}
 	else {
-	    G_warning(_("PostGIS layer <%s> already exists in database '%s'"),
-		      pg_info->table_name, pg_info->db_name);
+	    G_fatal_error(_("PostGIS layer <%s.%s> already exists in database '%s'"),
+			  pg_info->schema_name, pg_info->table_name,
+			  pg_info->db_name);
 	    return -1;
 	}
     }

+ 18 - 10
vector/v.edit/main.c

@@ -84,10 +84,12 @@ int main(int argc, char *argv[])
 	G_fatal_error(_("Required parameter <%s> not set"), params.in->key);
     
     if (action_mode == MODE_CREATE) {
-	int overwrite;
-
+	int overwrite, map_type;
+	
 	overwrite = G_check_overwrite(argc, argv);
-	if (G_find_vector2(params.map->answer, G_mapset())) {
+	if (G_find_vector2(params.map->answer, G_mapset()) &&
+	    (!G_find_file("", "OGR", G_mapset()) &&
+	     !G_find_file("", "PG", G_mapset()))) {
 	    if (!overwrite)
 		G_fatal_error(_("Vector map <%s> already exists"),
 			      params.map->answer);
@@ -95,20 +97,26 @@ int main(int argc, char *argv[])
 
 	/* 3D vector maps? */
 	ret = Vect_open_new(&Map, params.map->answer, WITHOUT_Z);
-	if (Vect_maptype(&Map) == GV_FORMAT_OGR_DIRECT) {
+	if (ret == -1) {
+	    G_fatal_error(_("Unable to create vector map <%s>"),
+			  params.map->answer);
+	}
+	
+	/* native or external data source ? */
+	map_type = Vect_maptype(&Map);
+	if (map_type != GV_FORMAT_NATIVE) {
 	    int type;
 	    type = Vect_option_to_types(params.type);
 	    if (type != GV_POINT && type != GV_LINE &&
 		type != GV_BOUNDARY)
 		G_fatal_error(_("Supported feature type for OGR layer: "
 				"%s, %s or %s"), "point", "line", "boundary");
-	    V2_open_new_ogr(&Map, type);
+	    if (map_type == GV_FORMAT_POSTGIS)
+		V2_open_new_pg(&Map, type);
+	    else
+		V2_open_new_ogr(&Map, type);
 	}
-	if (ret == -1) {
-	    G_fatal_error(_("Unable to create vector map <%s>"),
-			  params.map->answer);
-	}
-
+	
 	G_debug(1, "Map created");
 
 	if (ascii) {