[GRASS-dev] [GRASS GIS] #54: g.remove mixes raster and vector
maps: "Remove reclassed map first"
Glynn Clements
glynn at gclements.plus.com
Tue Feb 19 22:48:30 EST 2008
GRASS GIS wrote:
> #54: g.remove mixes raster and vector maps: "Remove reclassed map first"
> ---------------------+------------------------------------------------------
> Reporter: neteler | Owner: grass-dev at lists.osgeo.org
> Type: defect | Status: new
> Priority: major | Milestone: 6.4.0
> Component: default | Version: unspecified
> Keywords: |
> ---------------------+------------------------------------------------------
> A strange bug appeared: Trying to remove a vector map, g.remove gets
> confused with a non-exiting reclass map
>
> {{{
> GRASS 6.3.svn (pat):~ > g.remove
> vect=lst_20050101_avg,lst_20050101_avg2,lst_200501_avg_filt
> WARNING: [lst_20050101_avg at modisLSTzanzara] is a base map. Remove
> reclassed
> map first: MASK at modisLSTzanzara
> Removing vector <lst_20050101_avg2>
> WARNING: [lst_200501_avg_filt at modisLSTzanzara] is a base map. Remove
> reclassed map first: MASK at modisLSTzanzara
>
> GRASS 6.3.svn (pat):~ > g.remove vect=lst_20050101_avg
> WARNING: [lst_20050101_avg at modisLSTzanzara] is a base map. Remove
> reclassed
> map first: MASK at modisLSTzanzara
>
> GRASS 6.3.svn (pat):~ > g.list rast | grep lst_20050101_avg
> lst_20030114_avg lst_20050101_avg
> lst_20030115_avg lst_20050101_avg_lstmodel
>
> GRASS 6.3.svn (pat):~ > g.list vect | grep lst_
> lst_20050101_avg lst_200501_avg_filt
>
> GRASS 6.3.svn (pat):~ > r.info lst_20050101_avg | grep generated
> | generated by r.series
> |
>
> GRASS 6.3.svn (pat):~ > g.gisenv
> GISDBASE=/home/neteler/grassdata
> LOCATION_NAME=pat
> MAPSET=modisLSTzanzara
> DEBUG=0
> GRASS_GUI=text
> MONITOR=x0
> }}}
>
> The problem seems to be in source:grass/trunk/general/manage/cmd/remove.c
> (line 83) where it should not enter. Fix appreciated..
Can you test the attached patch?
--
Glynn Clements <glynn at gclements.plus.com>
-------------- next part --------------
Index: general/manage/cmd/remove.c
===================================================================
--- general/manage/cmd/remove.c (revision 30265)
+++ general/manage/cmd/remove.c (working copy)
@@ -24,6 +24,74 @@
#include "list.h"
#include "local_proto.h"
+static int
+check_reclass(const char *name, const char *mapset, int force)
+{
+ char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
+ char **rmaps;
+ int nrmaps;
+
+ if (G_is_reclassed_to(name, mapset, &nrmaps, &rmaps) > 0)
+ {
+ for ( ; *rmaps; rmaps++)
+ {
+ /* force remove */
+ if (force)
+ G_warning(
+ _("[%s@%s] is a base map for [%s]. Remove forced."),
+ name, mapset, *rmaps);
+ else
+ G_warning(
+ _("[%s@%s] is a base map. Remove reclassed map first: %s"),
+ name, mapset, *rmaps);
+ }
+
+ if (!force)
+ return 1;
+ }
+
+ if (G_is_reclass(name, mapset, rname, rmapset) > 0 &&
+ G_is_reclassed_to(rname, rmapset, &nrmaps, &rmaps) > 0)
+ {
+ char path[GPATH_MAX];
+ char *p = strchr(rname, '@');
+ char *qname = G_fully_qualified_name(name, mapset);
+
+ if (p)
+ *p = '\0';
+
+ G__file_name_misc(path, "cell_misc", "reclassed_to", rname, rmapset);
+
+ if(nrmaps == 1 && !G_strcasecmp(rmaps[0], qname))
+ {
+
+ if (remove(path) < 0)
+ G_warning(
+ _("Removing information about reclassed map from [%s@%s] failed"),
+ rname, rmapset);
+ }
+ else
+ {
+ FILE *fp = fopen(path, "w");
+
+ if (fp)
+ {
+ for ( ; *rmaps; rmaps++)
+ if (G_strcasecmp(*rmaps, qname))
+ fprintf(fp, "%s\n", *rmaps);
+ fclose(fp);
+ }
+ else
+ G_warning(
+ _("Removing information about reclassed map from [%s@%s] failed"),
+ rname, rmapset);
+
+ }
+ }
+
+ return 0;
+}
+
int
main (int argc, char *argv[])
{
@@ -32,10 +100,7 @@
struct Option **parm, *p;
struct Flag *force_flag;
char *name, *mapset;
- char rname[256], rmapset[256];
- int nrmaps;
- char **rmaps, *location_path;
- FILE *fp;
+ char *location_path;
int result = EXIT_SUCCESS;
int force = 0;
@@ -80,62 +145,10 @@
if (parm[n]->answers)
for (i = 0; (name = parm[n]->answers[i]); i++)
{
- if(G_is_reclassed_to(name, mapset, &nrmaps, &rmaps) > 0)
- {
- for(; *rmaps; rmaps++) {
- /* force remove */
- if ( force ) {
- G_warning(
- _("[%s@%s] is a base map for [%s]. Remove forced."),
- name, mapset, *rmaps);
- }
- else {
- G_warning(
- _("[%s@%s] is a base map. Remove reclassed map first: %s"),
- name, mapset, *rmaps);
- }
- }
- if ( !force )
- continue;
- }
- if(G_is_reclass(name, mapset, rname, rmapset) > 0 &&
- G_is_reclassed_to(rname, rmapset, &nrmaps, &rmaps) > 0)
- {
- char path[GPATH_MAX];
- char *p = strchr(rname, '@');
- char *qname = G_fully_qualified_name(name, mapset);
- if (p)
- *p = '\0';
- G__file_name_misc(path, "cell_misc", "reclassed_to", rname, rmapset);
+ if (G_strcasecmp(list[n].alias, "rast") == 0 &&
+ check_reclass(name, mapset, force))
+ continue;
- if(nrmaps == 1 && !G_strcasecmp(rmaps[0], qname))
- {
-
- if ( remove(path) < 0 ) {
- G_warning(
- _("Removing information about reclassed map from [%s@%s] failed"),
- rname, rmapset);
- }
-
- }
- else
- {
- if ( (fp = fopen(path, "w")) ) {
- for(; *rmaps; rmaps++)
- {
- if(G_strcasecmp(*rmaps, qname))
- fprintf(fp, "%s\n", *rmaps);
- }
- fclose(fp);
- }
- else {
- G_warning(
- _("Removing information about reclassed map from [%s@%s] failed"),
- rname, rmapset);
-
- }
- }
- }
if ( do_remove (n, name) == 1 )
{
result = EXIT_FAILURE;
More information about the grass-dev
mailing list