[GRASSweb-list]markus: web/grass51/tutorial ex_complex.html,1.8,1.9

grass at intevation.de grass at intevation.de
Thu Jul 31 06:43:25 EDT 2003


Author: markus

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

Modified Files:
	ex_complex.html 
Log Message:
updated Mapserver example

Index: ex_complex.html
===================================================================
RCS file: /grassrepository/web/grass51/tutorial/ex_complex.html,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ex_complex.html	31 Jul 2003 09:19:49 -0000	1.8
+++ ex_complex.html	31 Jul 2003 10:43:22 -0000	1.9
@@ -46,152 +46,114 @@
 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).
+for non-topological OGR/MapServer - this may change in future).
 <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.
+First we create a new PostGIS database suitable for PostGRASS:
 
 <div class="code"><pre>
-pg.postgisdb -c spearfish -h grass.itc.it -U postgres -G ./
-v.convert input=streams at PERMANENT output=streams
+#you need the file postgis.sql from PostGIS in the current directory:
+pg.postgisdb -c spearfish -h pgserver.itc.it -U postgres -G ./
 </pre></div>
-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):
+Now we change the GRASS 5.1 default setting for geometry data storage
+from the internal native format to PostGRASS:
 
 <div class="code"><pre>
-cd $HOME/grassdata/spearfish/user1/vector
-mkdir streams_pg
-cd streams_pg
+v.format
+  # Select "Output format (Native or PostGIS)" from the menu
+  # Select  Output format: postgis
+  # Select  PostGIS database: host=pgserver.itc.it,dbname=spearfish,user=postgres
+  # click "Apply" (check for error messages in the terminal window), 
+  #       "Close"
 </pre></div>
 
-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
-</pre></div>
+<br>
+Next we change the GRASS 5.1 default setting for attribute data storage
+from the internal DBF format to PostgreSQL:
 
-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
+v.database driver=pg database="host=pgserver.itc.it,dbname=spearfish,user=postgres"
 </pre></div>
 
-Then we import the map to PostGRASS:
+<br>
+We are ready to import the data now. As we are using the GRASS 5.0 spearfish
+data base, we have to convert the data to the new format. The new map will
+be directly stored in our PostGRASS server:
 
 <div class="code"><pre>
-v.out.ascii input=streams out=streams_pg
-v.in.ascii input=streams_pg out=streams_pg
+v.convert input=streams output=streams
 </pre></div>
 
-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
-</pre></div>
+<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.
+<P>
+The vector geometry and the attributes table are linked automatically.
+To verify that, we run:
 
-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
+v.info streams
+ [...]
+ Map format: postgis
+ [...]
+ Number of dblinks:      1
+ [...]
 </pre></div>
 
-We have the geometry and the attributes table ready now. Finally missing is
-the link of the vector geometry to the attribute table:
+<br>
+Let us look at the map now:
 
 <div class="code"><pre>
-v.db.connect map=streams_pg table=streams_atts driver=pg \
-             database='pgserver.itc.it,dbname=spearfish,user=postgres'
-v.db.connect -p streams_pg 
+d.mon x0
+g.region vect=streams
+d.vect streams col=blue
+v.db.connect -p streams
+d.what.vect streams
 </pre></div>
 
-Now we should be able to look at and query the map with:
-
+<br>
+To see the new tables in PostGRASS, we run:
 <div class="code"><pre>
-d.vect streams_pg col=green
-d.what.vect streams_pg
+db.connect driver=pg database="host=pgserver.itc.it,dbname=spearfish,user=postgres"
+db.tables -p
+db.describe -c streams
 </pre></div>
 
 <P>
 <b>MapServer preparations</b><p>
 
-To make MapServer accept the PostGIS data, we need a table
+To make MapServer accept the PostGIS data, we need to fill the 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
-);
-</pre></div>
-
-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
-</pre></div>
-
-<!-- select * from  geometry_columns;
-     \d geometry_columns
--->
-Then we fill this table with one row:
+PostgreSQL.
+<BR>
+One row has to be added:
 <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
+db.connect driver=pg database="host=pgserver.itc.it,dbname=spearfish,user=postgres"
+db.tables -p
+echo "INSERT INTO geometry_columns VALUES ('','spearfish','streams_geom','geom','2','-1','GEOMETRY');" | db.execute
+#verify:
+echo "select * from geometry_columns" | db.select
 </pre></div>
 
-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 :
+Finally MapServer requires a mapfile entry similar to this (note: 
+polygons are not supported yet in PostGRASS/MapServer and draw as
+boundaries only):
 
 <div class="code"><pre>
 LAYER
-  NAME "streams_pgg"
+  NAME "streams_geom"
   CONNECTIONTYPE postgis
   CONNECTION "user=postgres dbname=spearfish host=127.0.0.1"
   #      Column    geom_table
-  DATA "geom from streams_pgg"
+  DATA "geom from streams_geom"
   TYPE LINE
   STATUS DEFAULT
   CLASS
     SYMBOL "pattern1"
-    NAME "Soils"
+    NAME "label"
     OUTLINECOLOR 100 50 0
     COLOR 255 100 100
     LABEL
@@ -203,6 +165,9 @@
 END
 </pre></div>
 
+This 'streams' map does not contain attributes because of the related Spearfish
+map.
+<P>
 And here you can see how it looks like: <br>
 <a href=http://grass.itc.it/cgi-bin/mapserv?map=/var/www/map-script/mapserverjs.map&layer=dem>Demo Online MapServer
 reading GRASS raster, SHAPE, GeoTIFF and PostGRASS/PostGIS data</a>
@@ -216,9 +181,9 @@
 you should use 'CREATE TABLE' instead:
 
 <div class="code"><pre>
-CREATE VIEW test AS select streams_pgg.id, streams_pgc.cat, streams_pgg.type, streams_pgg.geom \
- from streams_pgg,streams_pgc WHERE streams_pgg.id = streams_pgc.id AND \
- streams_pgc.field = 1;
+CREATE VIEW test AS select streams_geom.id, streams_cat.cat, streams_geom.type, streams_geom.geom \
+ from streams_geom,streams_cat WHERE streams_geom.id = streams_cat.id AND \
+ streams_cat.field = 1;
 INSERT into geometry_columns values ( ' ', ' ', 'test2', 'geom', 2, -1, 'GEOMETRY' );
 </pre></div>
 





More information about the grass-web mailing list