path finding in hazad terrain

42
Bar Ilan University Path Finding in Hazard Terrain Final Project for M.Sc in computer science, Artificial Intelligence Oren Koler 2/24/2014

Upload: oren-koler

Post on 14-Apr-2017

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Path Finding In Hazad Terrain

Bar Ilan University

Path Finding in Hazard Terrain

Final Project for M.Sc in computer science, Artificial Intelligence

Oren Koler2/24/2014

Page 2: Path Finding In Hazad Terrain

Table of ContentsIntroduction........................................................................................................................................................1

Creating Cost layers...........................................................................................................................................7Project scripts...................................................................................................................................................17

Abstract In the last years, Unmanned Vehicles have become more and more popular for border patrol. UMV’s can patrol hazard’s border lines without the danger of soldiers getting killed. The fact the vehicles are unmanned allows its design to be more maneuverable in rough terrains. This flexibility allows us to create newer strategies for patrol. Observation points can be deeper in enemy lines and more dynamic. New points can be found every once and a while with new routes connecting them. This project shows how to find observation points and the routes between them for real terrain, based on real data sources which are used in the army.The project is designed for a patrolling unit that is given observation areas to watch. According to those areas and the terrain surface, it chooses its observation points and moves between them in an optimal manner.

IntroductionIt is common that when searching for a path between two points, the solution would be to use the A* algorithm for path finding. Indeed this is a very useful algorithm that can find a path in a given graph of points with edges connecting them with different weights. But in an open 3D environment (for instance in the regions of North Carolina), this graph does not exist. By using means of terrain analysis it is possible to create this graph for the A* algorithm by first finding the points of the graph and secondly, finding the weights and routes between them.When using terrain analysis, it is possible to give every pixel on the map a cost value. This value represents the cost for stepping on this x,y coordinate location. The cost can be based on many strategically features, for instance: height, cover, slope, terrain type etc.A path can be found between points based on the sum of costs from moving on the map “pixels” using the A* algorithm. A strategic location value can be based on a “pixels” height and its view shed but can also take into account its distance from a road for example.

Main Objectives1. Create a tool for finding strategic observation points2. Create a tool for finding routes between those points in hazard’s terrain

Basic conceptBy using the raw data accessible these days (for instance road maps and elevation maps), I can create for each type of data a cost layer. A cost layer is a colored map where each pixels value represents the effective cost for “stepping” on that pixel (specific for that data type). For instance, given 2 types of data, an elevation map (DTM) and a road map. The final result of terrain analysis of these two types of data would create different colored layers. A certain pixel in the elevation layer could have a low value because its height is low, but that same location in the roads layer would get a high value because is location is very close to a main road.I will further explain for each data type the method for creating its cost layer. All the layers have values from 0 to 100 where a location with a low value means that stepping on that location is cheap and therefore preferred.After creating all the initial cost layers (as many layers as needed). The layers are summed together according to their suggested importance. Each layer is multiplied by a percentage, the more the percentage is, the higher its importance and the more effect it will have on the final path finding.

1

Page 3: Path Finding In Hazad Terrain

All the percentages sum up to 100. The final cost layer will hold values between 0 and 100 were location of null value represent location that can’t be stepped on, like lakes or houses.

The tools for creating observation points and routes need to do initial terrain analysis on the raw data, but after finished, finding the observation points and routes between them take a short amount of time. It is possible to update observation points manually and start the path finding process. As long as the basic cost layers don’t change (and there is no reason why they should), the update time will be fast.

Hazard terrainThere are two hazards a patrolling vehicle needs to be aware of. Short range RPG units (ranges up to 200 meters). And IED’s (improvised explosive device) placed along the routes.

The IED hazardSince this project does not deal in detecting IED or maneuvering around them, the simple solution would be to detect the enemy unit placing the IED on the route. Also changing the observation points and there routes occasionally would prevent from the enemy units from knowing the UAV’s patrol routes. Another effort would be to search for paths between points that are not on easy terrains like roads – these will allow a larger spectrum of unpredictable routes to be chosen and finally the UAV can move along a route with some random offset, in doing so, it won’t be near the charge when it runs along a previous used route.The Path finding algorithm also prefers “stepping” on location that can be watched from the observation points this would also make it hard for enemy units to place an IED without being detected.

The RPG unit hazardThe Anti-tank units are most likely to hide in proximity to a patrol route and wait for an ambush. A unit hiding in the edge of a forest will not be detected and could easily escape after fire, hence patrolling routes should stay away from forests (at least 200 meters), and the same goes to urban areas. The path planning algorithm also prefers moving on high ground since it will have more field of view the higher it is and by so have a bigger chance in detecting an enemy unit.

About Grass 7.0

The application that I used for terrain analysis is Grass (version 7). The GRASS GIS project is an international team effort with scientists and developers participating from various fields. GRASS -Geographic Resources Analysis Support System has been under continual development since 1982 and has involved a large number of federal US agencies, universities, and private companies. The core components of GRASS and the management of the integration of the efforts into GRASS releases were accomplished by the Construction Engineering Research Laboratory (CERL) in Champaign, Illinois. It has been estimated that several million dollars of GRASS GIS software development efforts across the government have been completed since the 4.1 release. Since 1997 a worldwide network of developers continue to release new GRASS GIS versions.

GRASS (Geographic Resources Analysis Support System) is a free and open source Geographic Information System (GIS) software suite used for geospatial data management and analysis, image processing, graphics and map production, spatial modeling, and 3D visualization. GRASS GIS is currently used in academic and commercial settings around the world, as well as by many governmental agencies and environmental consulting companies. GRASS GIS can be used either as a stand-alone application or as backend for other software packages such as QGIS and R geo statistics. It is a founding member of the Open Source Geospatial Foundation.

Project inputs and outputs1. Input

a. DTM map (digital terrain model ) in high resolution (1 meter pixel) in geotif formatb. Vector data containing terrain data: Roads, Forests, Soil types, Observation areas

2

Page 4: Path Finding In Hazad Terrain

Figure 1 example of DTM

c. Initial parameters i. Number of wanted observation points

ii. Distribution importance between cost layers. ( for instance: height importance: 50%, road importance 25%, forest importance: 25%, total sum is 100% )

iii. Max allowed slope2. Output

a. A vector layer with observation points.b. A vector layer with routes between the observation points and there costc. All the cost layers that were created on the wayd. Possible to even estimate fuel consumption

3. Basic Requirementsa. Tool must use unclassified raw materialsb. Tool can only be based on free productsc. Tool must be unclassified ( not related to an army project)

Project installationThe installation is composed of three stages. Grass 7 installation, North California data base installation and coping project scripts into script directory.

Grass 7 is open source; meaning its source code can be downloaded and compiled. This project does not require that. The installation instructions for windows are found in this linkhttp://grass.osgeo.org/download/software/ms-windows/The grass directory needs to be placed as followed C:/GRASS7 since some scripts are based on this location. (This is important only for the project scripts and not for grass7; the scripts can be manually changed according to where grass7 was installed)

3

Page 5: Path Finding In Hazad Terrain

Figure 2 Web page for grass7 installation

The demo data base, north California can be found and downloaded in this link;http://grass.osgeo.org/download/sample-data/

Figure 3 Web page for North Carolina DB

All the shell scripts created for this project can be found in this document. The scripts need to be placed in the grass 7 script directory ..\GRASS7\scripts.

4

Page 6: Path Finding In Hazad Terrain

The Geo data base I chose to use a demo geo data base that is given with grass 7 called North Carolina. The data base has a variety of raster maps and vector data. The maps are in high resolution, varying from 10 meters to 1 meter (per pixel). There are road maps, streams, lakes, soil types and more, all unclassified.The elevation map I chose was: EL_D783_6m, this map has a good resolution and covers a large area (about 9 square kilometers). It has 500 rows & columns; its projection is Lambert Conformal Conic| sadsdcolumnscolumns, ProjectionN: 225552.45109601 S: 222504.445 Res: 6.09601219שדגE: 637033.27409601 W: 633985.268 Res: 6.09601219 |Range of data: min = 87.6681 max = 146.778

Figure 4 Used data layers

Working with grassWhen opening grass, you are asked to choose a project and a mapset. The project is the database. in this project its North Carolina. A map set defines which kinds of data to show, in this project the Permanent map set shows the elevation map and vector data used later in the project.

5

Page 7: Path Finding In Hazad Terrain

Figure 5 Grass7 starting window

The workspace can be saved as a .gxw file which saves all the layers currently shown. It is possible to import other sources of data and save them in the grass data base. It is also possible to export any layer to any world known format.

Grass is built from hundreds of modules, each module is a tool written in python(.py) or shell(.sh).The modules are listed in the module tab. They can run on the background allowing you to keep on working. On the terrain I worked on (relatively small), it took a module only a few seconds to run.

6

Page 8: Path Finding In Hazad Terrain

Figure 6 Grass module tab

Each module has its own window dialog for entering parameters. The modules can be run with Shell scripts in the command console tab. To run a script you need to type “sh myScript.sh”. It is recommended to type the full path of the scripts location: “sh c:\Temp\myScript.sh”For further knowledge on writing shell grass scripts:http://grasswiki.osgeo.org/wiki/Shell_scripting

Figure 7 Grass command console tab

7

Page 9: Path Finding In Hazad Terrain

Creating Cost layersEach cost layer is based on different raw data and is created in a different manner. Each pixel is given a value based on a procedure running on the raw data (some are given a null value).Afterword’s the cost layer values are stretched or shrunk to be between 0 & 100 by using a linear function. A low value in a location/pixel means that the cost for stepping on it is low.The algorithms that create these layers are programmed in shell (a basic script language that is used in grass).

Creating soil layerThe North Carolina Center for Geographic Information and Analysis (NCCGIA) department has a catalog of all its soil types in the region. The types are categorized in there document: SoilsMetadata.doc. The soil types are geographically mapped in the soil_wake layer. The DSL field (digital soil) holds the soil type.

For the experiment purposes the soil types were taken from the soil_id column. The cost per each soil was randomly chosen.

The procedure for creating the layer is CreateFinalSoils.sh the created layers name is ‘FinalSoils’. The procedure turns the soil type vector data into a raster based on the value in ‘a_SOILS_’ column. After that it reclasses the soil types to be between 1 & 100. Easy to walk on soils (like plains) get a low cost while hard terrains (like rocks) get a high cost value.

Command example; sh C:\GRASS7\scripts\CreateFinalSoils.sh soils_wake el_d783_6mWhere parameter 1 is the soil types vector and parameter 2 is the elevation layer used for region settings.

Figure 8 Example of procedure output

Creating elevation layer8

Page 10: Path Finding In Hazad Terrain

The most basic map is the terrain elevation. High ground is preferred on low ground while moving between observation points. The higher the vehicle is, the more terrain it will be able to watch and thus the harder it would be for enemy units to surprise it with an ambush.

The procedure for creating the layer is Reclass.sh and the created layers name is ‘FinalElevation’. The procedure reclasses the elevation points to be between 1 & 100. High ground would get a low cost while low ground get a high cost value.

Command example; sh C:\GRASS7\scripts\reclass.sh el_d783_6m FinalElevation yesWhere parameter 1 is the elevation layer, parameter 2 is the output name and parameter 3 with value yes means to flip the values, high ground get low values meaning it doesn’t cost much to step on high terrain and vice versa.

Figure 9 Example of procedure output

Creating forest layerIt is important that the vehicle stay away from areas that are easy to attack from. A forest and urban areas are an ideal place for placing RPG units. The trees/buildings make them hard to detect and give them an easy escape route. Therefore, routes shouldn’t enter these kinds of areas and try to be as further away as possible.

The procedure for creating this kind of layer is CreateFinalForest.sh and the created layer is called ‘FinalForests’. The procedure turns the vector areas into a raster where pixels within the areas are null. Rings of decreasing cost are generated around the areas. Locations that are close to the area will get high values. Location that are above the expected range of the RPG unit are given values of 1.

Command example; sh C:\GRASS7\scripts\CreateFinalForest.sh lakescut 200 el_d783_6mWhere parameter 1 is the forest/urban vector layer, parameter 2 is the max range of the RPG and parameter 3 is the elevation layer used for region settings.

9

Page 11: Path Finding In Hazad Terrain

Figure 10 Example of procedure output

Creating slope layerVehicles prefer horizontal terrain and are not capable of driving in steep terrain. The higher a locations slope is the higher its cost.

The procedure for creating this kind of layer is CreateFinalSlopes.sh and the created layer is called ‘FinalSlopes’. The procedure calculates the slope for each pixel from the elevation layer. Pixels with a value higher than the given max slope are set as null. Pixels with a small slope get a low cost value.

Command example; sh C:\GRASS7\scripts\CreateFinalSlopes el_D783_6m 20Where parameter 1 is the elevation layer used for calculating slopes and parameter 2 is the max allowed slope.

10

Page 12: Path Finding In Hazad Terrain

Figure 11 Example of procedure output

Creating roads layerRoads are a preferred route (than moving on rough terrain). But it is only cost effective to move on the road itself and not near a road. That why only the road gets a low cost while all the other terrain gets a high cost.

The procedure for creating this kind of layer is CreateFinalRoads.sh and the created layer is called ‘FinalRoads’. The procedure turns the road lines into a raster where pixels in the line and its immediate surroundings get a low cost.

Command example; sh C:\GRASS7\scripts\CreateFinalRoads.sh roadsMajor el_d783_6m 15Where parameter 1 is the road vector layer, parameter 2 is the elevation layer used for region settings and parameter 3 is the width of the road.

11

Page 13: Path Finding In Hazad Terrain

Figure 12 Example of procedure output

Creating peaks layerThe project finds optimal observation points, although it is also possible to import a vector layer with other observation points. The search algorithm need to know the areas that are to be watched, it then creates cost layers based on the viewed terrain, height, closeness to forests, closeness to roads and terrain slope. It even makes sure to find points that are not too close to each other.

The procedure for creating this kind of layer is CreateFinalPeaks.sh and the created layer is called ‘FinalPeaks’. The procedure creates random points in the observed area and then it runs the viewshed procedure on all the points in the area. Pixels with high values mean they see a lot of the points in the area. All the pixels in the area get value null since we don’t want observation points in the enemy territory. This layer is summed with the FinalRoads, FinalElevation,FinalForests, FinalSlopes layers where each layer has its own configured weight. Lastly, the algorithm chooses the wanted observation points. In each step, it chooses the least cost pixel in the raster and dismisses all pixels around it so in the next step the next observation point won’t be near this one.

Command example; sh C:\GRASS7\scripts\CreateFinalPeaks.sh observationarea el_d783_6m 10 500Where parameter 1 is the observed area, parameter 2 is the elevation layer used for viewshed calculation, parameter 3 is the number of wanted observation points and parameter 4 is the minimal distance between observation points.

12

Page 14: Path Finding In Hazad Terrain

Figure 13 Example of procedure output

Creating view shed layerRoutes that can be observed from the observation points are safer than routes that can’t be watched at all.Locations that are watched will have a lower cost than locations that are hidden.

The procedure for creating this kind of layer is CreateFinalViewShed.sh and the created layer is called ‘FinalViewShed’. The procedure runs the viewshed procedure on all given observation points. Pixels that are watched by many observation points will have a low cost.

Command example; sh C:\GRASS7\scripts\CreateFinalViewShed.sh Finalpeaks el_d783_6mWhere parameter 1 is the observation vector layer (the one created by CreateFinalPeaks) and parameter 2 is the elevation layer used for the viewshed procedure.

13

Page 15: Path Finding In Hazad Terrain

Figure 14 Example of procedure output

Creating Final Cost LayerAfter all the layers have been created (FinalViewShed, FinalRoads, FinalSlopes, FinalForests, FinalElevation, FinalSoiles), the layers are summed together where each layer gets its own weight (adding weights to 100). The routes will prefer moving on low cost pixels.

The procedure for creating this kind of layer is CreateFinalCost.sh and the created layer is called ‘FinalCost’. The procedure multiplies every layer with its weight and calculates the final average.

Command example; sh C:\GRASS7\scripts\FinalCost.shThe procedure looks for the layers created previously.

Figure 15 Example of procedure output

14

Page 16: Path Finding In Hazad Terrain

Creating Routes between PointsRoute creation is done as a matrix from each point to point. A cost layer is created for each point based on the Final cost layer created earlier. The point cost layer shows the minimal cost for each pixel on the map to that specific point. Based on the point cost layer, all routes from other observation points are constructed. After the routes are found there cost is calculated based on the point cost layer and the final slope layer. If point A is higher than points B than they will both have the same route from one to the other but there cost would be different. Moving from bottom to top will cost more than top to bottom.

The procedure for creating this kind of layer is CreateFinalRoutes.sh and the created layer is called ‘FinalRoutes’. It is a loop that for each observation point creates cost layer and direction layer to the point.It finds the routes and calculates route value. Each row in the output in composed of point start number, point end number and cost for moving from start to end.

Command example; sh C:\GRASS7\scripts\CreateFinalCost.sh Peaks el_D783_6m FinalCost where parameter 1 is the observation vector layer (the one created by CreateFinalPeaks), parameter 2 is the elevation layer used for slope calculation and parameter 3 is the cost layer.

Figure 16 Example of point cost layer

15

Page 17: Path Finding In Hazad Terrain

Figure 17 Example of final routes

Figure 18 Example of vector output

16

Page 18: Path Finding In Hazad Terrain

Project scriptsThe following are the scripts explained earlier. The scripts need to be located in c:\grass7\scripts.

CreateFinalRoads.sh

17

E_ERR_ARG=65## checks if there are 2 argumentseval `g.findfile element=vector file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the vector mapset" echo "Insert as argument 1 the vector layer with roads" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

eval `g.findfile element=cell file=$2`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 2 the elevation Layer" echo "Layer $2 does not exist in the raster mapset" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

if [[ $3 == *[^0-9]* ]] then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 3 the max distance allowed from road" echo "Argument $3 should be a number between 0 to 10" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

inmap=$1region=$2maxDistanceFronRoad=$3

## if value equals 0 or null then only the road itself be be set with a low costif [[ $maxDistanceFronRoad -eq 0 ]]then maxDistanceFronRoad=1fi

## Cut only the features in the region of the wanted areag.region rast=$regionv.in.region --quiet --overwrite output=tempv.overlay --quiet --overwrite ainput=$inmap binput=temp operator=and output=temp1#Turn vector layer into a raster v.to.rast --quiet --overwrite input=temp1 output=temp use=val value=1## Create a max distance buffer around the roads ## get raster resolution ( creates $nsres ) eval `r.info -g temp` ## create cost layer according to raster resolution r.mapcalc --overwrite "temp2 = $nsres" ## create cost up to max maxRange given in param 2 r.cost --quiet --overwrite input=temp2 output=temp1 start_rast=temp max_cost=$maxDistanceFronRoad ## make all the rest of the layer as maxRange r.mapcalc --overwrite "temp = if(isnull(temp1),$maxDistanceFronRoad,temp1)" ## set the outer ring of the max maxRange ( which is slightly bigger than maxRange ) to maxRange g.copy --quiet --overwrite rast=temp,temp1 r.mapcalc --overwrite "temp = if(temp1>$maxDistanceFronRoad,$maxDistanceFronRoad,temp1)"## reclass layer sh C:\GRASS7\scripts\reclass.sh temp FinalRoads

Page 19: Path Finding In Hazad Terrain

CreateFinalSlopes.sh

CreateFinalSoils.sh

18

E_ERR_ARG=65eval `g.findfile element=cell file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the raster mapset" echo "Insert as argument 1 the elevation layer" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

if [[ $2 == *[^0-9]* ]] then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 2 the max allowed slope" echo "Argument $2 is should be a number between 0 to 90" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfiinmap=$1maxSlope=$2## craete the slope layerr.slope.aspect --quiet --overwrite elevation=$inmap slope=temp## make all pixels with value higher than maxSlope into nullr.mapcalc --overwrite "temp1 = if(temp>$maxSlope,null(),temp)"## recalss the layersh C:\GRASS7\scripts\reclass.sh temp1 FinalSlopes

E_ERR_ARG=65#~ checks if there are 2 argumentseval `g.findfile element=vector file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the vector mapset" echo "Insert as argument 1 the vector layer with soils" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

eval `g.findfile element=cell file=$2`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 2 the elevation Layer" echo "Layer $2 does not exist in the raster mapset" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

inmap=$1region=$2

## Cut only the features in the region of the wanted areag.region rast=$regionv.in.region --quiet --overwrite output=tempv.overlay --quiet --overwrite ainput=$inmap binput=temp operator=and output=temp1#Turn vector layer into a raster v.to.rast --overwrite input=temp1 output=temp use=attr attrcolumn=a_SOILS_## reclass layer sh C:\GRASS7\scripts\reclass.sh temp FinalSoils

Page 20: Path Finding In Hazad Terrain

CreateFinalViewshed.sh

19

E_ERR_ARG=65eval `g.findfile element=vector file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the vector mapset" echo "Insert as argument 1 the vector layer with observation points" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

eval `g.findfile element=cell file=$2`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $2 does not exist in the raster mapset" echo "Insert as argument 2 the elevation layer" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

if [[ -z $3 ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "State the output layer name as argument 3 " echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

peaks=$1elevation=$2finalElevationName=$3

g.region rast=$elevation## create an empty rasterr.mapcalc --overwrite "temp = 0" ## used to count the number or rows that have been readcurrentPoint=0## used to get rows by there index/categoryc=0eval `v.info -t map=$peaks`while [ $currentPoint != $points ]do ## get a point coordinate COR=$(v.db.select -c map=$peaks columns=x,y separator=, where="cat = $c") if [ -z $COR ] then echo no coord for c $c else ((currentPoint++)) ## do los function for current coord r.viewshed --quiet --overwrite in=$elevation out=temp2 coordinate=$COR obs_elev=2.75 memory=3000 stream_dir=tmp ## add all points values togther-the higher a points value is - the safer it is g.copy --overwrite rast=temp,temp1 r.mapcalc --quiet --overwrite "temp = if(isnull(temp2),0,1)+temp1" fi ((c++)) done## set values between 1 and 100sh c:/grass7/scripts/reclass.sh temp $finalElevationName yes

Page 21: Path Finding In Hazad Terrain

CreateFinalPeaks.sh

20

Page 22: Path Finding In Hazad Terrain

CreateFinalRoutes.sh

21

E_ERR_ARG=65## checks if there are 2 argumentseval `g.findfile element=vector file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the vector mapset" echo "Insert as argument 1 the vector layer with areas" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfieval `g.findfile element=cell file=$2`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 2 the elevation Layer" echo "Layer $2 does not exist in the raster mapset" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

if [[ $3 == *[^0-9]* ]] then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 3 the number of wanted observation points" echo "Argument $3 should be a number between 1 to 20" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfiif [[ $4 == *[^0-9]* ]] then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 4 the minimal distance between observation points" echo "Argument $4 should be a number between 1 to 1000" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfiobservationArea=$1elevation=$2peaksNum=$3distanceBetweenPoints=$4## create random points in areag.region vect=$observationAreav.random --overwrite output=temp1 n=100v.select --overwrite ainput=temp1 binput=$observationArea output=temp2 operator=overlap## put coordinates in x,y columnspython C:/GRASS7/scripts/v.db.addtable.py map=temp2python C:/GRASS7/scripts/v.db.addcolumn.py map=temp2 columns="x double,y double"v.to.db map=temp2 option=coor columns=x,y## set working regiong.region rast=$elevation## create an empty raster for the viewsheds## used to get rows by there index/categorysh C:\GRASS7\scripts\createFinalViewshed.sh temp2 $elevation FinalPeakViewShed##create the final cost layerg.region rast=FinalPeakViewShedr.mapcalc --overwrite "FinalPeaksCost = (FinalRoads@user1 * 10 + FinalElevation@user1 * 10 + FinalForests@user1 * 10 + FinalSlopes@user1*10 + FinalPeakViewShed@user1 * 60) / 100" ## Turn vector layer into a raster v.to.rast --overwrite input=$observationArea output=temp use=val## in the final cost layer, make the inner observation area is null so no observation points will not be found in the observation areag.copy --overwrite rast=FinalPeaksCost,temp1r.mapcalc --overwrite "FinalPeaksCost = if(isnull(temp),temp1, null()) "## clean vector from previous rung.remove vect=mergedPeaks## create a new vecot filev.edit --quiet --overwrite map=mergedPeaks tool=create## insert vactor into DBpython C:/GRASS7/scripts/v.db.addtable.py --quiet map=mergedPeakspython C:/GRASS7/scripts/v.db.addcolumn.py map=mergedPeaks columns="x double,y double"## create a copy so FinalPeaksCost doesnt get dirty g.copy --overwrite rast=FinalPeaksCost,tempnumOfPeaks=1while [ $numOfPeaks -le $peaksNum ]do ##find max point eval `r.info -r map=temp` z=`echo "$max - 0.00001" | bc` ##get the pixel with the max value r.mapcalc --overwrite "temp1 = if(temp>$z,1,null())" ## adds the new point into the peaks layer r.to.vect -t --quiet --overwrite input=temp1 output=temp1 type=point python C:/GRASS7/scripts/v.db.addtable.py --quiet map=temp1 python C:/GRASS7/scripts/v.db.addcolumn.py map=temp1 columns="x double,y double" v.to.db --quiet map=temp1 option=coor columns=x,y v.patch -a -e --quiet --overwrite input=temp1 output=mergedPeaks ## create a 300 meter buffer to make sure no other points are chosen from the area r.buffer --overwrite input=temp1 output=temp2 distances=$distanceBetweenPoints g.copy --overwrite rast=temp,temp1 r.mapcalc --overwrite "temp = if(isnull(temp2),temp1, null()) " ((numOfPeaks++)) done

Page 23: Path Finding In Hazad Terrain

CreateFinalForest.sh

22

E_ERR_ARG=65eval `g.findfile element=vector file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the vector mapset" echo "Insert as argument 1 the vector layer with observation points" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

eval `g.findfile element=cell file=$2`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $2 does not exist in the raster mapset" echo "Insert as argument 2 the elevation layer" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

eval `g.findfile element=cell file=$3`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $3 does not exist in the raster mapset" echo "Insert as argument 3 the final cost layer" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

VECT=$1elevation=$2costLayer=$3

#~ clean previous rung.remove vect=mergedRoutes@user1#~ create a new vecot filev.edit --quiet --overwrite map=mergedRoutes tool=create#~ insert vactor into DBpython C:/GRASS7/scripts/v.db.addtable.py --quiet map=mergedRoutespython C:/GRASS7/scripts/v.db.addcolumn.py --quiet map=mergedRoutes columns="value double"python C:/GRASS7/scripts/v.db.addcolumn.py --quiet map=mergedRoutes columns="fromPoint int,toPoint int"#~ craete slope layer for cost directionr.slope.aspect --overwrite elevation=$elevation aspect=temp3#~ the a,b,c,d params are in charge of iterating threw the vector layera=1c=0eval `v.info -t map=$VECT`while [ $a -le $points ]do COR=$(v.db.select -c map=$VECT columns=x,y separator=, where="cat = $c") if [ -z $COR ] then echo no coord for c $c else (( a++ )) echo r.cost for point $c r.cost --quiet --overwrite input=$costLayer outdir=temp2 output=temp start_coordinates=$COR b=1 d=0 while [ $b -lt $points ] do if [ $c != $d ] then COR=$(v.db.select -c map=$VECT columns=x,y separator=, where="cat = $d") if [ -z $COR ] then echo no coord for d $d else (( b++ )) echo Finding route from $d to $c r.drain --overwrite -a -d input=$costLayer indir=temp2 output=temp1 start_coordinates=$COR eval `r.info -r temp1` pathCost=$max #~ this section gets the cost depending on slope and found path r.mapcalc --quiet --overwrite "temp4 =if(isnull(temp1),0,if(abs(temp3-temp2)>180,360-abs(temp3-temp2),abs(temp3-temp2)))" r.drain --overwrite -a -d input=temp4 indir=temp2 output=temp3 start_coordinates=$COR eval `r.info -r temp3` slopeCost=$max #~ turns the raster into a vector r.to.vect --overwrite --quiet input=temp1 output=temp1 type=line #~ sets the value of the path to be the path cost and the slope cost specific for the found route python C:/GRASS7/scripts/v.db.update.py map=temp1 layer=1 column=value value=`echo $slopeCost + $pathCost | bc` #~ adds the to& from columns python C:/GRASS7/scripts/v.db.addcolumn.py --quiet map=temp1 columns="fromPoint int,toPoint int" python C:/GRASS7/scripts/v.db.update.py map=temp1 layer=1 column=fromPoint value=$d python C:/GRASS7/scripts/v.db.update.py map=temp1 layer=1 column=toPoint value=$c #~ adds the new route into the route layer v.patch -a -e --quiet --overwrite input=temp1 output=mFinalRoutes fi fi (( d++ )) done fi (( c++ ))done

Page 24: Path Finding In Hazad Terrain

FinalCost.sh

Reclass.sh

23

E_ERR_ARG=65## checks if there are 2 argumentseval `g.findfile element=vector file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the vector mapset" echo "Insert as argument 1 the vector layer with soils" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

if [[ $2 == *[^0-9]* ]] then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 2 the danger distance" echo "Argument $2 is should be a number between 0 to 1000" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

eval `g.findfile element=cell file=$3`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Insert as argument 3 the elevation Layer" echo "Layer $3 does not exist in the raster mapset" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

inmap=$1 maxRange=$2 region=$3 ## Cut only the features in the region of the wanted areag.region rast=$regionv.in.region --overwrite output=tempv.overlay --overwrite -t ainput=$inmap binput=temp operator=and output=temp1## Turn vector layer into a raster v.to.rast --overwrite input=temp1 output=temp use=val## get raster resolution ( creates $nsres )eval `r.info -g temp`## create cost layer according to raster resolutionr.mapcalc --overwrite "temp2 = $nsres"## create cost up to max maxRange given in param 2r.cost --overwrite input=temp2 output=temp1 start_rast=temp max_cost=$maxRange## make all the rest of the layer as maxRanger.mapcalc --overwrite "temp = if(isnull(temp1),$maxRange,temp1)"## set the outer ring of the max maxRange ( which is slightly bigger than maxRange ) to maxRangeg.copy --overwrite rast=temp,temp1r.mapcalc --overwrite "temp = if(temp1>$maxRange,$maxRange,temp1)"## make the inner area nullg.copy --overwrite rast=temp,temp1r.mapcalc --overwrite "temp = if(temp1==0,null(),temp1)"## reclass layer sh C:\GRASS7\scripts\reclass.sh temp FinalForests yes

g.region [email protected] --overwrite "FinalCost = (FinalRoads@user1 * 15 + FinalElevation@user1 * 40 + FinalForests@user1 * 15 + FinalSlopes@user1*15 + FinalViewShed@user1 * 15) / 100"

Page 25: Path Finding In Hazad Terrain

AppendicesThe following are explanations on how to work with the modules I used in the project scripts. This is useful for further development of the algorithm.

Creating Viewshed layer Module name is r.viewshed. Computes the view shed of a point on an elevation raster map. The output is a raster where all pixels of value 1 are points that can be viewed from the given location.

24

E_ERR_ARG=65eval `g.findfile element=cell file=$1`if [[ -z $name ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Layer $1 does not exist in the vector mapset" echo "Insert as argument 1 the vector layer with roads" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

if [[ -z $2 ]]then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "State the output layer name as argument 2 " echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit $E_ERR_ARGfi

flip=0if [[ $3 -eq "yes" ]]then flip=99fi

## sets inout as arg 1 and out put as arg 2inmap=$1outmap=$2 ## sets the boundaries of the upcoming functionsg.region rast=$inmap## saves its value in $max & $mineval `r.info -r $inmap`## sets all raster values between 1 & 100r.mapcalc --overwrite "$outmap = abs((float($inmap) *99/($max-$min)+(100)-(99 *$max/($max-$min))-$flip))"

Page 26: Path Finding In Hazad Terrain

Figure 19 Example of module

Figure 20 Example of output

Importing a peaks layerModule name is v.in.ascii. Creates a vector layer based on coordinate points. Can be used for importing custom peaks.

25

Page 27: Path Finding In Hazad Terrain

Figure 21 Example of module

Figure 22 Example of text input

Creating slope layerModule name is r.slope. Generates raster maps of slope, aspect, curvatures and partial derivatives from a elevation raster map.

26

Page 28: Path Finding In Hazad Terrain

Figure 23 Example of module

Figure 24 Example of outputs

Adding a tif map into the DBModule name is r.in.gdal. Can add various formats into the map set. The command can easily be accessed from main menu->File->import raster data.

27

Page 29: Path Finding In Hazad Terrain

Figure 25 Example of module

Getting raster statisticsModule name is R.stats. Generates area statistics for raster map layers. Shows how many pixels are for every value.

28

Page 30: Path Finding In Hazad Terrain

Figure 26 Example of output

Reclass a raster layerModule name is r.mapcalc. Performs arithmetic on raster map layers. New raster map layers can be created which are arithmetic expressions involving existing raster map layers, integer or floating point constants, and functions.

Figure 27Example of module

Getting layer information

29

Page 31: Path Finding In Hazad Terrain

Module name is r.info. Outputs basic information about a raster map layer.

Figure 28 Example of output

Adding x,y columns in vector layerModule name is v.db.addcolumn. Was used to add X,Y columns as attributes so theu could be read in the scripts.

Figure 29 Example of module

30

Page 32: Path Finding In Hazad Terrain

Inserting point coordinate’s into x,y columnsModule name is V.to.db. Inserts data into from vector features into its attribute columns.

Figure 30 Example of module

Removing layers from the DBModule name is g.remove. Removes unwanted layers from the map set. Used for cleaning.

Figure 31 Example of module

31

Page 33: Path Finding In Hazad Terrain

Turn vector into raster layerModule name is V.to.rast. Can use attributes in the vector data as pixel value.

Figure 32 Example of module

Setting values to nullModule name is r.null. Turns pixel values in a raster to null. Used in cost layers to define location that cant be stepped on.

Figure 33 Example of module

32

Page 34: Path Finding In Hazad Terrain

Exporting vector to AsciiModule name is V.out.ascii. Can export the final routes result out of the grass mapset.

Figure 34 Example of module

Least cost routeModule name is R.drain. Traces a flow through an elevation model on a raster map. It uses the point cost layer to find the shortest path from anywhere on the map to that point.

Figure 35 Example of module

33

Page 35: Path Finding In Hazad Terrain

Figure 36 Example of module

Figure 37 Example of module

34

Page 36: Path Finding In Hazad Terrain

Figure 38 Example of output

Useful hyperlinks 1. DTM 2. http://vterrain.org/Doc/VTBuilder/overview.html 3. http://www.viewfinderpanoramas.org/Coverage%20map%20viewfinderpanoramas_org3.htm 4. http://rmw.recordist.com/ 5. http://en.wikipedia.org/wiki/Viewshed_Analysis 6. http://www.osgeo.org/ 7. http://www.saga-gis.org/en/index.html 8. http://ws.csiss.gmu.edu/DEMExplorer/ 9. http://www.terrainmap.com/rm39.html 10. http://www.innovativegis.com/basis/BeyondMappingSeries/BeyondMapping_III/Topic8/BM_III_T8.htm 11. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=An%20overview%20of%203D%20Analyst

References1. Kuo-Ho Su , Feng-Li Lian and Chan-Yun Yang , “Navigation design with SVM path planning and

fuzzy-based path tracking for wheeled agent”, 2012 International Conference on Fuzzy Theory and it's Applications (iFUZZY), vol., no., pp. 273 - 278 , 16-18 Nov. 2012

2. Keonyup Chu , Minchae Lee , Myoungho Sunwoo , “Local Path Planning for Off-Road Autonomous Driving With Avoidance of Static Obstacles”, IEEE Transactions on Intelligent Transportation Systems, vol. 13 , pp. 1599 - 1616 , 2012 

3. Goldman, J.A., “Path planning problems and solutions”, Aerospace and Electronics Conference, vol.1, pp. 105 - 108 , 1994

4. Ting Zhao , Jinyun Fang, “A transit path planning model based on the heterogeneous road network”, 17th International Conference on Geoinformatics, vol., pp 1-6 , 2009

5. Joo Young Hwang , Jun Song Kim, Sang Seok Lim, Kyu Ho Park, "A fast path planning by path graph optimization”, IEEE Transactions on Systems, Man and Cybernetics, Part A: Systems and Humans, vol. 33, pp. 121-129, 2003

35

Page 37: Path Finding In Hazad Terrain

6. Jianming Guo , Liang Liu , Qing Liu , Yongyu Qu, “An Improvement of D* Algorithm for Mobile RobotPath Planning in Partial Unknown Environment”, Second International Conference on Intelligent Computation Technology and Automation, vol. 3, pp. 394-397, 2009

7. Toda, Y. , Kubota, N.,”Path planning using multi-resolution map for a mobile robot”, 2011 Proceedings of SICE Annual Conference (SICE), vol., pp 1276-1281, 2011

8. Hartley, T.P. , Mehdi, Q.H.,”In-game adaptation of a navigation mesh cell path”, 17th International Conference on Computer Games (CGAMES), vol., pp. 230-236 , 2012

9. Fischer, L. , Nedel, L., “Semi-automatic Navigation on 3D Triangle MeshesUsing BVP Based Path-Planning”,  24th SIBGRAPI Conference on Graphics, Patterns and Images (Sibgrapi), vol., pp. 33-40, 2011

10. Yao Cui , Guofeng Qin, “Intelligent path planning in 3D scene”, 2010 International Conference on Computer Application and System Modeling (ICCASM), vol. 3, pp. 579-583,2010

11. Kyoung-Ok Kim , Young-Kyu Yang , Jong Hoon Lee ,Kyung-Ho Choi , Hyun Ok Nan , Dong-Jo Seo,”Development of a tactical terrain analysis system with GIS technique”, Surface and Atmospheric Geoscience and Remote Sensing Symposium, vol. 2, pp. 860-862, 1994

12. Bellone, M., Messina, A., Reina, G., “A new approach for terrain analysis in mobile robot applications”, IEEE International Conference on Mechatronics (ICM), vol., pp. 225-230, 2013

36