[GRASSweb-list]markus: web/grass51/tutorial ex_complex.html,1.9,1.10
grass at intevation.de
grass at intevation.de
Thu Jul 31 09:17:43 EDT 2003
Author: markus
Update of /grassrepository/web/grass51/tutorial
In directory doto:/tmp/cvs-serv3375
Modified Files:
ex_complex.html
Log Message:
added cats management and vector line length assignment
Index: ex_complex.html
===================================================================
RCS file: /grassrepository/web/grass51/tutorial/ex_complex.html,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ex_complex.html 31 Jul 2003 10:43:22 -0000 1.9
+++ ex_complex.html 31 Jul 2003 13:17:41 -0000 1.10
@@ -173,7 +173,7 @@
reading GRASS raster, SHAPE, GeoTIFF and PostGRASS/PostGIS data</a>
<P>
-<b>Add a table 'view'</b><p>
+<b>EXTRA: Add a table 'view'</b><p>
Since we still have the geometry and attributes in different tables, we
can add a 'view' onto both tables (sort of virtual table merging both).
@@ -192,6 +192,83 @@
may calculate the length of each vector, assign it to the attributes table
and enjoy the map queries.
+<P>
+<b>Adding stream length labels</b>
+<P>
+Since the Spearfish 'streams' map does not contain attributes, we show how
+to add stream length labels. To have useful stream lengths, we first
+polish the map and generate polylines from lines (changing nodes along
+a vector to vertices, whereever possible):
+
+<div class="code"><pre>
+v.build.polylines in=streams_catsnew out=streams_pl
+d.vect streams_pl col=red
+</pre></div>
+
+<br>
+Now the existing 'cat' values must be removed as we need the vector
+lines numbered individually:
+
+<div class="code"><pre>
+v.category input=streams_pl option=del out=streams_nocat
+v.category input=streams_nocat option=report
+</pre></div>
+
+<br>
+The second command should report nothing. Now we add individual
+category values to each vector (increasing number):
+
+<div class="code"><pre>
+v.category input=streams_nocat option=add step=1 cat=1 out=streams_length
+v.category input=streams_length option=report
+</pre></div>
+Now categories should be displayed.
+<p>
+
+Vector geometry statistics such as line length can be calculated with 'v.to.db'
+(print only first):
+<div class="code"><pre>
+v.to.db -p streams_length option=length units=me col1=cat
+</pre></div>
+
+<br>
+The length values we want to assign in a new attribute column.
+Up to now there is no attribute table for the new map. We generate
+it therefore and add the length attributes. The link between
+vectors and attribute table rows is established by the 'cat' values.
+Note that uploading attributes of a vector map to the DBMS has to be done
+column-wise:
+
+<div class="code"><pre>
+echo "create table streams_length (cat int, length float)" | db.execute
+db.describe -c streams_length
+v.db.connect -p streams_length
+
+#set DBMS link for new map to new table:
+v.db.connect driver=pg database="host=pgserver.itc.it,dbname=spearfish,user=postgres" table=streams_length
+v.to.db streams_length option=cat col1=cat
+v.to.db streams_length option=length col1=length
+</pre></div>
+
+<br>
+<!-- echo "insert into viapri_for_clean_c values (1,1)" | db.execute -->
+
+To verify, we can query the table and look at the map in the GRASS monitor:
+<div class="code"><pre>
+echo "select * from streams_length" | db.select
+d.vect streams_length col=brown display=shape,attr attrcol=length
+</pre></div>
+
+To use the new map 'streams_length' also in MapServer, in table
+'geometry_columns' a new row must be added:
+
+<div class="code"><pre>
+echo "INSERT INTO geometry_columns VALUES ('','spearfish','streams_length_geom','geom','2','-1','GEOMETRY');" | db.execute
+</pre></div>
+
+And finally the map has to be added to the 'mapfile' of MapServer.
+
+
<p><table width="100%" cellpadding="3" border="0">
<tr><td align="left" bgcolor="#B0F0B0"><font color="#00000"><big><b>
<a name="shape_conversion"></a>
@@ -199,8 +276,8 @@
<DIV ALIGN=right><a href="#toc">[UP]</a></DIV>
</b></big></font></td></tr></table>
-This time we are not talking about simlpy registering a SHAPE map,
-but really converting it to another format.<br>
+This time we are not talking about simply registering a SHAPE map,
+but about really converting it into another spatial format.<br>
WARNING: don't try this at home. Still pretty unstable.
<div class="code"><pre>
@@ -211,24 +288,19 @@
#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
+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 in the 'dbln' file:
-cd `g.gisenv GISDBASE`
-cd `g.gisenv LOCATION_NAME`
-cd `g.gisenv MAPSET`
-
-#create here a file 'dbln' with following contents:
-1 markveggy VEGCNP_ID /ssi0/ssi/neteler/grassdata/botswanaLL/PERMANENT/shp dbf
+v.db.connect newmap_clean dr=dbf database=/ssi0/ssi/neteler/grassdata/botswanaLL/PERMANENT/shp table=markveggy key=VEGCNP_ID
#check if it is connected:
-v.db.connect -p newmap
+v.db.connect -p newmap_clean
#draw & query
d.erase
-d.vect newmap
-d.what.vect newmap
+d.vect newmap_clean
+d.what.vect newmap_clean
</pre></div>
TODO: check if meanwhile g.copy does the same, probably followed by v.clean
More information about the grass-web
mailing list