Нефть и песок О стали Компрессор - подбор и ошибки Из истории стандартизации резьб Соперник ксерокса - гектограф Новые технологии производства стали Экспорт проволоки из России Прогрессивная технологическая оснастка Цитадель сварки с полувековой историей Упрочнение пружин Способы обогрева Назначение, структура, характеристики анализаторов Промышленные пылесосы Штампованные гайки из пружинной стали Консервация САУ Стандарты и качество Технология производства Водород Выбор материала для крепежных деталей Токарный резец в миниатюре Производство проволоки Адгезия резины к металлокорду Электролитическое фосфатирование проволоки Восстановление корпусных деталей двигателей Новая бескислотная технология производства проката Синие кристаллы Автоклав Нормирование шумов связи Газосварочный аппарат для тугоплавких припоев
Главная --> Промиздат -->  Map principle 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 ( 88 ) 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127


irestore old MASK, if present

g.remove MASK > /dev/null

g.rename rast=$TMP.MASK,MASK 2> /dev/null

This script shows how UNIX commands and GRASS modules can be linked. It also provides a simple parser (through g.parser), so the script will both run both in the command line mode, and, when started without parameters, in interactive mode. The first test checks if the module is started within GRASS, and exits if it is not. The usage description is stored in a function to save space within the script and to improve the legibility.

With g.parser a simple parser is provided to query input maps. Here a raster map such as a watershed or other raster area map are of interest. The module checks if the user requested the module help description or otherwise accepts the first parameter as raster file name. Then the ID number of the raster polygon is checked (which might be queried with d.what.rast earlier). This is followed by the centroid calculation according to the centroid formula. The calculation requires the area of the current raster polygon which is retrieved from r.report. Additionally the current resolution is needed. In case that MASK is present, it will be saved and later restored. This is necessary, as the area of interest has to be selected inside the input raster map with a new MASK. To see the r.centroid script operating on Spearfish region data, you may run:

tcalculate watershed (minimum area size: 1000 cell units): g.region rast=elevation.dem -p

r.watershed elevation=elevation.dem basin=basins threshold=1000 d.rast basins

♦calculate area and centroid coordinates for watershed no. 42: r.centroid map=basins areanumber=42

# display centroid of watershed no. 42,

# coordinates from above r.centroid:

echo 593934.29 4918883.74 42 I s.in.ascii sites=grav center d.sites grav center col=red

Generally you may face the problem that a script is not working as expected. To identify problem(s), you can add printing of variable contents



with echo $VARIABLE. An alternative, recommended method to debug shell scripts is to start them with -x flag. This will switch the shell into an echo-mode:

sh -X r.centroid map=basins areanumber=42

This will echo every line in the terminal window which simplifies error identification.

Further scripts are described in Albrecht, 1992 and Shapiro and Westervelt, 1992. Plenty of scripts to learn from are included in GRASS (from inside GRASS change to $GISBASE/scripts/).

11.3. AUTOMATED USAGE OF GRASS

Due to the modular character of GRASS a monolithic GRASS program does not exist. In fact GRASS is a collection of modules which are run in a special environment. The structure allows GRASS to be completely controlled from outside through scripts.

GRASS in batch mode. The usage of GRASS in batch mode requires setting of some environment variables, which can be also done manually or in scripts. An example in bash-shell style may be as follows:

echo L0CATI0N NAME: spearfish > $H0ME/.grassrc5

echo MAPSET: userl >> $HOME/.grassrc.i

echo DIGITIZER: none >> $HOME/.grassrc5

echo GISDBASE: /usr/local/share/grassdata >> $HOME/.grassrc.i

echo GRASS GUI: text >> $HOME/.grassrc5

export GISBASE=/usr/local/grass53

export GISRC=$H0ME/.grassrc.5

export PATH=$PATH:$GISBASE/bin;$GISBASE/scripis

After setting these variables, the environment is defined and all GRASS modules can be used. Note that GRASS 5.3 allows the user to run only a single session at a time. Otherwise region setting conflicts may arise. However, the user can work in multiple session in the same LOCATION, when using different MAPSETs. The module-specific environment variables are further explained in the software documentation, check with:

g.manual env vars



Once the minimum number of environment variables has been set, GRASS commands can be integrated into shell, CGI, PERL, PHP and other scripts. A CGI-based example to build a mapping server on top of GRASS is SlideLinks 3 on Internet which also integrates PHP and a PostgreSQL database management system for landslide inventory. From time to time it is recommended to remove temporary GRASS files by:

$GISBASE/etc/clean temp

Automated generating of a LOCATION from external raster data. A

nice application for running GRASS in batch mode is the automated generating of locations from external GIS raster data. We use r.in.gdal for this purpose as the module supports many formats and it can also read projections from metadata if provided:

if./bin/sh

# This pmgram is Free Software under the GNU GPL (>=v2). t create a new LOCATION from a raster data set

variables to customize:

GISB ASE=/usr/local/grass.5 3

GISDBASE=/usr/Iocal/share/grassdata

MAP=$1

LOCATION=$2

#nothing to change below: if [ $# - 2 I ; then

echo Script to create a new LOCATION from a raster data set

echo Usage:

echo create location.sh rasterfile location name exit 1 fi

generate temporal LOCATION: TEMPDIR=$$.tmp

mkdir -p $GISDBASE/$TEMPDIR/temp

#save existing $H0ME/.grassrc5 if test -e $H0ME/.grassrc5 ; then

mv $H0ME/.grassrc5 /tmp/$TEMPDIR.grassrc5

echo L0CATI0N NAME: $TEMPDIR > $H0ME/.grassrc5

>> $H0ME/.grassrc5 >> $H0ME/.grassrc5 $HOI\/IE/.grassrc5

echo MAPSET: temp echo DIGITIZER: none echo GISDBASE: $GISDBASE export GISBASE=$GISBASE export GISRC=$H0ME/.grassrc5 export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 ( 88 ) 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127