CREATING A SHAPEFILE USING DB DATA




Steps to follow:

1. CONNECT THE DATABASE
2. LINK A DB TABLE TO THE VECTOR MAP
3. CREATE A SHAPE FILE
4. REGISTER A SHAPEFILE








1. CONNECT THE DATABASE

To connect an external database to GRASS 5.7 just run db.connect on the terminal. Write the name of the database you want to connecgt to GRASS 5.7 and choose the right driver on the form: if you're using a PostgreSQL database you have to select pg driver.







2. LINK A DB TABLE TO THE VECTOR MAP

The next step is to select a table from the database connected to GRASS 5.7, and link it to the vector map. To do this run v.db.connect.

In the v.db.connect form enter these options:



NOTICE:

To extablish a connection between a vector map and a database table, map categories must match table keys or id of a certain field: the name of this field must be entered in the "key name" box of the form.


Press Run and on the form a warning appears: The table "table_name" is now part of vector map "map_name" and may be deleted or overwritten by GRASS modules.






3. CREATE A SHAPE FILE

To create a Shapefile use v.out.ogr command. In this case a database table is connected to the vector map you're about to convert to shape format: all table data will be stored in the .dbf file of the shape map, creating a multi-attribute map.
Using OGR datasource name and OGR layer name you can choose shapes' directory and file names.






4. REGISTER A SHAPEFILE

To register a Shapefile, run v.shape.register command: in this way it can be opened and edited by GRASS 5.7.

The registered shape can now be opened and queried as a normal GRASS 5.7 vector map. Querying the map you can see that all data is now stored in the shapefile, not in the database!





               

Università degli Studi di Trento - Facoltà di Ingegneria