Skip to content

g.rename.many

Renames multiple maps in the current mapset.

g.rename.many [-sd] [raster=name] [raster_3d=name] [vector=name] [separator=character] [--verbose] [--quiet] [--qq] [--ui]

Example:

g.rename.many raster=name

grass.script.run_command("g.rename.many", raster=None, raster_3d=None, vector=None, separator="comma", flags=None, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("g.rename.many", raster="name")

Parameters

raster=name
    File with rasters to be renamed
    Format of the file is one raster map per line. Old name first, new name second (separated by comma by default)
raster_3d=name
    File with 3D rasters to be renamed
    Format of the file is one raster map per line. Old name first, new name second (separated by comma by default)
vector=name
    File with vectors to be renamed
    Format of the file is one vector map per line. Old name first, new name second (separated by comma by default)
separator=character
    Field separator
    Special characters: pipe, comma, space, tab, newline
    Default: comma
-s
    Skip file format and map existence checks
    By default a file format check is performed and existence of map is checked before the actual renaming. This requires going through each file two times. It might be advantageous to disable the checks for renames of large number of maps. However, when this flag is used an error occurs, some maps might be renamed while some others not.
-d
    Do the checks only (dry run)
    This will only perform the file format and map existence checks but it will not do the actual rename. This is useful when writing the file with renames.
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output
--qq
    Very quiet module output
--ui
    Force launching GUI dialog

raster : str, optional
    File with rasters to be renamed
    Format of the file is one raster map per line. Old name first, new name second (separated by comma by default)
    Used as: input, file, name
raster_3d : str, optional
    File with 3D rasters to be renamed
    Format of the file is one raster map per line. Old name first, new name second (separated by comma by default)
    Used as: input, file, name
vector : str, optional
    File with vectors to be renamed
    Format of the file is one vector map per line. Old name first, new name second (separated by comma by default)
    Used as: input, file, name
separator : str, optional
    Field separator
    Special characters: pipe, comma, space, tab, newline
    Used as: input, separator, character
    Default: comma
flags : str, optional
    Allowed values: s, d
    s
        Skip file format and map existence checks
        By default a file format check is performed and existence of map is checked before the actual renaming. This requires going through each file two times. It might be advantageous to disable the checks for renames of large number of maps. However, when this flag is used an error occurs, some maps might be renamed while some others not.
    d
        Do the checks only (dry run)
        This will only perform the file format and map existence checks but it will not do the actual rename. This is useful when writing the file with renames.
verbose: bool, optional
    Verbose module output
    Default: False
quiet: bool, optional
    Quiet module output
    Default: False
superquiet: bool, optional
    Very quiet module output
    Default: False

DESCRIPTION

g.rename.many renames multiple maps at once using g.rename module. Old and new names are read from a text file. The file format is a simple CSV (comma separated values) format with no text delimiter (e.g. no quotes around cell content). Comma is a default cell delimiter but it can be changed to anything.

Possible use cases include:

  • renaming maps named in a certain language to English when data were obtained at national level but the futher collaboration is international
  • renaming provided sample maps with English names to a national language for educational purposes in case English is not appropriate
  • preparation of a GRASS GIS Standardized Sample Dataset which requires a certain set of standardized names

EXAMPLE

Renaming rasters

First prepare a file with names of raster maps to be renamed. The file can be prepared in spreadsheet application (and saved as CSV with cell delimiter comma and no text delimiter) or as a text file in any (plain) text editor. In any case, the result should be a plain text file with format and content similar to the following sample:

landuse96_28m,landuse
geology_30m,geology
soilsID,soils

Once the file is prepared, the module can be called:

g.rename.many raster=raster_names.csv

This example worked only with raster maps. However multiple files, one for each map type, can be used at once.

Creating a file with current names

A template for renaming can be prepared using g.list module, for example in command line (bash syntax):

g.list type=raster mapset=. sep=",
" > raster_names.csv

Note that we are using only maps in a current Mapset because these are the only ones we can rename.

With some further processing file template can be made more complete by including map names twice (bash syntax):

g.list type=raster mapset=. | sed -e "s/\(.*\)/\1,\1/g" > raster_names.csv

The sed expression used here takes whatever is on a line on input and puts it twice on one line on the output separated by comma.

SEE ALSO

g.rename, g.list

AUTHOR

Vaclav Petras, NCSU OSGeoREL

SOURCE CODE

Available at: g.rename.many source code (history)
Latest change: Thursday Mar 20 21:36:57 2025 in commit 7286ecf