GRASS Vector Layers

From GRASS-Wiki
Jump to navigation Jump to search

Introduction

Grass documentation provides basic information about vector attribute management. categories of vector features and vector layers.

The aim of this tutorial is to show how to create, manipulate and display different layers of a vector using relational database.

Problem Description

An organization provides information about routes to be driven by drivers. The organization's database consists of

  • roads (road network)
  • routes driven on that roads

Simple approach can be taken to present the routes to drivers. For every route a vector map could be created and overlayed over the road network vector, i.e.

   $ d.vect map=roads
   $ d.vect map=route01 color=green width=2

Above idea has a major flaw. If route data changes or new route is added then vector maps has to be regenerated or removed.

Assuming that route network and routes data are stored in relational database, the database tables can be linked to road network map as its layers. Such layer information could be utilized to display maps, i.e.

   $ d.vect map=roads
   $ d.vect map=roads layer=2 where="route_id=1" color=green width=2

The tutorial reuses road network provided with Spearfish data. To solve problem defined above, the roads data and sample route needs to be prepared. This is described in next section.


Road Network and Routes Data

Database Tables

Relation database should contain two tables

  • road network table
  • driven routes table

Road network table has to contain at least two columns

  • road segment id usually provided with road network data by vendor
  • vectory category required by Grass to identify vector features

Road network table can be defined like

   create table road_network (
       cat integer not null unique,
       id integer not null unique   -- road segment id
   );

Routes table contains route identifier and id of road segment driven on a route

   create table routes (
       route_id integer not null,
       rn_id integer not null,    -- references road_network.id
       primary key (route_id, rn_id)
   );

Above tables allow to provide road network and driven routes information. They can be more complicated depending on application but for purpose of this tutorial such minimal approach is being kept.

Road Network

Spearfish data provides road network map in roads vector. It contains few hundred lines - road network segments. Data associated with this vector are very simple and it has to be extended

  • unique category id for every vector road segment needs to generated
  • unique id has to be assigned to every road segment

v.category --o in=roads out=outmap option=del

v.category --o in=outmap out=stepmap option=add

v.to.db map=setpmap option=cat

update road_network set id=cat;


http://grass.osgeo.org/grass63/manuals/html63_user/vectorintro.html