Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual: conversion of all HTML manual pages to markdown #4865

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
107 changes: 107 additions & 0 deletions db/databaseintro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
### Attribute management in general

GRASS can be linked to one or many database management systems (DBMS).
The *db.\** set of commands provides basic SQL support for attribute
management, while the *v.db.\** set of commands operates on the vector
map (see [Vector introduction](vectorintro.md)).

### Available drivers

Available drivers are listed in [SQL support in GRASS GIS](sql.md).

**Notes**:
The DBF driver provides only very limited SQL support (as DBF is not an
SQL DB) while the other DBMS backends (such as SQLite, PostgreSQL, MySQL
etc) provide full SQL support since the SQL commands are sent directly
to the DBMS. For this reason, the SQLite driver is the default DBMI
backend.

### DB connection management

The current database management settings are shown or modified with
[db.connect](db.connect.md) for current mapset. Available DBMI drivers
are listed with [db.drivers](db.drivers.md). Some DBMI backends require
a user/password for driver/database to be set with
[db.login](db.login.md). In order to test a driver, run
[db.test](db.test.md).

### Attribute data import and export

Attribute data can be imported with [db.in.ogr](db.in.ogr.md) from
various formats and exported with [db.out.ogr](db.out.ogr.md). To
internally copy a a full table or selectively parts of it, use
[db.copy](db.copy.md).

Further conversion tools:

- [MDB Tools](https://github.com/mdbtools/mdbtools): Convert MS-Access
data to SQL, DBF, etc.
- [Using OpenOffice.org with SQL
Databases](https://grasswiki.osgeo.org/wiki/Openoffice.org_with_SQL_Databases)

### SQL commands

GRASS supports two main SQL operations, execution of an SQL statement
([db.execute](db.execute.md)) and selection of data from a table
([db.select](db.select.md)). See the [SQL help page](sql.md) for
examples.

### Managing the default DBMI settings

Per default vector map attributes are stored in SQLite tables. This
default definition can be modified with [db.connect](db.connect.md). If
an external DBMS is used, [db.login](db.login.md) may be required.

### Creating a database

Specific commands are explained on the individual driver pages (these
pages are only available if driver was compiled in this installation):

- DBF: see [DBF](grass-dbf.md) page
- SQLite: [SQLite](grass-sqlite.md) page
- mySQL: [mySQL](grass-mysql.md) and [meSQL](grass-mesql.md) pages
- ODBC: [ODBC](grass-odbc.md) page (connect to Oracle, etc.)
- PostgreSQL: [PostgreSQL](grass-pg.md) and PostGIS page

### Metadata

All columns for a given table are listed with
[db.columns](db.columns.md). The command [db.describe](db.describe.md)
describes a table in detail. To list all available tables for a given
database, run [db.tables](db.tables.md).

### Table maintenance

To drop a column from a selected attribute table, use
[db.dropcolumn](db.dropcolumn.md). With [db.droptable](db.droptable.md)
an attribute table can be deleted.

### Database Schema

Currently schema support only works for PostgreSQL connections. Default
schema can be set with [db.connect](db.connect.md). Note that the
default schema will be used by all db.\* modules.

[db.tables](db.tables.md) returns 'schema.table' if schemas are
available in the database.

### Migrating to a different database engine

To migrate a GRASS database table (or a GRASS vector map) to a different
DBMI engine, the best solution is to create a new MAPSET, define the
DBMI settings accordingly with [db.connect](db.connect.md) and if
needed, [db.login](db.login.md). Then the table of interest can be
copied over with [db.copy](db.copy.md) from the original MAPSET.
Likewise, a vector map including its table(s) are copied from the
original MAPSET to the current MAPSET with [g.copy](g.copy.md).

### See also

- [Introduction into raster data processing](rasterintro.md)
- [Introduction into 3D raster data (voxel)
processing](raster3dintro.md)
- [Introduction into vector data processing](vectorintro.md)
- [Introduction into image processing](imageryintro.md)
- [Introduction into temporal data processing](temporalintro.md)
- [Projections and spatial transformations](projectionintro.md)
- [Graphical User Interface](wxguiintro.md)
52 changes: 52 additions & 0 deletions db/db.columns/db.columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## DESCRIPTION

*db.columns* lists all columns for a give table. Connection to databases
are supported through dbf, shp, odbc and pg drivers.

## NOTE

If parameters for database connection are already set with
[db.connect](db.connect.md), they are taken as default values and do not
need to be spcified each time.

## EXAMPLES

### List columns of a PostgreSQL attribute table

```shell
db.columns table=zipcodes_wake driver=pg database=grassdb
```

*If the database parameters are already set, the columns can be listed
directly*

```shell
db.columns table=zipcodes_wake
```

### List columns from Shape file with DBF attribute table

```shell
db.columns table=zipcodes_wake driver=dbf database=/grassdata/nc_spm_08/PERMANENT/dbf/
```

### List columns of table in SQLite database

Note that the SQLite backend is the default setting.

```shell
db.columns driver=sqlite table=archsites database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
```

## SEE ALSO

*[db.connect](db.connect.md), [db.describe](db.describe.md),
[db.drivers](db.drivers.md), [db.droptable](db.droptable.md),
[db.execute](db.execute.md), [db.login](db.login.md),
[db.tables](db.tables.md), [GRASS SQL interface](sql.md)*

[GRASS SQL interface](sql.md)

## AUTHOR

Radim Blazek, ITC-Irst, Trento, Italy
136 changes: 136 additions & 0 deletions db/db.connect/db.connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
## DESCRIPTION

*db.connect* allows the user to set database connection parameters.
These parameters are then taken as default values by modules so that the
user does not need to enter the parameters each time.

The default database backend in GRASS GIS is [SQLite](grass-sqlite.md)
(since version 7).

## NOTES

Values are stored in the mapset's `VAR` file; the connection is not
tested for validity.

The **-p** flag will display the current connection parameters.

The **-c** flag will silently check if the connection parameters have
been set, and if not will set them to use GRASS's default values.
(useful in scripts before you attempt to create a new database table)

To connect a vector map to a database table, use
*[v.db.connect](v.db.connect.md)* or
*[v.db.addtable](v.db.addtable.md)*.

## EXAMPLES

### SQLite (default backend)

Local storage:

```shell
db.connect -d
db.connect -p
db.tables -p
```

The SQLite database file is created automatically when used the first
time.

See [SQLite](grass-sqlite.md) database driver for details.

### PostgreSQL (local connection)

Local storage, database tables stored in database "mydb" (may require
the use of *[db.login](db.login.md)*):

```shell
db.connect driver=pg database=mydb
db.login user=myname pass=secret
db.connect -p
db.tables -p
```

See [PostgreSQL](grass-pg.md) database driver for details.

### PostgreSQL (network connection)

Network storage, database tables stored in database "mydb" (may require
the use of *[db.login](db.login.md)*):

```shell
db.connect driver=pg database=mydb
db.login user=myname pass=secret host=myserver.com port=6666
db.connect -p
db.tables -p
```

See [PostgreSQL](grass-pg.md) database driver for details.

### MySQL (local connection)

Local storage, database tables stored in database "mydb" (may require
the use of *[db.login](db.login.md)*):

```shell
db.connect driver=mysql database=mydb
db.login user=myname pass=secret
db.connect -p
db.tables -p
```

See [MySQL](grass-mysql.md) database driver for details.

### MySQL (network connection)

Network storage, database tables stored in database "mydb" (may require
the use of *[db.login](db.login.md)*):

```shell
db.connect driver=mysql database=mydb
db.login user=myname pass=secret host=myserver.com
db.connect -p
db.tables -p
```

See [MySQL](grass-mysql.md) database driver for details.

### ODBC

Network storage, database tables stored in database "mydb" (may require
the use of *[db.login](db.login.md)*):

```shell
db.connect driver=odbc database=mydb
db.login user=myname pass=secret
db.connect -p
db.tables -p
```

See [ODBC](grass-odbc.md) database driver for details.

### DBF (local, not recommended)

Local storage (the dbf/ subdirectory in the mapset must exist or must be
created by the user):

```shell
db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
db.tables -p
```

See [DBF](grass-dbf.md) database driver for details.

## SEE ALSO

*[db.columns](db.columns.md), [db.copy](db.copy.md),
[db.drivers](db.drivers.md), [db.login](db.login.md),
[db.tables](db.tables.md), [v.db.addtable](v.db.addtable.md),
[v.db.connect](v.db.connect.md)*

[GRASS SQL interface](sql.md)

## AUTHORS

Main author: Radim Blazek, ITC-Irst, Trento, Italy
GRASS 7 improvements: Martin Landa, Markus Metz
72 changes: 72 additions & 0 deletions db/db.copy/db.copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## DESCRIPTION

*db.copy* allows the user to copy a table between two databases.
Databases can be connected through different drivers (see examples
below).

## NOTES

Attribute tables can be copied using *db.copy* and, when to be
associated to a vector map, assigned to the map with
*[v.db.connect](v.db.connect.md)*. Current connection settings are saved
in the file *\$LOCATION/vector_map/dbln*.

## EXAMPLES

### From DBF to PostgreSQL

*Storing table 'geonames.dbf' (in current directory) into PostgreSQL
through ODBC:*

```shell
db.copy from_driver=dbf from_database='$GISDBASE/$LOCATION_NAME/PERMANENT/dbf' \
from_table=geonames to_driver=pg to_database="host=pgserver,dbname=testdb" \
to_table=geonames
```

### From PostgreSQL to DBF

```shell
db.copy from_driver=pg from_database="host=pgserver.example.org,dbname=testdb" \
from_table=origtable to_driver=dbf \
to_database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf' to_table=origtable
```

### From PostgreSQL to PostgreSQL with condition

```shell
db.copy from_driver=pg from_database="host=localhost,dbname=testdb" \
from_table=geonames to_driver=pg to_database="host=localhost,dbname=testdb" \
to_table=selection where="cat < 500"
```

### From DBF to SQLite

```shell
db.copy from_driver=dbf from_database='$GISDBASE/$LOCATION_NAME/PERMANENT/dbf' \
from_table=geonames_features to_driver=sqlite \
to_database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db' to_table=geonames_features

# convenient viewer:
sqlitebrowser $HOME/grassdata/nc_spm_08/user1/sqlite/sqlite.db
```

### From SQLite to DBF

```shell
db.copy from_driver=sqlite from_database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db' \
from_table=ammprv to_driver=dbf to_database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/' \
to_table=ammprv
```

## SEE ALSO

*[db.connect](db.connect.md), [db.drivers](db.drivers.md),
[db.login](db.login.md), [v.db.connect](v.db.connect.md),
[v.clean](v.clean.md)*

[GRASS SQL interface](sql.md)

## AUTHOR

Radim Blazek, ITC-irst, Trento, Italy
Loading
Loading