[GRASSweb-list]markus: web/grass51/tutorial attrib_storage.html,1.6,1.7 demo.html,1.2,1.3 examples.html,1.5,1.6 geom_storage.html,1.4,1.5

grass at intevation.de grass at intevation.de
Thu Jan 23 10:42:51 EST 2003


Author: markus

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

Modified Files:
	attrib_storage.html demo.html examples.html geom_storage.html 
Log Message:
added PostGRASS/Mapserver example

Index: attrib_storage.html
===================================================================
RCS file: /grassrepository/web/grass51/tutorial/attrib_storage.html,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- attrib_storage.html	21 Jan 2003 17:39:41 -0000	1.6
+++ attrib_storage.html	23 Jan 2003 15:42:49 -0000	1.7
@@ -452,20 +452,12 @@
 <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.ca.postgresql.org/users-lounge/docs/>PostgreSQL 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>
@@ -476,7 +468,7 @@
 <!-- FOOTER -->
 <p>
 <hr>
-<DIV ALIGN=right>&copy; 2002 Markus Neteler<br>
+<DIV ALIGN=right>&copy; 2002-2003 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$

Index: demo.html
===================================================================
RCS file: /grassrepository/web/grass51/tutorial/demo.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- demo.html	22 Jan 2003 18:27:19 -0000	1.2
+++ demo.html	23 Jan 2003 15:42:49 -0000	1.3
@@ -192,6 +192,19 @@
 ./bench
 </div></pre>
 
+will print a table similar to this example:
+ 
+<div class="code"><pre>
+ 
+</div></pre>
+Benchmark native contra PostGIS with following number of vectors:
+ Number of points: 200000
+ Number of lines: 160000
+ Number of centroids: 40000
+ Number of areas: 40000
+ Number of islands: 40000
+Action          big             big.post
+import          60.177005 note remote machine
 </li>
 </ul>
 

Index: examples.html
===================================================================
RCS file: /grassrepository/web/grass51/tutorial/examples.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- examples.html	21 Jan 2003 17:39:41 -0000	1.5
+++ examples.html	23 Jan 2003 15:42:49 -0000	1.6
@@ -78,6 +78,8 @@
    data</a>
 <li><a href="#db_copy">Example: Copying a database table from one DBMS to another within GRASS 5.1
    table</a>
+<li><a href="#postgismapserver">Example: Writing the GRASS 5.0 Spearfish
+   'streams' map into PostGIS for MapServer</a>
 </ol>
 
 
@@ -375,11 +377,186 @@
 This may take some time depending on network speed and table size.
 
 
+<p><table width="100%" cellpadding="3" border="0">
+<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
+<a name="postgismapserver"></a>
+Example: Writing the GRASS 5.0 Spearfish 'streams' map into PostGIS for MapServer
+</b></big></font></td></tr></table>
+
+In this example we want to take the Spearfish 'streams' vector map and write
+it to PostGRASS (PostGIS). This map will be accessible by MapServer.<br>
+<b>Note:</b> PostGRASS data linked to MapServer support only LINE and POINT
+vectors but not POLYGONS (PostGRASS is not doubling boundaries as required
+for non-topological OGR/MapServer).
+<P>
+First we create a new PostGIS database suitable for PostGRASS, then we
+convert the old 5.0 'streams' map to 5.1 native format.
+
+<div class="code"><pre>
+postgisdb -c spearfish -h grass.itc.it -U postgres -G ./
+v.convert input=streams at PERMANENT output=streams
+</div></pre>
+The category labels are automatically written to a new DBF file.
+<br>
+Note that there are two small (!) leftover vector lines in the original 5.0
+streams map. These you may delete with the new 'v.digit', then the topology
+will be clean.
+<br>
+Now we write it to PostGRASS. For that we have to create a 'frmt' file which
+defines the PostGRASS connection and a 'head' file which defines the basic
+vector metadata. Note that special characters including '.' are forbidden
+(SQL restriction):
+
+<div class="code"><pre>
+cd $HOME/grassdata/spearfish/user1/vector
+mkdir streams_pg
+cd streams_pg
+</div></pre>
+
+Here generate the ASCII file 'frmt':
+<div class="code"><pre>
+FORMAT:postgis
+HOST:pgserver.itc.it
+DATABASE:spearfish
+USER:postgres
+GEOM_TABLE:streams_pgg
+CAT_TABLE:streams_pgc
+</div></pre>
+
+Next we need a 'head' file (you may re-use another 'head' file from another
+vector map):
+<div class="code"><pre>
+ORGANIZATION: GRASS Development Team
+DIGIT DATE:   8/23/90
+DIGIT NAME:   grass
+MAP NAME:     streams_pg
+MAP DATE:     2003
+MAP SCALE:    24000
+OTHER INFO:   Map imported from Spearfish 5.0
+ZONE:         0
+MAP THRESH:   0.500000
+</div></pre>
+
+Then we import the map to PostGRASS:
+
+<div class="code"><pre>
+v.out.ascii input=streams out=streams_pg
+v.in.ascii input=streams_pg out=streams_pg
+</div></pre>
+
+Now we may also want to store the attributes in PostgreSQL. The 'v.convert'
+which we used above, had already written a DBF file. This we can copy now to
+PostgreSQL into the same database 'spearfish':
+
+<div class="code"><pre>
+db.copy from_driver=dbf from_database=$HOME/grassdata/spearfish/user1/dbf \
+  from_table=streams to_driver=pg \
+  to_database="host=pgserver.itc.it,dbname=spearfish,user=postgres" \
+  to_table=streams_atts
+</div></pre>
+
+To check the existing tables in PostGIS, we run:
+<div class="code"><pre>
+db.connect driver=pg database="host=pgserver.itc.it,dbname=spearfish,user=postgres"
+db.tables -p
+db.describe -c streams_atts
+</div></pre>
+
+We have the geometry and the attributes table ready now. Finally missing is
+the DB link definition for GRASS which is defined in the 'dbln' file:
+
+<div class="code"><pre>
+cd $HOME/grassdata/spearfish/user1/vector/streams_pg
+</div></pre>
+
+The 'dbln' file contains the connection parameters such as:
+<div class="code"><pre>
+#field table ID database DBMIdriver
+1 streams_atts CAT host=pgserver.itc.it,dbname=spearfish,user=postgres pg
+</div></pre>
+
+Now we should be able to look at and query the map with:
+
+<div class="code"><pre>
+d.vect streams_pg col=green
+d.what.vect streams_pg
+</div></pre>
+
+<P>
+<b>MapServer preparations</b><p>
+
+To make MapServer accept the PostGIS data, we need a table
+'GEOMETRY_COLUMNS' which links the geometry to the attributes within
+PostgreSQL. Generate following SQL ASCII file:
+
+<div class="code"><pre>
+CREATE TABLE GEOMETRY_COLUMNS (
+    F_TABLE_CATALOG VARCHAR(256) NOT NULL,
+    F_TABLE_SCHEMA VARCHAR(256) NOT NULL,
+    F_TABLE_NAME VARCHAR(256) NOT NULL,
+    F_GEOMETRY_COLUMN VARCHAR(256) NOT NULL,
+                COORD_DIMENSION INTEGER NOT NULL,
+    SRID INTEGER NOT NULL,
+    TYPE VARCHAR(30) NOT NULL
+);
+</div></pre>
+
+and generate this this table in PostGIS within the 'spearfish' database:
+
+<div class="code"><pre>
+psql -h pgserver.itc.it -U postgres spearfish < geometry_columns.sql
+</div></pre>
+
+<!-- select * from  geometry_columns;
+     \d geometry_columns
+-->
+Then we fill this table with one row:
+<div class="code"><pre>
+psql -h pgserver.itc.it -U postgres spearfish
+INSERT INTO geometry_columns VALUES ('','spearfish','streams_pgg','geom','2','-1','GEOMETRY');
+\q
+</div></pre>
+
+The entry order is:<br>
+CATALOG empty , SCHEMA database, NAME geomtable, COLUMN geometry_column,
+DIMENSION 2, SRID -1, TYPE GEOMETRY
+<p>
+
+Finally MapServer requires a mapfile entry similar to this (polygons are
+unsupported :
+
+<div class="code"><pre>
+LAYER
+  NAME "streams_pgg"
+  CONNECTIONTYPE postgis
+  CONNECTION "user=postgres dbname=spearfish host=127.0.0.1"
+  #      Column    geom_table
+  DATA "geom from streams_pgg"
+  TYPE LINE
+  STATUS DEFAULT
+  CLASS
+    SYMBOL "pattern1"
+    NAME "Soils"
+    OUTLINECOLOR 100 50 0
+    COLOR 255 100 100
+    LABEL
+      POSITION CC
+      SIZE SMALL
+      COLOR 255 0 0
+    END
+  END
+END
+</div></pre>
+
+And here you can see how it looks like: <a
+href=http://grass.itc.it/cgi-bin/mapserv?map=/var/www/map-script/mapserverjs.map&layer=dem>Online MapServer
+reading GRASS raster, SHAPE, GeoTIFF and PostGRASS/PostGIS data</a>
+
 <hr>
 <b>Further Links:</b>
 
 <ul>
-<li><a href=http://postgis.refractions.net/>PostGIS with shp2pgsql</a>:<br>
+<li><a href=http://postgis.refractions.net/download.php>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

Index: geom_storage.html
===================================================================
RCS file: /grassrepository/web/grass51/tutorial/geom_storage.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- geom_storage.html	21 Jan 2003 17:39:41 -0000	1.4
+++ geom_storage.html	23 Jan 2003 15:42:49 -0000	1.5
@@ -163,7 +163,7 @@
 </div></pre>
 
 Next we have to create a 'frmt' file which defines the PostGRASS connection
-and a 'head' file which defines the basic vector names:
+and a 'head' file which defines the basic vector metadata:
 <div class="code"><pre>
 cd $HOME/grassdata/botswanaUTM34/PERMANENT/vector
 mkdir pgmap
@@ -216,6 +216,14 @@
 
 <ul>
 <li><a href=http://postgis.refractions.net/docs/>PostGIS manual</a><br>
+<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://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>
 </ul>
 
 <!-- FOOTER -->





More information about the grass-web mailing list