Database Related Modules¶
In this section, modules are listed which relate to GRASS GIS databases. The modules listed below can create databases and mapsets.
The modules work with GRASS GIS versions ['grass70', 'grass71', 'grass72', 'grass73', 'grass74']
.
However, this can easily be extended. To extend the versions, add new GRASS GIS versions to self.candidates
in
gscpy.g_db.g_c_database
.
The name of the modules was chosen to ensure conformity with the GRASS GIS conventions. The addition c was added to
module gscpy.g_db.g_c_mapset
to signalize that the already existing module g.mapset
is passed with the flag
-c
(create).
-
class
gscpy.g_db.g_database.
Database
(db_dir, db_name, t_srs=None, t_srs_file=None, launch=False)[source]¶ Create a GRASS GIS Database.
Create a new location, including it’s default PERMANENT mapset, with or without entering the new location.
Parameters: - db_dir (str) – Location of GRASS GIS database
- db_name (str) – Name of the database.
- t_srs (int, optional) – A EPSG Code for georeferencing purposes.
- t_srs_file (str, optional) – If t_srs is not used, a georeferenced file can be here uploaded.
- launch (bool, optional) – If True, GRASS GIS will start with the new created mapset.
-
db_dir
¶ str
-
db_name
¶ str
-
t_srs
¶ str or NoneType
-
t_srs_file
¶ str or NoneType
-
launch
¶ bool
Examples
The general usage is
$ g.database [-l] db_dir=string db_name=string [t_srs=integer] [t_srs_file=string] [--verbose] [--quiet]
Create a new location, including it’s default PERMANENT mapset, without entering the new location using a EPSG code:
$ g.database db_dir=/home/user/grassdata db_name=germany t_srs=32630
Create a new location, including it’s default PERMANENT mapset, without entering the new location using a georeferenced raster file:
$ g.database db_dir=/home/user/grassdata db_name=germany t_srs_file=myFile.tiff
Create new mapset within the new location and launch GRASS GIS within that mapset
$ g.database -l db_dir=/home/user/grassdata db_name=germany t_srs=32630
Notes
It is mandatory that t_srs OR t_srs_file is set.
This class trys to find [‘grass70’, ‘grass71’, ‘grass72’, ‘grass73’, ‘grass74’] commands. This list can easily be extended for other versions of GRASS GIS.
- Flags:
- l : Launch mapset with GRASS GIS.
-
create_database
()[source] Create a GRASS GIS Database.
Returns: Return type: None
-
class
gscpy.g_db.g_c_mapset.
Mapset
(mapset, dbase=None, location=None)[source]¶ Create a mapset in a GRASS GIS Database if it is not existent. This will changes the current working MAPSET, LOCATION, or GISDBASE. This is a fairly radical action to run mid-session, take care when running the GUI at the same time.
In GRASS GIS there is a similar function (g.mapset). This function shortens the flags and creates directly a new mapset if it is not existent.
Parameters: - mapset (str, optional) – Name of mapset.
- dbase (str, optional) – Location of GRASS GIS database
- mapset – Name of the mapset that will be created.
-
mapset
¶ str
-
dbase
¶ str
-
location
¶ str
Examples
The general usage is
$ g.c.mapset [] mapset=string [dbase=string] [location=string] [--verbose] [--quiet]
Creation of a mapset within a GRASS GIS session
$ g.c.mapset mapset=Goettingen
Creation of a mapset within another GRASS GIS database
$ g.c.mapset mapset=Goettingen dbase=/home/user/grassdata/germany
By default, the shell continues to use the history for the old mapset. To change this behaviour the history can be switched to record in the new mapset’s history file as follows:
$ g.c.mapset mapset=Goettingen history -w history -r /"$GISDBASE/$LOCATION/$MAPSET"/.bash_history HISTFILE=/"$GISDBASE/$LOCATION/$MAPSET"/.bash_history
Notes
By default, the shell continues to use the history for the old mapset. To change this behaviour the history look at the examples.
-
create_mapset
()[source] Create a mapset in a GRASS GIS Database if it is not existent.
Returns: Return type: None