[GRASSweb-list]markus: web/grass51/tutorial 51attributes.jpg,NONE,1.1 51vectorarch.jpg,NONE,1.1 attrib_storage.html,NONE,1.1 examples.html,NONE,1.1 geom_storage.html,NONE,1.1 index.html,NONE,1.1

grass at intevation.de grass at intevation.de
Mon Dec 23 04:03:52 EST 2002


Author: markus

Update of /grassrepository/web/grass51/tutorial
In directory doto:/tmp/cvs-serv24670

Added Files:
	51attributes.jpg 51vectorarch.jpg attrib_storage.html 
	examples.html geom_storage.html index.html 
Log Message:
moved extended tutorial into subdir

--- NEW FILE: 51attributes.jpg ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: 51vectorarch.jpg ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: attrib_storage.html ---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <DEFANGED_meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <DEFANGED_meta name="Author" content="Markus Neteler">
   <DEFANGED_link rel="stylesheet" type="text/css" href="../../sitestyle.css">
   <title>GRASS 5.1: Attribute management with connections to DBMS</title>
</head>
<body>

<!-- HEADER -->
<table width=100%><tr><td width=80>
<A HREF="index.html">
<DEFANGED_IMG src="../../images/grass.smlogo.gif" alt="HOME" border="0" align=middle></A>
</td><td><H1>
GRASS 5.1: Attribute management with connections to DBMS
</H1></td></tr></table>
<!-- END OF HEADER -->

<hr>
<a href="index.html">Tutorial HOME</a> |
<a href="geom_storage.html">Geometry management</a> |
<a href="attrib_storage.html">Attribute management</a> |
<a href="examples.html">Usage Examples</a>
<hr>

<i><b>README:</b>
GRASS 5.1 is currently under development. It is neither complete (it still
contains only a few modules) nor it is intended to productional usage. 
Development releases are provided for people who want to help test, debug,
and improve GRASS 5.1. Knowing this, please read on.</i><br>
<i>
These examples described here may work or not. You are kindly invited to
send us further examples and/or code bugfixes/enhancements.</i>
<P>

<h2>Introduction</h2>
The attribute management was completely changed in GRASS 5.1 to achieve
multi-attribute capabilities managed within external databases. The former
dig_cats/ files are not used any more and all vector attributes are stored
in external database. Connection with database is done through DBMI library
(DataBase Management Interface) with its integrated drivers. At time of this
writing following DBMI drivers for attribute storage are available: 

<ul>
<li>DBF file
<li>ODBC connected RDBMS (e.g. Oracle, mySQL, PostgreSQL etc)
<li>PostgreSQL database
<li>mySQL database
</ul>

The connection of a vector map to an attribute table is defined in the
<tt>DB</tt> file. This file is currently a text file (ASCII) and must
be created in the MAPSET subdirectory. Each line in the DB file refers
to a map. Wildcards and inheritance from previous lines is implemented.
See some <tt>DB</tt> file details <a href="http://freegis.org/cgi-bin/viewcvs.cgi/~checkout~/grass51/doc/vector/vector.html#attr">here</a>.

<center>
<DEFANGED_IMG src="51attributes.jpg" alt="GRASS 5.1 attributes model">
</center>

Each vector element may have none, one or more categories (cats). More cats
are distinguished by field number (field). Records in a vector attribute
table are linked to vector entities by field and category number. The field
number identifies a database table and the category number identifies the
table record. I.e. for unique combination <tt>mapset + map + field +
category</tt> exists one unique combination <tt>driver + database + table +
row</tt>.

When a definition defines more fields for one map i.e. in one
map the same vector features are linked to several attribute tables. <p>

For each pair <tt>map + field</tt> must be defined table, key column,
database, driver. This definition must be written to <tt>$MAPSET/DB</tt>
text file. Each row in DB file contains names separated by spaces in
following order ([] - optional):

<pre>
map[@mapset] field table [key [database [driver]]] 
</pre>

If key, database or driver are omited (on second and higher row only) last
definition is used. Definition from DB file in other mapset may be
overwritten by definition in current mapset if mapset is specified with map
name.
<p>

Wild cards * and ? may be used in map and mapset names.  Variables
$GISDBASE, $LOCATION, $MAPSET, $MAP, $FIELD may be used in table, key,
database and driver names. Note that $MAPSET is not current mapset but
mapset of the map the rule is defined for.

<hr>
<ol>
<li><a href="#DBF">Attributes stored in DBF table</a>
<li><a href="#ODBC">Attributes stored in external database (PostgreSQL)
        connected through ODBC</a>
<li><a href="#PostgreSQL">Attributes stored in external database (PostgreSQL)
        directly connected</a>
<li><a href="#mySQL">Attributes stored in external database (mySQL)
        directly connected</a>
<li><a href="#StarOffice">Changing table column types with StarOffice</a>
<li><a href="#OpenOffice">Changing table column types with OpenOffice</a>
</ol>

To get debug information, set variable (set to 0 for debug silence) to 1..5:<div class="code"><pre>
export GRASS_DEBUG_LEVEL=5
</div></pre>


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="DBF"></a>
Attributes stored in DBF file
</b></big></font></td></tr></table>

Example: Connection of SHAPE file with attributes in DBF file.<p>

An entry in the GRASS 5.1 'DB' file such as:
<div class="code"><pre>
markveggy.shp 1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/shp dbf
</div></pre>
is required.
<p>
You can check the connection of a vector map to a table:

<div class="code"><pre>
v.db.connect markveggy.shp
</div></pre>

which should print the database connection to DBF file.
<P>
For the <tt>db.*</tt> commands, connect GRASS 5.1 to the table:
<div class="code"><pre>
db.connect driver=dbf database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp
db.tables -p
</div></pre>

Now the table name 'markveggy' should be printed which is the DBF file.


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="ODBC"></a>
Attributes stored in external database (PostgreSQL) connected
through ODBC
</b></big></font></td></tr></table>

Possible communication between GRASS 5.1 and PostgreSQL database for
    attribute management (ODBC can connect to other RDBMS as well): <p>

<table cellpadding="2" cellspacing="2" border="1" align="center">
  <tbody>
    <tr>
      <td valign="top" align="center" bgcolor="#99ff99">GRASS module &lt;-&gt;&nbsp;
   DBMI &lt;-&gt; ODBCdriver</td>
      <td valign="top" align="center" bgcolor="#99ff99">&lt;-&gt;</td>
      <td valign="top" align="center" bgcolor="#99ff99">unixODBC</td>
      <td valign="top" align="center" bgcolor="#99ff99">&lt;--&gt;</td>
      <td valign="top" align="center" bgcolor="#99ff99">ODBC-to-RDBMS-driver
   &lt;-&gt; RDBMS Database</td>
    </tr>
    <tr>
      <td valign="top" align="center"><i><b>GRASS<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>&lt;-&gt;<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>Interface<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>&lt;-&gt;<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>PostgreSQL<br>
      </b></i></td>
    </tr>
    <tr>
      <td valign="top" align="center"><i><b>GRASS<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>&lt;-&gt;<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>Interface<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>&lt;-&gt;<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>Oracle<br>
      </b></i></td>
    </tr>
    <tr>
      <td valign="top" align="center"><i><b>GRASS<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>&lt;-&gt;<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>Interface<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>&lt;-&gt;<br>
      </b></i></td>
      <td valign="top" align="center"><i><b>...<br>
      </b></i></td>
    </tr>
  </tbody>
</table>
<p>

Example: Connection of SHAPE file with attributes in PostgreSQL table which
get's connected through ODBC to GRASS 5.1. The name of the PostgreSQL
database is 'grass51test' which contains the imported DBF file as table
'markveggy'.
<p>

Some steps are required:
<ul>
<li>
Configure ODBC driver for selected database (manually or with 'ODBCConfig').
ODBC drivers are defined in /etc/odbcinst.ini. Here is example:</li>

<div class="code"><pre>&nbsp;[PostgreSQL]
&nbsp;Description&nbsp;&nbsp;&nbsp;&nbsp; = ODBC for PostgreSQL
&nbsp;Driver&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /usr/lib/libodbcpsql.so
&nbsp;Setup&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /usr/lib/libodbcpsqlS.so
&nbsp;FileUsage&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1</div></pre>

<li> Create DSN (data source name). The DSN is used as database name in db.*
modules. Then DSN must be defined in $HOME/.odbc.ini (for this user only) or in
/etc/odbc.ini for (for all users) [watch out for the database name which
appears twice and also for the PostgreSQL protocol version]. Omit blanks at
the beginning of lines:</li>

<div class="code"><pre>&nbsp;[grass51test]
&nbsp;Description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = PostgreSQL
&nbsp;Driver&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = PostgreSQL
&nbsp;Trace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = No
&nbsp;TraceFile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;Database&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = grass51test
&nbsp;Servername&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = localhost
&nbsp;UserName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = neteler
&nbsp;Password&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;Port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 5432
&nbsp;Protocol&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 7.0.3
&nbsp;ReadOnly&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = No
&nbsp;RowVersioning&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = No
&nbsp;ShowSystemTables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = No
&nbsp;ShowOidColumn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = No
&nbsp;FakeOidIndex&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = No
&nbsp;ConnSettings&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =</div></pre>

Configuration of an DSN without GUI is described on <a href="http://www.unixodbc.org/odbcinst.html">http://www.unixodbc.org/odbcinst.html</a>,
but odbc.ini and .odbc.ini may be created by the 'ODBCConfig' tool. You can
easily&nbsp; view your DSN structure by 'DataManager'. Configuration with
GUI is described on <a href="http://www.unixodbc.org/doc/UserManual/">http://www.unixodbc.org/doc/UserManual/</a>
<p>
To find out about your PostgreSQL protocol, run <br>
<tt>cat /var/lib/pgsql/data/PG_VERSION</tt><br>
or <br>
<tt>psql -V</tt> 

<li>
Now create a new database if not yet existing ('-h host' defines the
        PostgreSQL server host if not localhost):
<div class="code"><pre>
createdb -h rastrel grass51test
</div></pre>

<li>Now store the table into PostgreSQL (you may use pg.in.dbf from 5.0 or other
tools).

<li>
Now run the 'db.connect' command:
<div class="code"><pre>
db.connect driver=odbc database=grass51test
</div></pre>

<li>Next we dump the DBF file into PostgreSQL (NOTE: unless we don't have a
            'db.copy' command, we may 'pg.in.dbf' from GRASS 5.0 or
            the external 'pg2xbase' software):
<div class="code"><pre>
#go to directory, where registered SHAPE/DBF files are:
cd `g.gisenv GISDBASE`
cd `g.gisenv LOCATION_NAME`
cd shp

pg.in.dbf in=markveggy.dbf dumpmode=normal 
</div></pre>


<li> Next add an entry in the GRASS 5.1 'DB' file:
<div class="code"><pre>
markveggy.shp 1 markveggy VEGCNP_ID grass51test odbc
</div></pre>

<li>
Finally a test: Here we should see the table columns (if the ODBC
              connection works):
<div class="code"><pre>
db.tables -p
db.columns table=markveggy
</div></pre>
Now the table name 'markveggy' should be printed which is the PostgreSQL table.
<P>
Doesn't work? Check with 'isql &lt;databasename&gt;' if the ODBC-PostgreSQL
connection is really established.
</ul>

Note that you can also connect mySQL, Oracle etc. through ODBC to GRASS 5.1.

You can also check the vector map itself concerning a current link to a
table:

<div class="code"><pre>
v.db.connect markveggy.shp
</div></pre>

which should print the database connection through ODBC to the defined RDBMS.

<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="PostgreSQL"></a>
Attributes stored in PostgreSQL database table
directly connected
</b></big></font></td></tr></table>

Example: Connection of SHAPE file with attributes in PostgreSQL database table
directly connected to GRASS 5.1.<p>

If not yet done, create a new database if not yet existing ('-h host'
defines the PostgreSQL server host if not localhost):

<div class="code"><pre>
createdb -h rastrel grass51test
</div></pre>

Now store the table into PostgreSQL (you may use pg.in.dbf from 5.0 or other
tools).
<p>
Add entry in the GRASS 5.1 'DB' file in the mapset directory:
<div class="code"><pre>
markveggy.shp 1 markveggy VEGCNP_ID grass51test pg
</div></pre>

Connect GRASS 5.1 to the table:
<div class="code"><pre>
db.connect driver=pg database=grass51test
db.tables -p
db.describe -c markveggy
</div></pre>

This should print name and columns of the table 'markveggy' which is stored
as PostgreSQL table.

<P>
Doesn't work? Check with 'psql -l' if the PostgreSQL
connection is really established.

You can also check the vector map itself concerning a current link to a
table:

<div class="code"><pre>
v.db.connect markveggy.shp
</div></pre>

which should print the database connection to PostgreSQL.

<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="mySQL"></a>
Attributes stored in mySQL database table
</b></big></font></td></tr></table>

Example: Connection of SHAPE file with attributes in mySQL database table
directly connected to GRASS 5.1.<p>

TODO.

<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="StarOffice"></a>
Changing table column types with StarOffice
</b></big></font></td></tr></table>

Sometimes the ID field in a database table (e.g. .dbf) is of a wrong type.
It must be converted to Integer (be sure that the ID values are in the range
of Integer, float IDs are not supported). To change the type of a table
column you can use StarOffice. Start it without parameters, then:

<div class="code"><pre>
File -> New -> Database
                 [Properties]
                   * Type -> dBase
                     Directory -> [Browse, select directory]
                   * Tables -> check if the table is visible
                     -> OK button
</div></pre>

Now you reach the Database tool which provides "Forms", "Reports", "Queries"
and "Tables". Select "Tables", then you should see your table as icon.<br>

To change column types, click with right mouse button onto the table icon to
change the "Properties". Then select the column and change the type to
"Number" (alias Integer). Save the table. Now GRASS 5.1 can use the ID
column as it is of Integer type.


<p><table width="100%" cellpadding="3" border="0"> <tr><td align="left"
bgcolor="#B0F0B0"><font color="#00000"><big><b> <a name="OpenOffice"></a>
Changing table column types with OpenOffice
</b></big></font></td></tr></table>

Sometimes the ID field in a database table (e.g. .dbf) is of a wrong type.
It must be converted to Integer (be sure that the ID values are in the range
of Integer, float IDs are not supported). To change the type of a table
column you can use OpenOffice. Start it without parameters, then:

<div class="code"><pre>
Tools -> Data Sources
            -> New Data Source
                  [General] 
                    * Database type: dBase
                    * Data source URL [Browser: ...]
                          -> select directory
                  [Tables] 
                    * check if the table is visible 
                          -> OK button
View -> Data
             * Sources
                     -> select your data source (probably "Data source 1")
             * Tables
                   * your table 
                        * click right mouse button on table
                             -> Edit table
</div></pre>

Select the column and change the type to "Number" (alias Integer). Save the
table. Now GRASS 5.1 can use the ID column as it is of Integer type.
<br>
PROBLEM: In OpenOffice 1.0.1 Number/Integer does not exist!!

<hr>
<b>Further Links:</b>

<ul>
<li><a href=http://postgis.refractions.net/>PostGIS with shp2pgsql</a>:<br>
          <tt>shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql</tt>
<li><a href=http://www.postgresql.org/>PostgreSQL</a> and 
    <a href=http://techdocs.postgresql.org/>PostgreSQL Technical
     Documentation</a>
<li><a href=http://www.klaban.torun.pl/prog/pg2xbase/>pg2xbase</a>
                  (DBF <-> PostgreSQL)
<li><a href=http://e00pg.sourceforge.net/>e002pg</a> (E00 to PostGIS
                  filter)
<li><a href=http://gdal.velocet.ca/projects/opengis/>ogrinfo and
                    ogr2ogr</a> (GIS vector format converter and
                  library, e.g. ArcInfo or SHAPE -> PostGIS)<br>
          <tt>ogr2ogr -f "PostgreSQL" shapefile ??</tt>

<li><a href=http://mdbtools.sourceforge.net/>mdbtools</a> (converts
                  MS-ACCESS data to SQL, DBF etc.)<br>
          <tt>gmdb dbfile.mdb</tt>
<li><a href=http://www.unixodbc.org/>unixODBC</a> to connect GRASS 5.1
                  to database servers such as PostgreSQL, Oracle etc.
</ul>

<!-- FOOTER -->
<p>
<hr>
<DIV ALIGN=right>&copy; 2002 Markus Neteler<br>
<a href="mailto:weblist at grass.itc.it">Comments</a> about this page | <a href="../../faq/index.html">FAQ</a> | <a href="../../download.html">Download</a> | <a href="../../support.html">Support</a> | <a href="../../gdp/index.html">Docs</a>  | <a href="../../grassdevel.html">Programming</a> | Back <a href=index.html>5.1 Tutorial Home</a><br>
<i>Last change:
$Date: 2002/12/23 09:03:49 $
</i></DIV>

</body>
</html>

--- NEW FILE: examples.html ---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <DEFANGED_meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <DEFANGED_meta name="Author" content="Markus Neteler">
   <DEFANGED_link rel="stylesheet" type="text/css" href="../../sitestyle.css">
   <title>GRASS 5.1 Usage examples</title>
</head>
<body>

<!-- HEADER -->
<table width=100%><tr><td width=80>
<A HREF="index.html">
<DEFANGED_IMG src="../../images/grass.smlogo.gif" alt="HOME" border="0" align=middle></A>
</td><td><H1>
GRASS 5.1 Usage Examples
</H1></td></tr></table>
<!-- END OF HEADER -->

<hr>
<a href="index.html">Tutorial HOME</a> |
<a href="geom_storage.html">Geometry management</a> |
<a href="attrib_storage.html">Attribute management</a> |
<a href="examples.html">Usage Examples</a>
<hr>

GRASS 5.1 is currently under development. It is neither complete (it still
contains only a few modules) nor it is intended to productional usage. 
Development releases are provided for people who want to help test, debug,
and improve GRASS 5.1. Knowing this, please read on.
<p>

<i><b>Disclaimer:</b> These examples described here may work or
        not. You are kindly invited to send us further examples and/or
        code bugfixes/enhancements.</i>
<P>

To get debug information, set variable (set to 0 for debug silence) to
      1..5:
<div class="code"><pre>
export GRASS_DEBUG_LEVEL=5
</div></pre>

<h2>Following modules are available at time of this writing</h2> (see
timestamp at bottom)

<ul>
<li>d.erase d.m d.mon d.path d.rast d.vect d.what.vect d.zoom
<li>db.columns db.createdb  db.describe db.dropdb    db.execute db.tables
    db.connect db.databases db.drivers db.droptable db.select
<li>g.gisenv   g.mapsets  g.region
<li>nviz
<li>v.build v.digit v.clean.test  v.in.ascii  v.rand.poly
    v.topo.check v.build.polylines v.convert v.info v.shape.register
    v.category v.db.connect v.digit v.out.ascii v.patch v.shape.unregister
    v.clean v.extract v.out.ogr v.surf.rst
<li>
If you start a module just by name, a related <a
                                         href=http://mpa.itc.it/radim/g51/d.vect-gui.jpg>GUI window pops up</a>.
<li>
d.m is a new <a href=http://mpa.itc.it/radim/g51/d.m.jpg>display manager</a>.
</ul>

<hr>
<ol>
<li><a href="#convert">Convert from/to GRASS 5.0 vector maps</a>
<li><a href="#geometry">Geometry storage in various formats</a>
<li><a href="#attributes">Attribute storage in (external) databases</a>
<li><a href="#geometry">Geometry stored in external database</a>
<li><a href="#v.extract">Example: Extract vector data from map to new map
   with SQL statements (PostGRASS)</a>
<li><a href="#ogr_export">Example: Vector map export data using OGR</a>
<li><a href="#SQL_queries">Example: SQL queries</a>
<li><a href="#shape_conversion">Example: Conversion of SHAPE map to GRASS
   5.1 vector map</a>
</ol>


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="convert"></a>
Convert from/to GRASS 5.0 vector maps
</b></big></font></td></tr></table>

<b>
Convert 5.0 vector maps to 5.1
</b><p>

You can run 5.1 (at the same time) on a 5.0 location without problems.<br>
To convert 5.0 vector data to 5.1, run:
<div class="code"><pre>
v.convert in=vectormap_from_50 out=vectormap
</div></pre>

Vector maps from 5.0 and 5.1 do not interfere (different directories),
so you can use the  same names.

<p><b>
Convert 5.1 vector map to GRASS 5.0
</b><p>

<div class="code"><pre>
v.out.ascii -o newmap.clean out=newmap.clean
</div></pre>

Then go to 5.0 and run v.in.ascii + v.support.

<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="geometry"></a>
Geometry storage in various formats
</b></big></font></td></tr></table>

There are various possibilities to store vector geometry in GRASS 5.1:

<ul>
<li>native format (default)
<li>SHAPE format
<li>PostGRASS format (using PostgreSQL/PostGIS)
<li>OGR supported formats (under development)
</ul>

Read on here about <a href=geom_storage.html>storing vector geometry in
GRASS 5.1</a>.


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="attributes"></a>
Attribute storage in (external) databases
</b></big></font></td></tr></table>

There are various possibilities to store attributes in GRASS 5.1:

<ul>
<li>DBF file
<li>ODBC connected RDBMS
<li>PostgreSQL database
<li>mySQL database
</ul>

Read on here about <a href=attrib_storage.html>storing attributes in
GRASS 5.1</a>.


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="v.extract"></a>
Example: Extract vector data from map to new map with SQL statements
</b></big></font></td></tr></table>

<div class="code"><pre>
#note: strings must be quoted:
v.extract markveggy.shp output=markveggy.1 where="VEGTYPE = 'PS'"

#selection with OR:
# Take care to use parenthesis on both sides of or ( otherwise the result m
# be bogus). Single clause of one comparison should also be enclosed in
# brackets standing on one of the sides of 'or' like in:
#     select * from tab where (c1 < 5) or (c2 >1)

v.extract markveggy.shp out=markveggy.1 new=1 where="(VEGTYPE = 'Wi') or (VEGTYPE = 'PS') or (PRIME_TYPE='Wi')"
#to use the new map, you should link attributes to it. This can
#be the table from the parent map. Edit the DB file and add a row for
#the new map (here: markveggy.1)
#Then check connection:
v.db.connect input=markveggy.1

#Query new map with attributes:
d.what.vect -a

#Or you can display with labels attached to the vector: First we check
# from which column labels to display:
db.columns tab=markveggy
d.vect markveggy.1 att=vegtype display=attr lcolor=red
</div></pre>

<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="ogr_export"></a>
Example: Vector map export data using OGR
</b></big></font></td></tr></table>

#Export of GRASS 5.1 vector map to SHAPE format (generates /tmp/testogr.shp
#and related files):

<div class="code"><pre>
v.out.ogr input=multi typ=line dsn=/tmp layer=testogr
</div></pre>
<p>

#Export to GML format (generates /tmp/testogr..gml file with layer 'testogr'):
<div class="code"><pre>
v.out.ogr input=multi typ=line dsn=/tmp/testogr.gml layer=testogr format=GML
</div></pre>


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="SQL_queries"></a>
Example: SQL queries
</b></big></font></td></tr></table>


<b>Example: we want to read attributes from a connected DBF table (see above
how to connect attribute tables):</b><p>

<div class="code"><pre>
#Select from table 'markveggy' (in database 'grass51test') all rows where 'VEGTYPE = "IFA"':
#NOTE: string attributes must be quoted:
echo "select VEGCNP_ID from markveggy where VEGTYPE = 'IFA'" | db.select -hc

#NOTE: for areas such selections only work when area centroids are present!
d.erase
d.vect markveggy.vegtype where="VEGTYPE = 'IFA'"
d.what.vect -a
</div></pre>

<b>Example: we want to read attributes from a PostgreSQL table connected through
ODBC  (see above how to connect attribute tables):</b><p>

<div class="code"><pre>
echo "select VEGCNP_ID from markveggy where VEGTYPE = 'IFA'" | db.select -hc

#NOTE: for areas such selections only work when area centroids are present!
d.erase
d.vect markveggy.vegtype where="VEGTYPE = 'Wiii'"
d.what.vect -a
</div></pre>

You see that it is the same! After connecting a GRASS 5.1 vector map, all
db.* modules work in the same way independent from the connected RDBMS.
<p>
Hints for GRASS-PostGIS: see e.g. <a
href="http://grass.itc.it/pipermail/grassuser/2002-November/015822.html">this
thread</a>.

<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="shape_conversion"></a>
Example: Conversion of SHAPE map to GRASS 5.1 vector map
</b></big></font></td></tr></table>

WARNING: don't try this at home. Still pretty unstable.

<div class="code"><pre>
v.out.ascii markveggy.shp out=test1
v.in.ascii test1 out=newmap
v.info newmap

#NOTE: this cannot work properly as SHAPE contains closed polygons
#v.clean should be used etc...

v.clean newmap out=newmap.clean tool=break,rmdupl
d.vect newmap.clean ty=area,boundary col=red

#we connect this map to the old DBF file:
db.connect database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp
db.describe table=markveggy

#we have to add an entry to the DB file:
cd `g.gisenv GISDBASE`
cd `g.gisenv LOCATION_NAME`
cd `g.gisenv MAPSET`

#if DB file not present, create it. Otherwise add the line:
newmap 1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/PERMANENT/shp dbf

#NOTE: it is sufficent to only write changed entries for 'KEY_COLUMN',
# 'path' and 'driver' entries because unchanged entries are inherited
# from the previous line(s). The full DB file make now contain:
markveggy.shp 1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/PERMANENT/shp dbf
newmap 1 markveggy

#... which links map 'newmap' with field 1 to table 'markveggy' with CAT_COLUMN
#'VEGCNP_ID' with the DBF file in directory '/ssi0/ssi...' using the 'dbf' driver
#(yes, we need an DB file editor - do you write it for us?)

#verify some settings:
g.gisenv

#query
d.erase
d.vect newmap
d.what.vect newmap
</div></pre>



<hr>
<b>Further Links:</b>

<ul>
<li><a href=http://postgis.refractions.net/>PostGIS with shp2pgsql</a>:<br>
          <tt>shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql</tt>
<li><a href=http://www.postgresql.org/>PostgreSQL</a> and 
    <a href=http://techdocs.postgresql.org/>PostgreSQL Technical
     Documentation</a>
<li><a href=http://www.klaban.torun.pl/prog/pg2xbase/>pg2xbase</a>
                  (DBF <-> PostgreSQL)
<li><a href=http://e00pg.sourceforge.net/>e002pg</a> (E00 to PostGIS
                  filter)
<li><a href=http://gdal.velocet.ca/projects/opengis/>ogrinfo and
                    ogr2ogr</a> (GIS vector format converter and
                  library, e.g. ArcInfo or SHAPE -> PostGIS)<br>
          <tt>ogr2ogr -f "PostgreSQL" shapefile ??</tt>

<li><a href=http://mdbtools.sourceforge.net/>mdbtools</a> (converts
                  MS-ACCESS data to SQL, DBF etc.)<br>
          <tt>gmdb dbfile.mdb</tt>
<li><a href=http://www.unixodbc.org/>unixODBC</a> to connect GRASS 5.1
                  to database servers such as PostgreSQL, Oracle etc.
</ul>

<!-- FOOTER -->
<p>
<hr>
<DIV ALIGN=right>&copy; 2002 Markus Neteler<br>
<a href="mailto:weblist at grass.itc.it">Comments</a> about this page | <a href="../../faq/index.html">FAQ</a> | <a href="../../download.html">Download</a> | <a href="../../support.html">Support</a> | <a href="../../gdp/index.html">Docs</a>  | <a href="../../grassdevel.html">Programming</a> | Back <a href=index.html>5.1 Tutorial Home</a><br>
<i>Last change:
$Date: 2002/12/23 09:03:49 $
</i></DIV>

</body>
</html>

--- NEW FILE: geom_storage.html ---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <DEFANGED_meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <DEFANGED_meta name="Author" content="Markus Neteler">
   <DEFANGED_link rel="stylesheet" type="text/css" href="../../sitestyle.css">
   <title>GRASS 5.1: Geometry management with connections to DBMS</title>
</head>
<body>

<!-- HEADER -->
<table width=100%><tr><td width=80>
<A HREF="index.html">
<DEFANGED_IMG src="../../images/grass.smlogo.gif" alt="HOME" border="0" align=middle></A>
</td><td><H1>
GRASS 5.1: Geometry management, optionally with connections to DBMS
</H1></td></tr></table>
<!-- END OF HEADER -->

<hr>
<a href="index.html">Tutorial HOME</a> |
<a href="geom_storage.html">Geometry management</a> |
<a href="attrib_storage.html">Attribute management</a> |
<a href="examples.html">Usage Examples</a>
<hr>

<i><b>README:</b>
GRASS 5.1 is currently under development. It is neither complete (it still
contains only a few modules) nor it is intended to productional usage. 
Development releases are provided for people who want to help test, debug,
and improve GRASS 5.1. Knowing this, please read on.</i><br>
<i>
These examples described here may work or not. You are kindly invited to
send us further examples and/or code bugfixes/enhancements.</i>
<P>

<h2>Introduction</h2>
In GIS the vector data model is used for geographic phenomena which may be
represented by geometric entities (primitives) like points, lines, and
areas. In GRASS 5.1 the vector data model includes the description of
topology, where besides the coordinates describing the location of the
points, lines, boundaries and centroids also their spatial relations are
stored. In general topological GIS require a data structure, where common
boundary between two adjacent areas is stored as a single line, simplifying
the map maintenance. 

The new GRASS 5.1 vector architecture overcomes the vector limitations of
GRASS 4.x-5.0 by extending the vector support with attributes stored in
external relational databases and by new 3D capabilities. Besides internal
file based storage the geometry may alternatively be stored in PostGIS
database. This enables users to maintain large data sets with simultaneous
write access. External GIS formats such as SHAPE-files may be used directly
without necessity of format conversion.

<center>
<DEFANGED_IMG src="51vectorarch.jpg" alt="GRASS 5.1 vector architecture">
</center>
<P>
There are various possibilities to store vector geometry in GRASS 5.1:

<ul>
<li>native format (default)
<li>SHAPE format
<li>PostGRASS format (using PostgreSQL/PostGIS)
<li>OGR supported formats (under development)
</ul>

See some vector API details <a href="http://freegis.org/cgi-bin/viewcvs.cgi/~checkout~/grass51/doc/vector/vector.html">here</a>.


<hr>
<ol>
<li><a href="#native">Geometry stored in native format</a>
<li><a href="#SHAPE">Geometry stored in SHAPE file: Registration of a map in
SHAPE format</a>
<li><a href="#PostGRASS">Geometry stored in external database (PostGRASS)
using PostGIS</a>
</ol>

To get debug information, set variable (set to 0 for debug silence) to 1..5:<div class="code"><pre>
export GRASS_DEBUG_LEVEL=5
</div></pre>


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="native"></a>
Geometry stored in native format
</b></big></font></td></tr></table>

Per default the vector geometry is stored in the GRASS 5.1 location
in native format.
<p>
For attributes management, see <a href="attrib_storage.html">various
methods</a>. You can store attributes in a DBF table, or connect to ODBC,
PostgreSQL or mySQL.


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="ODBC"></a>
Geometry stored in SHAPE file: Registration of a map in SHAPE format
</b></big></font></td></tr></table>

Direct SHAPE file support is implemented, i.e. maps in SHAPE format can be
used directly in GRASS 5.1 without importing them.

<div class="code"><pre>
#register SHAPE files (this will copy them into the LOCATION):

v.shape.register markveggy.shp
 Found following integer field(s) in SHAPE file:
 VEGCNP_
 VEGCNP_ID
 which field do you want to use? Enter name from above list:
 VEGCNP_ID
 markveggy.shp is registered now.
 The SHAPE files (.shp, shx and .dbf) were copied to:
   /ssi0/ssi/neteler/grassdata/botswanaLL/shp
 Consider to run v.build:
     v.build markveggy.shp

#WARNING: The DB file must probably be edited manually.

#build pseudo-topology for SHAPE
 v.build markveggy.shp

#get info about vector map:
 v.info markveggy.shp

#look at the map:
 d.mon x0
 d.vect markveggy.shp
</div></pre>

The DBF table should have been registered by v.shape.register in the DB file
(find in the mapset directory). Read also
<a href="attrib_storage.html#DBF">Attributes stored in DBF table</a>

<div class="code"><pre> 
#query map:
 d.what.vect
 d.what.vect -a
</div></pre>

<p>
For attributes management, see <a href="attrib_storage.html">various methods</a>
including the usage of the DBF file.


<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="PostGRASS"></a>
Geometry stored in PostGRASS database table using PostGIS
</b></big></font></td></tr></table>

Using PostGRASS which stores the vector geometry in a PostgreSQL/PostGIS
database, multiple user write access to vector geometry becomes possible.

<P>
TODO.
<P>
Hints for GRASS-PostGIS: see e.g. <a
href="http://grass.itc.it/pipermail/grassuser/2002-November/015822.html">this
thread</a>.

<!-- FOOTER -->
<p>
<hr>
<DIV ALIGN=right>&copy; 2002 Markus Neteler<br>
<a href="mailto:weblist at grass.itc.it">Comments</a> about this page | <a href="../../faq/index.html">FAQ</a> | <a href="../../download.html">Download</a> | <a href="../../support.html">Support</a> | <a href="../../gdp/index.html">Docs</a>  | <a href="../../grassdevel.html">Programming</a> | Back <a href=index.html>5.1 Tutorial Home</a><br>
<i>Last change:
$Date: 2002/12/23 09:03:49 $
</i></DIV>

</body>
</html>

--- NEW FILE: index.html ---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <DEFANGED_meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <DEFANGED_meta name="Author" content="Markus Neteler">
   <DEFANGED_META Name="description" Content="GRASS GIS (Geographic Resources
         Analysis Support System) is an open source, free software
         Geographical Information System (GIS) with raster, topological
         vector, image processing, and visualization functionality">
   <DEFANGED_META Name="keywords" Content="gis, GIS, GRASS, 5.1, vector, tutorial, DBMS, RDBMS, PostGIS, PostgreSQL, mySQL, DBF">
   <DEFANGED_link rel="stylesheet" type="text/css" href="../../sitestyle.css">
   <title>GRASS 5.1 tutorial</title>
</head>
<body>

<!-- HEADER -->
<table width=100%><tr><td width=80>
<A HREF="../index.html">
<DEFANGED_IMG src="../../images/grass.smlogo.gif" alt="HOME" border="0" align=middle></A>
</td><td><H1>
GRASS 5.1 (draft) Tutorial
</H1></td></tr></table>
<!-- END OF HEADER -->

Welcome to this draft tutorial.
GRASS 5.1 is currently under development. It is neither complete (it still
contains only a few modules) nor it is intended to productional usage. 
Development releases are provided for people who want to help test, debug,
and improve GRASS 5.1. Knowing this, please read on.

<ol>
<li><a href="geom_storage.html">Geometry management, optionally with connections to DBMS</a>
<li><a href="attrib_storage.html">Attribute management with connections to DBMS</a>
<li><a href="examples.html">Examples to use the GRASS 5.1 vector engine</a>
</ol>

<hr>
References:<p>

R. Blazek, M. Neteler, and R. Micarelli, 2002. The new GRASS 5.1 vector
architecture. In <i>Open source GIS - GRASS users conference 2002, Trento,
Italy, 11-13 September 2002. University of Trento, Italy</i>.
<a target="top" href="http://www.ing.unitn.it/~grass/proceedings/proceedings/pdfs/Blazek_Radim.pdf">http://www.ing.unitn.it/~grass/proceedings/proceedings/pdfs/Blazek_Radim.pdf</a>
<p>

<b>Further Links:</b>

<ul>
<li><a href=index.html>GRASS 5.1 main page</a></li>
<li><a href="http://mpa.itc.it/markus/grass51/index.html">GRASS 5.1 Draft
    Programmer's Manual</a></li>
<li> Implementation of new <a
 href="http://freegis.org/cgi-bin/viewcvs.cgi/~checkout~/grass51/doc/vector/vector.html">GRASS
 5.1 vector API</a> (3D vectors, DBMS support, 32/64bit support)</li>
</ul>

<!-- FOOTER -->
<p>
<hr>
<DIV ALIGN=right>&copy; 2002 Markus Neteler<br>
<a href="mailto:weblist at grass.itc.it">Comments</a> about this page | <a href="../../faq/index.html">FAQ</a> | <a href="../../download.html">Download</a> | <a href="../../support.html">Support</a> | <a href="../../gdp/index.html">Docs</a>  | <a href="../../grassdevel.html">Programming</a> | Back <a href=../index.html>5.1 HOME</a><br>
<i>Last change:
$Date: 2002/12/23 09:03:49 $
</i></DIV>

</body>
</html>





More information about the grass-web mailing list