Prev Up Top Next Contents

5.B GIS

5.B.1 Grass

GRASS (Geographical Resources Analysis Support System), http://grass.fbk.eu , is a set of programs under a graphical interface, the "GIS Manager". It is very robust and certainly the best among the open source GIS. The output of the programs is diaplayed in the "output" window, which is also the grass console where the commands can be written and executed. Infact the grass windows are just graphical interfaces that help the user to enter the argument for the programs.
It has a wide documentation, available in internet, and the reader should refer to it. There are a few pages about Grass on the Therion wiki (in the French section).
The data are organized in Locations and Mapsets. When you start Grass you must choose a work Location and Mapset. The GIS Manager has a set of menus:


Grass interface
Fig. 78. Grass interface

5.B.1.1 Sample Grass uses

To manage the mapset configuration: "Config ->Region ->Display | Change | Zoom max"
To manage maps (list, rename, remove): "File ->Manage maps ->List | Rename | Remove"
To import a map (georeferenced TIFF image): "File ->Import ->Raster map ->Multiple formats using GDAL". Next selct the map TIFF file and possible the box "Override projection".
To list the raster maps: "File ->Manage maps ... ->List maps" and select the map type ("rast").
To chenge the bounds of a raster map: "Raster ->Develop map ->Manage boundary definitions" Then select the raster map, and insert the North, South, East and West values.
To display a raster maps: add a raster layer (second button), click on the name "raster 1", select the "Base map". Next click on the first (or the second) button of the Map Display window to display (or refresh) the window. Repeat if you want to add several maps. To display vector map add a vector layer (eighth button), and set the layer map (and the color).
To remove a layer from the display, select it (click on it) and cut (button with scissors on the second row).
To import a DXF file (e.g., created with Therion): "File ->Import ->Vector map ->DXF file", select the DXF file, and enter the map name.
To add a shapefile: "File ->Import ->Vector map ->Various format using OGR", select the ".shx" file, enter the vector map name. You might have to check "Overwrite projection (use location projection)" if OGR does not recognize the projection, but you are sure that the shapefile data projection is the same as that of the Location.
To enlarge the map elements with a buffer zone: "Vector ->Create vector buffer". Select the input map, enter a name for the output map, select the types (point, line, area) around which to create the buffer, and the buffer size.
To view the attributes of a vector map: "Vector ->Report and statistics ->Basic information"
  "v.info -c map=<map1> layer=1"
To extract a submap with a query: "Vector ->Query by attribute", select the input map and enter the name of the output map; select the element type and enter the where clause of the query.
   v.extract input=<map1> output=<map2> type=point layer=1 type=-1 'where ...'
   v.select ainput=<map1> atype=point alayer=1 binput=<map2> btype=area
      blayer=1 output=<map3> operator=overlap
To manage X-monitors: "Config ->X-Monitor" and select the action (start, stop, modify, ...).
  d.mon select=x0
  d.monsize setmonitor=x0 setwidth=700 setheight=500

To digitize a vector map: "Vector ->Develop map ->Digitize"
  v.digit -n map=<new_map> {bgcmd=d.rast raster_map}
this loads the georeferenced TIFF image in a X-monitor. v.digit has a graphical interface with buttons to digitize points, lines, area boundaries, and area centroids. Therefore you need to trace the boundary line between two areas only once.
Among the v.digit settings (second botton from the right) you can pick the colors that highlight different items. The program distinguishes boundaries of one area from those between two areas, lines from boundaries, and so on. Still anomg the settings is the table of attributes. Before digitizing you must define the table of attributes of the elements you digitize. When an element is finished you are prompted to enter its attributes.
Digitizing area borders it may happen that they do not close perfectly well together. You may have to zoom in (left and middle mouse button to select the region of zoom) and move line points (left mouse button to select the point and to specify the new position). Or you may have to split a boundary line in two, in order to join in another boundary.
The vector map digitized in grass can be exported as shapefile and used in the other programs.

To georeference a raster image. First create a temporary location with XY projection and bounds 0 for South and West, the image height for North, and the image width for East. Use a resolution of 1x1 (pixels). You can erase this location afterwards by removing its directory from the Grass data directory.
Next import the image "File ->Import ->Raster map ->Multiple formats using GDAL". You have to select to image file and the name of the raster map in Grass.
  r.in.gdal input=<filename> output=<mapname>
The image is imported as three maps, one for each color, red, green and blue. They are named as "mapname.red" and so on. Therefore you may want to put them together again, "Raster ->Manage map colors ->Create color image from RBG files": select the input maps and the output one. At the end you can remove the three component maps and their group, "File ->Manage maps and volumes ->Remove maps".
  r.composite red=<map.red> green=<map.green> blue=<map.blue> levels=32 output=<mapRGB>
  g.remove rast=<map.red>,<map.green>,<map.blue>
  g.remove group=<map>
Now you want to reproject the image in the XY projection to the projection of the work location. You need to select a few control points (eg, the image corners) and specify their coordinate in the work location. "Image ->Develop images and group ->Create/edit imagery group". You must enter a name for the group and choose the input raster map,
  i.group group=<group_name> input=<mapRGB>
Next assign the location/mapset to the group "Image ->Develop images and group -> Target imagery group",
  i.target group=<group_name> location=DEST mapset=<mapset>
Now it's time to select the control points. This is better done graphically, "Image ->Rectify and georeference image group ->Set ground control points ...". Finally you can georeference the map "Image ->Rectify and georeference image group -> Affine and ...". The extension is appended to the name to form the output map name; the order is the order of the interpolation polynomial (between 1 and 4).
  i.rectify group=<group_name> input=<mapRBG> extension=e order=1
Managing DEM (Digital Elevation Model). Grass can import the SRTM DEM file in hgt format (notice that the input file must be zipped), "File ->Import ->Raster map ->SRTM hgt file"
  r.in.srtm input=<hgt_zipfile> output=map
The SRTM files can have holes. They can be smoothed interpolating the data across the hole, "Raster ->Interpolate surface ->Fill NULL cells ..." and resample the result "Raster ->Develop map ->Resample (change resolution) ..."
  r.fillnulls input=<map> output=<new_map> tension=40 smooth=0.1
  r.resamp.rst input=<new_map> ew_res=0.000003 ns_res=0.000003 elev=elev_fine overlap=3 zmult=1.0 tension=40

5.B.2 QGis

Qgis http://www.qgis.org has a well-organized graphical interface. It is very intuitive, and allows to
The QGis interface has a menu` list and toolbars. Buttins are grouped in sets: File, Layer, Digitize, Navigation, Attributes, Plugins, Help, Label, Grass. The interface is highly configurable through the menu "Settings" (which allows also to sets general program settings).


2D shapefile plan loaded in QGis
Fig. 79. 2D shapefile plan loaded in QGis

It's veru easy to georeference a raster map with QGis. Open the georeference window, "Plugin ->Georeferencing", load the image in the window, "File ->Open raster" or first button on the left, and select the referencing points "Edit /arrow Add point" or seventh button, writing the points coordinates. To select the points accurately zoom in and out and move the image, menu "View" or buttons on the right. When youhave entered enough points, you can georeference the image, "File ->Start georeferncing". You have to set the reference system and the name of the output map.
The digitizing interface is also very simple and intuitive. Select a vector layer and activate the editing (first button on the "Digitize" toolbar): this enables the other buttons, and the "Edit" menu as well. You can edit vector layers. The editing depends on the geometric feature type of the layer: point, line or polygons.
It is unfortunate that QGis is not strictly geometric, so that it requires to trace areas, instead of area boundaries. Therefore one must trace the boundary between two areas twice, Inevitably the two lines are a bit different, and one must zoom in to correct (to the necesary level of accuracy) the discrepancies.

5.B.3 Spatialite

Spatialite http://wwww.gaia-gis.it/spatialite is a spatial database (based on SQlite a file based database), that is a databse with geographical functions of the Open GIS Consortium http://www.opengeospatial.org .
Spataialite can be used from the command line (or even as sqlite3 with the spatialite library is loaded, ".load libspatialite.so"), or with the graphical interface spatialite-gui.
A geographical database is characterized by one (or more) geometry field that contains the geographical informations. For SQlite the geometry is a BLOB. There are seven types of geographical objects, the basic three are POINT, LINESTRING, and POLYGION. The others are MULTI- versions of these and GEOMETRYCOLLECTION.
Main functions (G: geometry, Gp point geometry, Gl line geometry, Ga area geometry)
Geometric analysis functions (there are analogous functions, with name prefixed by MBR, that operate on the bounding boxes (MBR) of the geometries, and are of much faster execution; for example MBRContains)
Utility functions for MBR
Geometric composition functions
Other functions
it is possible to export a table as a shapefile. Here "geotable" is the table to export, "shape_file" is the shapefile name without the extension ".shp", "CP1252" is the codepage (charset), and "type" is the geometric type (POINT, LINESTRING, ...).
  .dumpshp TABLE geotable shape_file CP1252 type
It is not enough to add a column named "Geometry" to make a table spatial. Indeed the name of the geometry column is irrelevant. In order for the database to be geographical two special tables are necessary: the table of reference systems, "spatial_ref_sys", and the table of geometry columns, "geometry_column", which list the columns that contain the geographical informations, and their reference systems These tables are created (and popolated) through a script (available from sptialaite website). The graphical interface does all this when you create a new dabatase. The command to load and execute a script is
  .read script charset
The command to import a shapefile is (here "srid" is the code of the reference system, eg. 32632 for UTM32, and "geom" is the name of the geometry field)
  .loadshp shape_file table CP1252 srid geom


Therion cave-list loaded in spatialite
Fig. 80. Therion cave-list loaded in spatialite

Coordinate conversion. Note that AddGeometryColumn is a function that takes the names of the table, the geometry column, and the type as strings; the other arguments are the SRID code and the dimension.
  SELECT AddGeometryColumn( 'tabella', 'wgs84', 32632, 'POINT', 2 );
  UPDATE tabella set wgs84 = Transform( geom, 32632 );
  SELECT AsText(geom), AsText( wgs84 );
Shapefile and text tables can be loaded also as virtual tables (as such they cannot be modified). Here dsep is the separator of decimals (POINT or COMMA), tsep that of text (DOUBLEQUOTE or SINGLEQUOTE), and fsep the field separator (e.g, ';').
  CREATE VIRTUAL TABLE tabella USING VirtualShape( shape_file, CP1252, 3003 );
  CREATE VIRTUAL TABLE tabella USING VirtualText( file, CP1252, dsep, tsep, fsep);
Three useful SQlite command and other SQL commands (in particular SELECT is a general purpose command to execute functions)

therion users - Wed Apr 13 20:43:05 2011
Prev Up Top Next Contents

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.