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:
- "File". Map management: import, export, list, removal, conversion.
Georeferencing.
- "Config". Program settings, "region" configuration, projections,
and X-monitors.
- "Raster". Map digitization, resampling, query, buffers, analysis tools
and models, editing, surface generation, statistics.
- "Vector". Map digitization, vector item management, query, buffers,
analysis tools, attributes editing, statistics.
- "Imagery". Management and anlysis of images.
- "Grid3D". Creation and menegement do 3D grids.
- "Database". Database connection, management (SQL), table import.
- "Help".
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.
- v.buffer input= output= type=point,line,area buffer=dist
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
- manage projects: "File ->New", "File ->Open", ...
The projects are saves in the directory .qgis
- georeferenfe maps (images): select points and a reference system;
save as geotiff.
- insert layers, either vector or raster. Layers are listed in the layer
panel. Those with the box checked are displayed in the main canvas.
Layer properties (including display properties) can be modified by
clicking on the layer name in the panel. To remove a layer select it
and press Ctrl-D.
- analyse and "compute" with layers, through a library of plugins.
QGis comes with only basic plugins, but a large number of plugins can
be downloaded from internet, and to this aim QGis has a plugin manager
("Pluins" menu).
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).
- File. Projects management
- Edit.
- View. Display, zoom, select, measure
- Layer. Layer management (raster, vector, ...)
- Plugins. Libraries the extend the functionalities of QGis. Most of the
computation is carried out by plugins.
- Raster. Computation of the expressions on ratser maps:
arithmetic, logical, functions etc.
- Vector. Computation on vector maps.1
- Help.
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.
- Add a polygon: activate the relative button and click on the points
of the polygon contour with the left mouse button, end with the right
mouse button. You can interrupt the point selection to move the map
(drag with the "hand" tool) and/or zoom in/out; to continue editing
you need to activate the polygon button and then you resume from where
you left.
- Cut a hole in polygon: menu "Edit ->Add ring" and draw the contour
of the hole as you would draw that of a polygon.
- Move the points of a contour: select the "move point" button, and click
on the contour of the polygon. The point become little red square; click
on the one you want to move (it becomes blue) and drag it to the new
position. If you double click near a point it is splitted into two
effectively inserting a new point in the contour.
- Move a feature as a whole.
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
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)
- real X( Gp )
- real Y( Gp )
- string AsText( G )
- G GeomFromText( 'string' )
- integer Dimension( G )
- integer NumPoints( Gl )
- real GLength( Gl )
- real Area( Ga )
- POINT Centroid( Ga )
- POINT StartPoint( Gl )
- POINT EndPoint( Gl )
- POINT PointN( Gl, n )
- integer NumInteriorRings( Ga )
- LINESTRING ExteriorRing( Ga )
- LINESTRING InterionRingN( Ga, n )
- POLYGON Envelope( G )
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)
- Contains( G1, G2 ) 1 if G1 contains G2
- Disjoint( G1, G2 ) 1 if G1 and G2 are disjoint
- Equal( G1, G2 ) 1 if G1 = G2
- Intersect( G1, G2 ) 1 if G1 and G2 have void intersection
- Within( G1, G2 ) 1 if G1 is contained in G2
- Touches( G1, G2 ) 1 if the intersection is contained in the border
of both G1 and G2
- Overlaps( G1, G2 )
- Crosses( G1, G2 )
- Relates( G1, G2, matrix ) The third argument is a 3x3 matrix of the
intersection between interior, boundary, and exterior of the two geometries
with values T (true), F (false), * (don't care) or 0, 1, 2 (dimension
of the intersection)
Utility functions for MBR
- BuildMBR( x1, y1, x2, y2, geom )
- BuildCircleMBR( x, y, radius )
Geometric composition functions
- Intersection( G1, G2 ) = G1 AND G2
- Difference( G1, G2 ) = G1 AND NOT G2
- GUnion( G1, G2 ) = G1 OR G2
- SymDifference( G1, G2 ) = G1 XOR G2
Other functions
- real Distance( G1, G2 )
- POLYGON ConvexHull( G )
- Buffer( G, radius )
- Symplify( G, tolerance )
- SymplifyPreserveTopology( G, tolerance )
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
- name of the table containing the geometry
- name of the geometry column
- geometry type (POINT, LINESTRING, POLYGON, etc.)
- dimension of the geometry (2 per POINT, LINESTRING, POLYGON)
- SRID code (eg, for Italy, 32632 for UTM32, 3003 for Gauss Boaga)
- spatial_index_enabled
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
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)
- .nullvalue NULL
- .headers on
- .mode column
- BEGIN
- COMMIT
- ROLLBACK
- VACUUM
- ANALYZE
- SELECT t1.f1, t2.f2 AS 'header' FROM t1,t2 WHERE t1.f2 = t2.f2
- SELECT f1 AS 'campo 1', f2 AS 'campo 2' FROM tabella ORDER BY f2 DESC LIMIT 5
- SELECT t1.f1, t2.f2 FROM t1, t2 GROUP BY t1.f1
- SELECT t1.f1, t2.f2 FROM t1, t2 WHERE t1.f1 IN ('a', 'b', ... ) AND t1.f2 = t2.f2
- SELECT DISTINCT ...
- PRAGMA table_info( tabella )
- CREATE TABLE t1( f1 TEXT NOT NULL, geom BLOB NOT NULL)
- INSERT INTO t1(f1,geom) VALUES ('uno', GeomFromText('POINT(1,2)'))
- CREATE TABLE t1 AS SELECT * FROM t2 WHERE ...
- INSERT INTO t1(f1,f2,f3) SELECT a,b,c FROM t2 WHERE ...
- UPDATE t1 SET f1 = ... WHERE ...
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.