浏览代码

Fix handling of qualified map names

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@32717 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 17 年之前
父节点
当前提交
921fc190ea
共有 2 个文件被更改,包括 38 次插入31 次删除
  1. 29 30
      lib/gis/opencell.c
  2. 9 1
      lib/vector/Vlib/map.c

+ 29 - 30
lib/gis/opencell.c

@@ -158,10 +158,18 @@ int G__open_cell_old(const char *name, const char *mapset)
     int MAP_NBYTES;
     int MAP_NBYTES;
     RASTER_MAP_TYPE MAP_TYPE;
     RASTER_MAP_TYPE MAP_TYPE;
     struct Reclass reclass;
     struct Reclass reclass;
+    const char *xmapset;
 
 
     /* make sure window is set    */
     /* make sure window is set    */
     G__init_window();
     G__init_window();
 
 
+    xmapset = G_find_cell2(name, mapset);
+    if (!xmapset) {
+	G_warning(_("Unable to find <%s@%s>"), name, mapset);
+	return -1;
+    }
+    mapset = xmapset;
+
     /* Check for reclassification */
     /* Check for reclassification */
     reclass_flag = G_get_reclass(name, mapset, &reclass);
     reclass_flag = G_get_reclass(name, mapset, &reclass);
 
 
@@ -943,15 +951,17 @@ int G_set_fp_type(RASTER_MAP_TYPE map_type)
 int G_raster_map_is_fp(const char *name, const char *mapset)
 int G_raster_map_is_fp(const char *name, const char *mapset)
 {
 {
     char path[GPATH_MAX];
     char path[GPATH_MAX];
+    const char *xmapset;
 
 
-    if (G_find_cell2(name, mapset) == NULL) {
-	G_warning(_("Unable to find <%s@%s>"), name, mapset);
+    xmapset = G_find_cell2(name, mapset);
+    if (!xmapset) {
+	G_warning(_("Unable to find '%s' in '%s'"), name, mapset);
 	return -1;
 	return -1;
     }
     }
-    G__file_name(path, "fcell", name, mapset);
+    G__file_name(path, "fcell", name, xmapset);
     if (access(path, 0) == 0)
     if (access(path, 0) == 0)
 	return 1;
 	return 1;
-    G__file_name(path, "g3dcell", name, mapset);
+    G__file_name(path, "g3dcell", name, xmapset);
     if (access(path, 0) == 0)
     if (access(path, 0) == 0)
 	return 1;
 	return 1;
     
     
@@ -964,8 +974,6 @@ int G_raster_map_is_fp(const char *name, const char *mapset)
   Determines if the raster map is floating point or integer. Returns
   Determines if the raster map is floating point or integer. Returns
   DCELL_TYPE for double maps, FCELL_TYPE for float maps, CELL_TYPE for 
   DCELL_TYPE for double maps, FCELL_TYPE for float maps, CELL_TYPE for 
   integer maps, -1 if error has occured
   integer maps, -1 if error has occured
-  
-  This function just calls G_raster_map_type()!
 
 
   \param name map name 
   \param name map name 
   \param mapset mapset where map <i>name</i> lives
   \param mapset mapset where map <i>name</i> lives
@@ -974,38 +982,23 @@ int G_raster_map_is_fp(const char *name, const char *mapset)
 */
 */
 RASTER_MAP_TYPE G_raster_map_type(const char *name, const char *mapset)
 RASTER_MAP_TYPE G_raster_map_type(const char *name, const char *mapset)
 {
 {
-    return G_raster_map_type2(name, mapset);
-}
-
-/*!
-  \brief Determine raster type (look but don't touch)
-
-  See G_raster_map_type().
-
-  \param name map name
-  \param mapset mapset where map <i>name</i> lives
-  
-  \return raster data type
-*/
-RASTER_MAP_TYPE G_raster_map_type2(const char *name, const char *mapset)
-{
     char path[GPATH_MAX];
     char path[GPATH_MAX];
+    const char *xmapset;
 
 
-    if (G_find_cell2(name, mapset) == NULL) {
-	if (mapset) {
+    xmapset = G_find_cell2(name, mapset);
+    if (!xmapset) {
+	if (mapset && *mapset)
 	    G_warning(_("Raster map <%s> not found in mapset <%s>"), name, mapset);
 	    G_warning(_("Raster map <%s> not found in mapset <%s>"), name, mapset);
-	}
-	else {
+	else
 	    G_warning(_("Raster map <%s> not found"), name);
 	    G_warning(_("Raster map <%s> not found"), name);
-	}
 	return -1;
 	return -1;
     }
     }
-    G__file_name(path, "fcell", name, mapset);
+    G__file_name(path, "fcell", name, xmapset);
 
 
     if (access(path, 0) == 0)
     if (access(path, 0) == 0)
-	return G__check_fp_type(name, mapset);
+	return G__check_fp_type(name, xmapset);
 
 
-    G__file_name(path, "g3dcell", name, mapset);
+    G__file_name(path, "g3dcell", name, xmapset);
 
 
     if (access(path, 0) == 0)
     if (access(path, 0) == 0)
 	return DCELL_TYPE;
 	return DCELL_TYPE;
@@ -1046,8 +1039,14 @@ RASTER_MAP_TYPE G__check_fp_type(const char *name, const char *mapset)
     int in_stat;
     int in_stat;
     char *str, *str1;
     char *str, *str1;
     RASTER_MAP_TYPE map_type;
     RASTER_MAP_TYPE map_type;
+    const char *xmapset;
 
 
-    G__file_name_misc(path, "cell_misc", FORMAT_FILE, name, mapset);
+    xmapset = G_find_cell2(name, mapset);
+    if (!xmapset) {
+	G_warning(_("Unable to find '%s' in '%s'"), name, mapset);
+	return -1;
+    }
+    G__file_name_misc(path, "cell_misc", FORMAT_FILE, name, xmapset);
 
 
     if (access(path, 0) != 0) {
     if (access(path, 0) != 0) {
 	G_warning(_("Unable to find '%s'"), path);
 	G_warning(_("Unable to find '%s'"), path);

+ 9 - 1
lib/vector/Vlib/map.c

@@ -166,6 +166,7 @@ Vect_copy(const char *in, const char *mapset, const char *out, FILE * msgout)
 	GV_TOPO_ELEMENT, GV_SIDX_ELEMENT, GV_CIDX_ELEMENT,
 	GV_TOPO_ELEMENT, GV_SIDX_ELEMENT, GV_CIDX_ELEMENT,
 	NULL
 	NULL
     };
     };
+    const char *xmapset;
 
 
     dbDriver *driver;
     dbDriver *driver;
 
 
@@ -174,13 +175,20 @@ Vect_copy(const char *in, const char *mapset, const char *out, FILE * msgout)
     if (Vect_legal_filename(out) < 0)
     if (Vect_legal_filename(out) < 0)
 	G_fatal_error(_("Vector map name is not SQL compliant"));
 	G_fatal_error(_("Vector map name is not SQL compliant"));
 
 
+    xmapset = G_find_vector2(in, mapset);
+    if (!xmapset) {
+	G_warning(_("Unable to find vector map <%s> in <%s>"), in, mapset);
+	return -1;
+    }
+    mapset = xmapset;
+
     /* Delete old vector if it exists */
     /* Delete old vector if it exists */
     if (G_find_vector2(out, G_mapset())) {
     if (G_find_vector2(out, G_mapset())) {
 	G_warning(_("Vector map <%s> already exists and will be overwritten"),
 	G_warning(_("Vector map <%s> already exists and will be overwritten"),
 		  out);
 		  out);
 	ret = Vect_delete(out);
 	ret = Vect_delete(out);
 	if (ret != 0) {
 	if (ret != 0) {
-	    G_warning(_("Unable to delete vector map <%s>"), in);
+	    G_warning(_("Unable to delete vector map <%s>"), out);
 	    return -1;
 	    return -1;
 	}
 	}
     }
     }