[GRASSweb-list]markus: web/grass51 attrib_storage.html,NONE,1.1 geom_storage.html,NONE,1.1 examples.html,1.14,1.15

grass at intevation.de grass at intevation.de
Tue Dec 3 11:17:08 EST 2002


Author: markus

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

Modified Files:
	examples.html 
Added Files:
	attrib_storage.html geom_storage.html 
Log Message:
extended, cleanup

--- 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 -->


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:
<pre>
export GRASS_DEBUG_LEVEL=5
</pre>

<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>
</ol>

<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>

Add entry in the GRASS 5.1 'DB' file:
<pre>
markveggy.shp 1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/shp dbf
</pre>

Connect GRASS 5.1 to the table:
<pre>
db.connect driver=dbf database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp
db.tables -p
</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>
  </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>

<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</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>

<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; =</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):
<pre>
createdb -h rastrel grass51test
</pre>

<li>
Now run the 'db.connect' command:
<pre>
db.connect driver=odbc database=grass51test
</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):
<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 
</pre>


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

<li>
Finally a test: Here we should see the table columns (if the ODBC
              connection works):
<pre>
db.tables -p
db.columns table=markveggy
</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.

<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>

Add entry in the GRASS 5.1 'DB' file:
<pre>
markveggy.shp 1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/shp dbf
</pre>

Connect GRASS 5.1 to the table:
<pre>
db.connect driver=dbf database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp
db.tables -p
</pre>

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

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


<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.

<!-- FOOTER -->
<p>
<hr>
<DIV ALIGN=right>&copy; 2002 GRASS Development Team/MN<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=examples.html>5.1 examples</a><br>
<i>Last change:
$Date: 2002/12/03 16:17:05 $
</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 -->


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:
<pre>
export GRASS_DEBUG_LEVEL=5
</pre>

<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)</a>
</ol>

<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>
TODO.

<p>
For attributes management, see <a href="attrib_storage.html">various
methods</a>.


<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.

<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

#establish database connection (get path from v.shape.register messages):
#here we use the DBF driver:
 db.connect database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp

#look at the related dbf table:
 db.describe table=markveggy

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

#look at the map:
 d.mon x0
 d.vect markveggy.shp

#query map:
 d.what.vect
 d.what.vect -a
</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
</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 GRASS Development Team/MN<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=examples.html>5.1 examples</a><br>
<i>Last change:
$Date: 2002/12/03 16:17:05 $
</i></DIV>

</body>
</html>

Index: examples.html
===================================================================
RCS file: /grassrepository/web/grass51/examples.html,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- examples.html	26 Nov 2002 15:56:03 -0000	1.14
+++ examples.html	3 Dec 2002 16:17:05 -0000	1.15
@@ -8,10 +8,15 @@
 </head>
 <body>
 
-<table width="100%" cellpadding="3" border="0">
-<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
+<!-- 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
-</b></big></font></td></tr></table><p>
+</H1></td></tr></table>
+<!-- END OF HEADER -->
+
 
 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. 
@@ -43,37 +48,37 @@
     v.topo.check v.build.polylines v.convert v.info v.shape.register
     v.category v.digit v.out.ascii v.shape.unregister v.clean v.extract
     v.out.ogr v.surf.rst
-</ul>
-
+<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>.
-<p>
+<li>
 d.m is a new <a href=http://mpa.itc.it/radim/g51/d.m.jpg>display manager</a>.
+</ul>
 
-<p>
-<font color="#919100">
-TODO for this document - reorganize it to these items:<br>
+<hr>
 <ol>
-<li>GRASS vector data stored in GRASS (native) format, attributes stored in DBF table (use of
-        v.convert to convert 5.0 data)
-<li>GRASS vector data stored in GRASS (native) format, attributes stored in external database
-        (PostgreSQL) connected through ODBC
-<li>GRASS using vector geometry data stored in SHAPE format, attributes stored in SHAPE/DBF table
-<li>GRASS using vector geometry data stored in PostGIS format, attributes stored in DBF table
-<li>GRASS using vector geometry data stored in PostGIS format, attributes stored in PostgreSQL
-        table (connected through ODBC)
-<li>SQL queries and selective data visualization
-<li>Vector extraction into new map
-<li>(Import of common GIS formats)
-<li>Export into common GIS formats
+<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>
-</font>
+
 
 <p><table width="100%" cellpadding="3" border="0">
 <tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
-Example 1: Convert 5.0 vector maps to 5.1
+<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:
@@ -84,11 +89,9 @@
 Vector maps from 5.0 and 5.1 do not interfere (different directories),
 so you can use the  same names.
 
-<p><table width="100%" cellpadding="3" border="0">
-<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000">
-<big><b>
-Example 2: Export of 5.1 vector map to GRASS 5.0
-</b></big></font></td></tr></table>
+<p><b>
+Convert 5.1 vector map to GRASS 5.0
+</b><p>
 
 <pre>
 v.out.ascii -o newmap.clean out=newmap.clean
@@ -98,69 +101,62 @@
 
 <p><table width="100%" cellpadding="3" border="0">
 <tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
-Example 3: Registration of a map in SHAPE format
+<a name="geometry"></a>
+Geometry storage in various formats
 </b></big></font></td></tr></table>
 
-Maps in SHAPE format can be used directly in GRASS 5.1 without importing
-them.
-
-<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
+There are various possibilities to store vector geometry in GRASS 5.1:
 
-#WARNING: The DB file must probably be edited manually.
+<ul>
+<li>native format (default)
+<li>SHAPE format
+<li>PostGRASS format (using PostgreSQL/PostGIS)
+<li>OGR supported formats (under development)
+</ul>
 
-#build pseudo-topology for SHAPE
- v.build markveggy.shp
+Read on here about <a href=geom_storage.html>storing vector geometry in
+GRASS 5.1</a>.
 
-#establish database connection (get path from v.shape.register messages):
-#here we use the DBF driver:
- db.connect database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp
 
-#look at the related dbf table:
- db.describe table=markveggy
+<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>
 
-#get info about vector map:
- v.info markveggy.shp
+There are various possibilities to store attributes in GRASS 5.1:
 
-#look at the map:
- d.mon x0
- d.vect markveggy.shp
+<ul>
+<li>DBF file
+<li>ODBC connected RDBMS
+<li>PostgreSQL database
+<li>mySQL database
+</ul>
 
-#query map:
- d.what.vect
-</pre>
+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>
-Example 2: Extract vector data from map to new map with SQL statements
+<a name="v.extract"></a>
+Example: Extract vector data from map to new map with SQL statements
 </b></big></font></td></tr></table>
 
 <pre>
-db.connect database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp
-
 #note: strings must be quoted:
 v.extract markveggy.shp output=markveggy.1 where="VEGTYPE = 'PS'"
 </pre>
 
 <p><table width="100%" cellpadding="3" border="0">
 <tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
-Example 4: Export data using OGR
+<a name="ogr_export"></a>
+Example: Vector map export data using OGR
 </b></big></font></td></tr></table>
 
-Export to SHAPE format (generates /tmp/testogr.shp and related files):
+Export of GRASs 5.1 vector map to SHAPE format (generates /tmp/testogr.shp
+and related files):
+
 <pre>
 v.out.ogr input=multi typ=line dsn=/tmp layer=testogr
 </pre>
@@ -174,10 +170,51 @@
 
 <p><table width="100%" cellpadding="3" border="0">
 <tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
-Example 5: Conversion of SHAPE map to GRASS 5.1 vector map
+<a name="SQL_queries"></a>
+Example: SQL queries
 </b></big></font></td></tr></table>
 
-#WARNING: don't try this at home. Pretty unstable yet.
+
+<b>Example: we want to read attributes from a connected DBF table (see above
+how to connect attribute tables):</b><p>
+
+<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
+</pre>
+
+<b>Example: we want to read attributes from a PostgreSQL table connected through
+ODBC  (see above how to connect attribute tables):</b><p>
+
+<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
+</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.
 
 <pre>
 v.out.ascii markveggy.shp out=test1
@@ -221,185 +258,7 @@
 d.what.vect newmap
 </pre>
 
-<p><table width="100%" cellpadding="3" border="0">
-<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
-Example 6: Connecting GRASS 5.1 DBMI (attributes) to PostgreSQL
-      through ODBC
-</b></big></font></td></tr></table>
-
-Possible communication between GRASS 5.1 and PostgreSQL database for
-    attribute management: <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-PostgreSQL-driver
-&lt;-&gt; PostgreSQL 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>
-  </tbody>
-</table>
-
-<ul>
-<li>
-Configure ODBC driver for selected database (without ODBCConfig). ODBC
-drivers are defined in /etc/odbcinst.ini. Here is example:</li>
-
-<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</pre>
-
-<li> Create DSN (data source name). 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 the PostgreSQL protocol version]. Omit blanks at the beginning of
-lines:</li>
-
-<pre>&nbsp;[grass51test]
-&nbsp;Description&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; = PostgreSQL
-&nbsp;Trace&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;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; =
-&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; =</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 GUI ODBCConfig and 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 the database (if not yet existing, '-h host' defines the
-        PostgreSQL server host):
-<pre>
-createdb -h rastrel grass51test
-</pre>
-
-<li>
-Now run the 'db.connect' command:
-<pre>
-db.connect driver=odbc database=grass51test
-</pre>
-
-<li>Next we dump the DBF file into PostgreSQL (NOTE: unless a
-            'db.copy' does not exist, we use 'pg.in.dbf' from GRASS 5.0):
-<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 
-</pre>
-
-<li>
-Finally a test: Here we should see the table columns (if the ODBC
-              connection works):
-<pre>
-db.columns table=markveggy
-</pre>
-</ul>
-
-
-<p><table width="100%" cellpadding="3" border="0">
-<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
-Example 7: Export of SHAPE-DBF file to PostgreSQL and vector map
-      link to PostgreSQL through ODBC
-</b></big></font></td></tr></table>
-
-<pre>
-#edit DB file and create an entry
-cd `g.gisenv GISDBASE`
-cd `g.gisenv LOCATION_NAME`
-cd `g.gisenv MAPSET`
-
-#change existing 'markveggy.shp' to ODBC driver:
-markveggy.shp 1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/shp 
-
-#check settings
-db.connect -p
-
-#this should print the table name:
-db.tables
-</pre>
 
-
-<p><table width="100%" cellpadding="3" border="0">
-<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
-Example 8: SQL queries
-</b></big></font></td></tr></table>
-
-<pre>
-#First we want to read from the DBF table:
-#NOTE: connections for db.* SQL commands (eg db.select...) are established with db.connect:
-db.connect driver=dbf database=/ssi0/ssi/neteler/grassdata/botswanaLL/shp
-
-#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: vector commands use connection(s) defined in DB file (see above):
-#add line
-markveggy.vegtype 1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/shp dbf
-
-#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
-
-############
-#Now connection to PostgreSQL through ODBC:
-db.connect driver=odbc database=grass51test
-echo "select VEGCNP_ID from markveggy where VEGTYPE = 'IFA'" | db.select -hc
-
-#add line to DB file to connect vector map
-markveggy.vegtype 1 markveggy VEGCNP_ID grass51test odbc
-
-#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
-
-</pre>
-
-GRASS-PostGIS: see e.g. <a
-href="http://grass.itc.it/pipermail/grassuser/2002-November/038663.html">this
-thread</a>.
-<p>
-Attribute support for DBF, ODBC, mySQL, PostgreSQL now.
 
 <hr>
 <b>Further Links:</b>





More information about the grass-web mailing list