GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-761b3a08c9
file_name.c File Reference

GIS library - Determine GRASS data base file name. More...

#include <string.h>
#include <stdlib.h>
#include <grass/gis.h>
#include "gis_local_proto.h"
Include dependency graph for file_name.c:

Go to the source code of this file.

Functions

char * G_file_name (char *path, const char *element, const char *name, const char *mapset)
 Builds full path names to GIS data files. More...
 
char * G_file_name_misc (char *path, const char *dir, const char *element, const char *name, const char *mapset)
 Builds full path names to GIS misc data files. More...
 
char * G_file_name_tmp (char *path, const char *element, const char *name, const char *mapset)
 Builds full path names to GIS data files in temporary directory (for internal use only) More...
 
char * G_file_name_basedir (char *path, const char *element, const char *name, const char *mapset, const char *basedir)
 Builds full path names to GIS data files in temporary directory (for internal use only) More...
 

Detailed Description

GIS library - Determine GRASS data base file name.

(C) 2001-2015 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL

Definition in file file_name.c.

Function Documentation

◆ G_file_name()

char* G_file_name ( char *  path,
const char *  element,
const char *  name,
const char *  mapset 
)

Builds full path names to GIS data files.

If name is of the form "nnn@ppp" then path is set as if name had been "nnn" and mapset had been "ppp" (mapset parameter itself is ignored in this case).

Paths to files are currently in form: /path/to/location/mapset/element/name

path input buffer memory must be allocated by caller.

C:

G_file_name(path, "fcell", "my_raster", "my_mapset");
// path now is "/full/path/to/my_mapset/fcell/my_raster"
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
Definition: file_name.c:61
#define GPATH_MAX
Definition: gis.h:194
Definition: path.h:15

Python:

import ctypes
from grass.pygrass.utils import decode
from grass.lib.gis import G_file_name, GPATH_MAX
path = ctypes.create_string_buffer(GPATH_MAX)
path_str = decode(G_file_name(path, "elem", "name", "mapset"))
print(path_str)
>>> /full/path/to/mapset/elem/name
Parameters
[out]pathallocated buffer to hold resultant full path to file
elementdatabase element (eg, "cell", "cellhd", "vector", etc)
namename of file to build path to (fully qualified names allowed)
mapsetmapset name
Returns
pointer to path buffer

Definition at line 61 of file file_name.c.

Referenced by G_get_projepsg(), G_get_projinfo(), G_get_projunits(), G_has_vector_timestamp(), G_make_mapset_element(), G_mapset_permissions(), G_myname(), G_rename(), G_write_projsrid(), G_write_projwkt(), list_subgroups(), M__empty(), M_do_copy(), main(), Rast_map_is_fp(), Rast_map_type(), V1_close_nat(), Vect__get_element_path(), and Vect_copy().

◆ G_file_name_basedir()

char* G_file_name_basedir ( char *  path,
const char *  element,
const char *  name,
const char *  mapset,
const char *  basedir 
)

Builds full path names to GIS data files in temporary directory (for internal use only)

By default the GRASS temporary directory is located at $LOCATION/$MAPSET/.tmp/$HOSTNAME/. If basedir is provided, the temporary directory is located at <basedir>/.tmp/$HOSTNAME/.

Parameters
[out]pathbuffer to hold resultant full path to file
elementdatabase element (eg, "cell", "cellhd", "vector", etc)
namename of file to build path to (fully qualified names allowed)
mapsetmapset name
Returns
pointer to path buffer

Definition at line 154 of file file_name.c.

◆ G_file_name_misc()

char* G_file_name_misc ( char *  path,
const char *  dir,
const char *  element,
const char *  name,
const char *  mapset 
)

Builds full path names to GIS misc data files.

Paths to misc files are currently in form: /path/to/location/mapset/dir/name/element

path input buffer memory must be allocated by caller.

C:

G_file_name_misc(path, "cell_misc", "history", "my_raster", "my_mapset");
// path now contains "/full/path/to/my_mapset/cell_misc/my_raster/history"
char * G_file_name_misc(char *, const char *, const char *, const char *, const char *)
Builds full path names to GIS misc data files.
Definition: file_name.c:101

Python:

import ctypes
from grass.pygrass.utils import decode
from grass.lib.gis import G_file_name_misc, GPATH_MAX
path = ctypes.create_string_buffer(GPATH_MAX)
path_str = decode(G_file_name_misc(path, "dir", "elem", "name", "mapset"))
print(path_str)
>>> /full/path/to/mapset/dir/name/elem
Parameters
[out]pathallocated buffer to hold resultant full path to file
dirmisc directory (e.g., "cell_misc", "group")
elementdatabase element (in this case – file to build path to e.g., "history", "REF")
namename of object (raster, group; fully qualified names allowed e.g., "my_raster@PERMANENT")
mapsetmapset name
Returns
pointer to path buffer

Definition at line 101 of file file_name.c.

Referenced by Rast3d_filename(), Rast__check_fp_type(), and Rast__close_null().

◆ G_file_name_tmp()

char* G_file_name_tmp ( char *  path,
const char *  element,
const char *  name,
const char *  mapset 
)

Builds full path names to GIS data files in temporary directory (for internal use only)

By default temporary directory is located $LOCATION/$MAPSET/.tmp/$HOSTNAME. If GRASS_VECTOR_TMPDIR_MAPSET is set to "0", the temporary directory is located in TMPDIR (environmental variable defined by the user or GRASS initialization script if not given). Note that GRASS_VECTOR_TMPDIR_MAPSET variable is currently used only by vector library.

Parameters
[out]pathbuffer to hold resultant full path to file
elementdatabase element (eg, "cell", "cellhd", "vector", etc)
namename of file to build path to (fully qualified names allowed)
mapsetmapset name
Returns
pointer to path buffer

Definition at line 125 of file file_name.c.

References NULL.

Referenced by G_make_mapset_element_tmp(), and Vect__get_element_path().