Geoprocessing
Geoprocessing with
with GRASS
GRASS
Geoprocessing with GRASS
Paolo Zatelli
Dipartimento di Ingegneria Civile e Ambientale
Università di Trento
Paolo Zatelli | Università di Trento |
1/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
Combination of vector features
The combination of vector features is used to create new geometric
features with:
●
overlay of maps with logical operations;
●
patch of maps;
●
selection of overlapping geometric features;
●
evaluation of the distance between features and creation of the
minimum length segments;
●
creation of points and segments along lines;
●
creation of buffers around points, lines and areas.
Paolo Zatelli | Università di Trento |
2/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
Combination of areas with areas, lines and points
The combination of areas with areas, lines and points is done by:
●
●
●
●
overlay: creates new maps by combining geometric features using
AND, OR, XOR e NOT Boolean operators;
patch of maps: joins features from different maps, overlapping is
allowed;
select: selects geometric features, without creating new ones;
dissolving: merges features with the same category (or attribute)
into one single feature.
Paolo Zatelli | Università di Trento |
3/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
Buffer
Buffering consists in the creation of areas around features (points,
lines and areas) with shapes similar to the feature, usually larger:
●
●
●
with constant width (with respect to two given directions);
with width dependent on category (width is usually read from a
column of the table associated to the map);
with different widths on the right and left sides, with respect to the
lines' o boundaries' direction.
Paolo Zatelli | Università di Trento |
4/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
Other operations on vector features
Other operations combine vector features (point, lines and areas):
●
evaluation of distances between points and other features (points,
lines and areas), optionally creating vector segments representing
the minimum distance;
●
creation of points and segments along lines;
●
splitting of lines into segments;
●
evaluation of geometric features (length, area, etc.) for entities
and uploading them to their tables.
Paolo Zatelli | Università di Trento |
5/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
GRASS' modules
GRASS' modules for geoprocessing are:
● v.extract – extracts vector features from maps according to their
category or to a SQL query on their table;
● v.overlay – combines areas with points, lines and areas using
Boolean operator (AND, OR, XOR e NOT);
● v.patch – “sums” maps overlaying their features;
● v.select – selects (without modifying them) features in a map
overlapping features in another map;
● v.buffer – creates buffers around features;
● v.parallel – creates lines parallel to lines in a map.
Paolo Zatelli | Università di Trento |
6/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
GRASS's modules
Other GRASS' modules for geoprocessing:
● v.to.db
– evaluates, and optionally upload to a table, some
geometric features (length, area, etc.);
● v.distance – evaluates distances between point and other features
(points, lines and areas), optionally creating vector segments
representing the minimum distance;
● v.to.points – creates points along lines, with given mutual distance;
● v.segment – creates points and segments along lines, with a given
distance from the starting point;
● v.split – splits lines into segments.
Paolo Zatelli | Università di Trento |
7/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
Common modules' features
Some features are common for the GRASS' modules, because
they use the same GRASS vector library:
● modules
do not overwrite existing maps, unless the
--overwrite option is specified;
● it is possible to choose the type of feature (point, line,
boundary, centroid, area, face) to process in the input map;
● it is possible to choose the layer for categories (thus for the
table).
Paolo Zatelli | Università di Trento |
8/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.extract
extracts vector features from maps according to their category or to a SQL query on
their table
The syntax is:
v.extract [-dtrovq] input=name output=name [type=string[,string,...]] [layer=value]
[list=range] [where=sql_query] [file=name] [random=value] [new=value] [-overwrite] [--verbose] [--quiet]
flags:
-d Dissolve common boundaries (default is no), -t Do not copy table (see also 'new' parameter)
-r Reverse selection, --o Allow output files to overwrite existing files
--v Verbose module output, --q Quiet module output
Parameters:
input
Name of input vector map
output Name for output vector map
type
Types to be extracted (point,line,boundary,centroid,area,face)
layer
Layer number (if -1, all features in all layers of given type are extracted) default: 1
list
Category values (list of the categories to be extracted)
where WHERE conditions of SQL statement without 'where' keyword
file
Input text file with category numbers/number ranges to be extracted
random Number of random categories matching vector objects to extract
new
-1 to keep original categories or the desired NEW category value.
If new >= 0, table is not copied, default: -1
Paolo Zatelli | Università di Trento |
9/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.extract
Example:
v.extract input=fields@PERMANENT output=fields_mitchell type=area layer=1
new=-1 where="label='C. Mitchell#1' OR label='C. Mitchell#2' OR label='C.
Mitchell#3' OR label='C. Mitchell#4' OR label='C. Mitchell#5' OR label='C.
Mitchell#6'"
extracts fields owned by C. Mitchell from the fields map.
v.extract input=soils@PERMANENT output=soils_GBE type=area layer=1 new=-1
where="label='GBE'"
extracts areas with GBE soil type from the soils map.
Paolo Zatelli | Università di Trento |
10/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.extract
Paolo Zatelli | Università di Trento |
11/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.extract
Example with dissolve:
v.extract input=fields@PERMANENT output=fields_mitchell_dissolve
type=point,line,boundary,centroid,area,face layer=1 new=1 where="(label='C.
Mitchell#1') OR (label='C. Mitchell#2') OR (label='C. Mitchell#3') OR
(label='C. Mitchell#4') OR (label='C. Mitchell#5') OR (label='C.
Mitchell#6')" -d
extracts fields owned by C. Mitchell from the fields map and create an unique
area with category 1.
Paolo Zatelli | Università di Trento |
12/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
no dissolve
Paolo Zatelli | Università di Trento |
dissolve
13/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.overlay
combines areas with points, lines and areas using Boolean operator (AND, OR,
XOR e NOT).
The syntax is:
v.overlay [-t] ainput=name [atype=string[,string,...]] [alayer=integer] binput=name
[btype=string[,string,...]]
[blayer=integer]
output=name
[operator=string]
[olayer=integer[,integer,...]] [--overwrite] [--verbose] [--quiet]
flags:
-t Do not create attribute table, --o allow output files to overwrite existing files
--v verbose module output, --q quiet module output
Parameters:
ainput Name of input vector map (A)
atype
Feature type (line, area) (vector map A), default: area
alayer Layer number (vector map A), default: 1
binput Name of input vector map (B)
btype
Feature type (area) (vector map B), default: area
blayer Layer number (vector map B), default: 1
output Name for output vector map
operator Operator (and, or, not, xor), default: or
olayer Output layer for new category, ainput and binput, default: 1, 0, 0
Paolo Zatelli | Università di Trento |
14/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.overlay
AND operator (intersection):
v.overlay ainput=uno atype=area alayer=1 binput=due btype=area blayer=1
output=test_and operator=and olayer=1,0,0
Paolo Zatelli | Università di Trento |
15/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.overlay
OR operator (union):
v.overlay ainput=uno atype=area alayer=1 binput=due btype=area blayer=1
output=test_or operator=or olayer=1,0,0
Paolo Zatelli | Università di Trento |
16/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.overlay
XOR (eXclusive OR) operator:
v.overlay ainput=uno atype=area alayer=1 binput=due btype=area blayer=1
output=test_xor operator=xor olayer=1,0,0
Paolo Zatelli | Università di Trento |
17/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.overlay
NOT operator:
v.overlay ainput=uno atype=area alayer=1 binput=due btype=area blayer=1
output=test_not operator=not olayer=1,0,0
Paolo Zatelli | Università di Trento |
18/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.patch
combines features from different maps (two or more) into a new map.
The syntax is:
v.patch [-ae] input=string[,string,...] output=string [bbox=name] [--overwrite] [-verbose] [--quiet]
flags:
-a Append files to existing file (overwriting existing files must be activated)
-e Copy also attribute table
Only the table of layer 1 is currently supported
--o Allow output files to overwrite existing files
--v Verbose module output, --q Quiet module output
Parameters:
input
Name of input vector map(s)
output Name for output vector map
bbox Name for output vector map where bounding boxes of input vector maps are written to
Paolo Zatelli | Università di Trento |
19/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.patch
v.patch input=uno,due output=test_patch -e
Paolo Zatelli | Università di Trento |
20/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.select
selects (without modifying them) features in a map overlapping
features in another map.
The syntax is:
v.select [-tr] ainput=name [atype=string[,string,...]] [alayer=value] binput=name
[btype=string[,string,...]] [blayer=value] output=name [operator=string] [--overwrite]
[--verbose] [--quiet]
flags:
-t Do not create attribute table, -r Reverse selection
--o Allow output files to overwrite existing files, --v Verbose module output
--q Quiet module output
Parameters:
ainput
atype
alayer
binput
btype
blayer
output
operator
Name of input vector map (A)
Feature type (point,line,boundary,centroid,area) (vector map A)
Layer number (vector map A), default: 1
Name of input vector map (B)
Feature type (point,line,boundary,centroid,area) (vector map B)
Layer number (vector map B), default: 1
Name for output vector map
Operator defines required relation between features (overlap)
Paolo Zatelli | Università di Trento |
21/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.select - areas
v.select ainput=soils atype=area alayer=1 binput=fields_mitchell btype=area
blayer=1 output=soils_mitchell_select operator=overlap
Paolo Zatelli | Università di Trento |
22/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.select - lines
v.select ainput=roads atype=line alayer=1 binput=fields_portillo1 btype=area
blayer=1 output=roads_portillo_select operator=overlap
Paolo Zatelli | Università di Trento |
23/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.buffer
creates buffers around features
The syntax is:
v.buffer [-sc] input=name output=name [type=string[,string,...]] [layer=value]
[distance=value]
[minordistance=value]
[angle=value]
[bufcolumn=name]
[scale=value] [tolerance=value] [--overwrite] [--verbose] [--quiet]
flags:
-s Make outside corners straight, -c Don't make caps at the ends of polylines
--o Allow output files to overwrite existing files, --v Verbose module output
--q Quiet module output
Parameters:
input
Name of input vector map
output
Name for output vector map
type
Feature type (point,line,boundary,centroid,area)
layer
Layer number, default: 1
distance
Buffer distance along major axis in map units
minordistance Buffer distance along minor axis in map units
angle
Angle of major axis in degrees, default: 0
bufcolumn Name of column to use for buffer distances
scale
Scaling factor for attribute column values, default: 1.0
tolerance
Maximum distance between theoretical arc and polygon segments
as multiple of buffer, default: 0.01
Paolo Zatelli | Università di Trento |
24/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.buffer - lines
v.buffer input=streams_new output=streams_buffer_line type=line layer=1
distance=200 scale=1.0 tolerance=0.01
Paolo Zatelli | Università di Trento |
25/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.buffer - areas
v.buffer input=streams_new output=streams_buffer_area type=area layer=1
distance=300 scale=1.0 tolerance=0.01
Paolo Zatelli | Università di Trento |
26/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.buffer – widhts from table
v.buffer input=streams_new output=streams_buffer_db_line type=line layer=1
bufcolumn=buffer scale=1.0 tolerance=0.01
Paolo Zatelli | Università di Trento |
27/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.buffer – along major axis
v.buffer --overwrite --verbose input=line1 output=line_major distance=100
Paolo Zatelli | Università di Trento |
28/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.buffer – along minor axis
v.buffer --overwrite --verbose input=line1 output=line_minor distance=1
minordistance=100
Paolo Zatelli | Università di Trento |
29/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.buffer – 45° rotation of axes
v.buffer --overwrite --verbose input=line1 output=line_minor distance=1
minordistance=100 angle=45
Paolo Zatelli | Università di Trento |
30/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.parallel
creates lines parallel to lines in a map.
The syntax is:
v.parallel [-rb] input=name output=name distance=value [minordistance=value]
[angle=value] side=string [tolerance=value] [--overwrite] [--verbose] [--quiet]
flags:
-r Make outside corners round, -b Create buffer-like parallel lines
--o Allow output files to overwrite existing files, --v Verbose module output
--q Quiet module output
Parameters:
input
Name of input vector map
output
Name for output vector map
distance
Offset along major axis in map units
minordistance Offset along minor axis in map units
angle
Angle of major axis in degrees, default: 0
side
Side (left, right, both), default: right. left: Parallel line is on the left;
right: Parallel line is on the right; both: Parallel lines on both sides
tolerance Tolerance of arc polylines in map units
Paolo Zatelli | Università di Trento |
31/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.parallel
v.parallel input=streams_new output=streams_right side=right distance=100
v.parallel input=streams_new output=streams_left side=left distance=300
Paolo Zatelli | Università di Trento |
32/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.to.db
evaluates, and optionally upload to a table, some geometric features
(length, area, etc.).
The syntax is:
v.to.db [-psc] map=name [type=string[,string,...]] [layer=value] [qlayer=value] option=string
[units=string] [column=name[,name,...]] [qcolumn=name] [--verbose] [--quiet]
flags:
-p Print only, -s Only print SQL statements
-c In print mode prints totals for options: length,area,count
--v Verbose module output, --q Quiet module output
Parameters:
map Name of input vector map
type Feature type (point,line,boundary,centroid)
layer Layer number (write to), default: 1
qlayer Query layer number (read from), default: 1
Paolo Zatelli | Università di Trento |
33/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.to.db
continue
option Value to upload (cat, area, compact, fd, perimeter, length, count, coor, start, end,
sides, query, slope, sinuous)
cat: insert new row for each category if doesn't exist yet
area: area size
compact: compactness of an area, calculated as
compactness = perimeter / (2 * sqrt(PI * area))
fd: fractal dimension of boundary defining a polygon, calculated as
fd = 2 * (log(perimeter) / log(area))
perimeter: perimeter length of an area
length: line length
count: number of features for each category
coor: point coordinates, X,Y or X,Y,Z
start: line/boundary starting point coordinates, X,Y or X,Y,Z
end: line/boundary end point coordinates, X,Y or X,Y,Z
sides: categories of areas on the left and right side of the boundary, 'qlayer' is used for
area category
query: result of a database query for all records of the geometry(or geometries) from
table specified by 'qlayer' option
slope: slope steepness of vector line or boundary
sinuous: line sinuousity, calculated as line length / distance between end points
units Units - mi(les),f(eet),me(ters),k(ilometers),a(cres),h(ectares)
columns Name of attribute column(s)
qcolumn Name of attribute column used for 'query' option
Paolo Zatelli | Università di Trento |
34/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.to.db
v.to.db map=streams_new type=point,line,boundary,centroid layer=1 qlayer=1
option=length units=me column=lenght -p
gives:
cat|length
-1|2426.08071449311
1|32614.5522076325
2|183157.29968834
3|3458.83045471837
421|0
the total length for each line category.
Paolo Zatelli | Università di Trento |
35/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.distance
evaluates distances between point and other features (points, lines and areas),
optionally creating vector segments representing the minimum distance.
The syntax is:
v.distance
[-pa]
from=name
to=name
[from_type=string[,string,...]]
[to_type=string[,string,...]] [from_layer=value] [to_layer=value] [output=name]
[dmax=value] [dmin=value] upload=string[,string,...] column=name[,name,...]
[to_column=name] [table=name] [--overwrite] [--verbose] [--quiet]
flags:
-p Print output to stdout, don't update attribute table.
-a Calculate distances to all features within the threshold. The output is written to stdout
but may be uploaded to a new table created by this module.
--o Allow output files to overwrite existing files. --v Verbose module output
--q Quiet module output
Parameters:
from
to
from_type
to_type
from_layer
to_layer
output
Name of existing vector map (from)
Name of existing vector map (to)
Feature type (point,centroid) (from), default: point
Feature type (point,line,boundary,centroid,area) (to), default: point,line,area
Layer number (from), default: 1
Layer number (to), default: 1
Name for output vector map containing lines connecting nearest elements
Paolo Zatelli | Università di Trento |
36/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.distance
continue
dmax Maximum distance or -1 for no limit, default: -1
dmin
Minimum distance or -1 for no limit, default: -1
upload Values describing the relation between two nearest features
options: cat, dist, to_x, to_y, to_along, to_angle, to_attr
cat: category of the nearest feature
dist: minimum distance to nearest feature
to_x: x coordinate of the nearest point on 'to' feature
to_y: y coordinate of the nearest point on 'to' feature
to_along: distance between points/centroids in 'from' map and the linear
feature's start point in 'to' map, along this linear feature
to_angle: angle between the linear feature in 'to' map and the positive x axis,
at the location of point/centroid in 'from' map, counterclockwise, in
radians, which is between -PI and PI inclusive
to_attr: attribute of nearest feature given by to_column option
column Column name(s) where values specified by 'upload' option will be uploaded
to_column Column name of nearest feature (used with upload=to_attr)
table
Name of table created for output when the distance to all (-a) flag is used
Paolo Zatelli | Università di Trento |
37/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.distance – points and areas
v.distance from=archsites_not_natfor_fields to=bugsites_natfor
from_type=point to_type=point,line,area from_layer=1 to_layer=1
output=archsites_not_natfor_dist dmax=-1 upload=dist column=dist -p
Paolo Zatelli | Università di Trento |
38/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.distance – points and lines
v.distance from=archsites@PERMANENT to=roads@PERMANENT
output=archistes_to_roads from_type=point to_type=point,line,area
from_layer=1 to_layer=1 dmax=-1 upload=dist column=dist
Paolo Zatelli | Università di Trento |
39/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.to.points
creates points along lines, with given mutual distance.
The syntax is:
v.to.points [-nvit] input=name output=name [type=string[,string,...]] [llayer=value]
[dmax=value]
flags:
-n Write line nodes, -v Write line vertices
-i Interpolate points between line vertices, -t Do not create attribute table
--o Allow output files to overwrite existing files
--v Verbose module output, --q Quiet module output
Parameters:
input Input vector map containing lines
output Output vector map where points will be written
type
Feature type (point,line,boundary,centroid,area)
llayer Layer number, default: 1
dmax Maximum distance between points in map units, default: 100
The table of the input map is connected on the first layer of the output
map, a table containing the category of the underlying line for each point
and the progressive distance from the line's starting point is connected
on the second layer.
Paolo Zatelli | Università di Trento |
40/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.to.points
v.to.points input=railroads@PERMANENT type=point,line,boundary,centroid
output=railroads_points llayer=1 dmax=1000
Paolo Zatelli | Università di Trento |
41/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.to.points – with vertexes
v.to.points input=railroads@PERMANENT type=point,line,boundary,centroid
output=railroads_points llayer=1 dmax=1000 -v
Paolo Zatelli | Università di Trento |
42/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.segment
creates points and segments along lines, with a given distance from the starting
point.
The syntax is:
v.segment input=name output=name [llayer=value] [file=name] [--overwrite] [-verbose] [--quiet]
--o Allow output files to overwrite existing files
--v Verbose module output, --q Quiet module output
Parameters:
input Name of input vector map containing lines
output Name for output vector map where segments will be written
llayer Line layer, default: 1
file
Name of file containing segment rules. If not given, read from stdin.
The position of points and segment is given on the stdin:
P <point id> <line cat> <offset> [<side offset>]
L <segment id> <line cat> <start offset> <end offset> [<side offset>]
echo "L 2 1 2000 3000"|v.segment input=railroads output=railroads_segment_line llayer=1
echo "P 1 1 1000"|v.segment input=railroads output=railroads_segment_point llayer=1
Paolo Zatelli | Università di Trento |
43/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.segment
echo "P 1 1 1000"|v.segment input=railroads output=railroads_segment_point
llayer=1
echo "L 2 1 2000 3000"|v.segment input=railroads output=railroads_segment_line
llayer=1
Paolo Zatelli | Università di Trento |
44/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.split
splits lines into segments.
The syntax is:
v.split input=name output=name [length=value] [vertices=value]
Flags:
--o Allow output files to overwrite existing files
--v Verbose module output
--q Quiet module output
Parameters:
input
Name of input vector map
output
Name for output vector map
length
Maximum segment length.
vertices
Maximum number of vertices in segment.
The vertices parameter sets the maximum number of consecutive vertexes of the
input line that each segment can contain (2=only straight segments).
Paolo Zatelli | Università di Trento |
45/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
v.split
v.split input=railroads output=railroads_split_num vertices=10
Paolo Zatelli | Università di Trento |
46/47
Geoprocessing
Geoprocessing with
with GRASS
GRASS
License
This presentation is © 2009 Paolo Zatelli, available as
Paolo Zatelli | Università di Trento |
47/47
Scarica

Geoprocessing with GRASS - Università degli Studi di Trento