If you find this document usefull, please consider ordering a printed hardcopy!
Attribute management has completely changed in GRASS 6.0. The 'dig_cats/' structure in GRASS version 5.4longer exists. All attributes are now saved in database tables and are linked with the geometries via a DBMI (Database Management Interface). The following DBMI drivers are presently available:
The connection of a vectormap with an attribute table is GRASS-internally defined in a 'dbln' file. This is an ASCII file, which is saved in the vectormap folder. The file is generated when a map is imported into GRASS. If a table is supposed to be created later, another link should be added to the file using the module v.db.connect. The current connection of a map can be verified by the command v.db.connect -p vector map.
The command v.db.connect makes the connection between a vectormap and an attribute table possible - each table is thereby connected through different layer entries:
v.db.connect map=vectormap table=attribute1 layer=2 v.db.connect map=vectormap table=attribute2 layer=3 v.db.connect -p vectormap
An example application is described in chapter 11.2.2.
Note:
In this case it is absolutely important to note that during the deletion
of the vectormap all attribute tables, which are indicated in the
'dbln' and therefore linked with this map are deleted. In order to
avoid this it one can make a copy of the respective
attribute table and link the copy to the vectormap instead of
the 'original'.
db.copy from_driver=dbf from_table=origtable to_driver=dbf \ to_table=copytable
For changing the current settings of a database the following commands are available:
The db.* modules are completely independent from the v.* modules in GRASS and do only allow the modification of attribute tables. The dbf format is used as default. This can be set with the following command:
db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
User/password management with external databases
For attribute-data storage in external databases like PostgreSQL, user management is also possible. The module db.login takes control about a database and store its information in $HOME/.grasslogin6.
So working in groups is possible. A possible scenario can be as follows:
Location -> database Mapset -> database-scheme UNIX-User -> database-user UNIX-Group -> database-groupNow it is possible to grant certain permissions to groups corresponding to mapsets and location. Inside GRASS the module g.access is available.
Please keep in mind, that Unix- and database-users must be synchronized manually. This is important when removing a Unix-user. The corresponding database-user needs to be removed manually by the administrator as well.
The module v.db.select provides a basic report of vector-attributes inside the console. All attributes will be printed separated by defined field separator.
# Print attributes of vector-map roads v.db.select map=roads fs="|" cat|label 0|no data 1|interstate 2|primary highway, hard surface 3|secondary highway, hard surface 4|light-duty road, improved surface 5|unimproved road
The module v.to.db allows the addition of helpful attributes to the vector objects. These are:
However, an additional column (in the case of point coordinates two columns) must be added to the attribute table. This can be done using software such as OpenOffice or directly in GRASS:
# create additional integer-column (in dBASE format): echo "ALTER TABLE <vectormap> ADD COLUMN <column> integer" | db.execute # Add vector length: v.to.db map=<vectormap> option=length units=meters col1=<column> # Query for verification: echo "SELECT * FROM <vectormap>" | db.select
GRASS also offers the possibility of manipulating vector attributes. Attributes can be updated according to different query criteria via the SQL command 'UPDATE':
# update column area larger than 200: echo "UPDATE <table> SET attribute1 = 2 WHERE area > 200"| db.execute
If PostgreSQL is used as attribute storage, more SQL-commands are available via the commandline-tool psql which comes with the postgres-distribution.
It offers the possibility to update entries based on calculating results. The above examples could be changed to the following:
# update column area larger than 200
# based on calculations:
echo "UPDATE <table> SET area = (area*1000) WHERE \
area > 200"| psql -d <PG-database>
Manipulating vector attributes interactively is also possible. The vector file is opened and queried by the module d.what.vect. The attributes are displayed in a separate popup-window where they can be selected using the mouse and subsequently edited.
The newly designed GRASS plugin in the geodata viewer QGIS (19) provides yet another means for changing GRASS vector file attributes. A short description of this software package can be found in chapter 18.
If you find this document usefull, please consider ordering a printed hardcopy!