Introduction
This manual is aimed at users of the Rainforest Foundation UK's PostGIS database. It should be read by people wishing to upload and edit GPS survey data as well as by those who will administer the PostGIS database.
The manual can be used as a practical tutorial and aims to teach users how to: • Install the plugin
• Connect to the PostGIS database • View data from the database • Upload features to the database
• Populate and edit feature attributes in the database
This guide assumes that the audience is already familiar with basic Quantum GIS tasks such as creating shapefiles, editing table attributes etc.
In the following chapters, we'll be creating tables in the PostGIS database based on GPS point and track data surveyed in the field.
Each of the examples assumes that the user has already loaded their GPS data into QGIS, either directly using theGps Toolsplugin, or through theAdd Vector Layerdialog.
1.
Installing the plugin
IMPORTANT: If you already have a previous version of the plugin installed, uninstall it by removing the
rfuk_postgis_uploadfolder from your ~/.qgis/python/plugins folder and restarting QGIS.
The RFUK PostGIS Upload Plugin is located in a dedicated Quantum GIS python plugin repository. To install the plugin, we will first need to add the dedicated repository.
1. Open Quantum GIS
2. SelectFetch Python Plugins...from thePluginsmenu 3. Click theRepositoriestab
4. Click theAddbutton
5. Enter the details as shown in the image below and clickOK Name: RFUK Repositry
6. Click the Plugins tab
7. Typerfukin the filter box and select the plugin in the list:
8. ClickInstall plugin
A message should now be displayed to show that the plugin was successfully installed.
The plugin can be accessed through its icon,
By default, Quantum GIS will check for updates for plugins once a day. Quantum GIS will notify users when there is an update available for the plugin and prompt them to download and install it.
2.
Setting up PostGIS connections
In order the use RFUK's PostGIS database, you'll need to have been given a username and password. At present, a single login is used by each participating country. The username consists of the prefix
remote_followed by the name or abbreviation of the country. The following table shows a list of available usernames.
Country Username
Cameroon remote_cameroon
Central African Republic remote_car
Congo remote_congo
Democratic Republic of Congo remote_drc
Gabon remote_gabon
Each username will have the following levels of access to different types of data within the database. The wordcountryin the Dataset column should be replaced with the name of the country in which the surveyor is working.
Dataset Dataset Description Access
bg_country Background mapping specific to the country Read only bg_general Non country specific background mapping. These datasets
often cover multiple countries.
Read only
country_draft Survey data that has been uploaded and is in the process of being edited or is awaiting approval
Read / write
country_approved Survey data that has been finalised and approved Read only
It should be noted that surveyors have write access only to draft datasets. The following instructions will show how a PostGIS connection is created.
1. Open Quantum GIS and click theAdd PostGIS Layerbutton, TheAdd PostGIS Table(s)dialog should now be shown.
2. Click theNewbutton to configure a new connection.
3. Enter your username in theNameandUsernameentries and fill out the other entriesexactlyas shown above. Your password should have been provided by Rainforest Foundation UK.
4. ClickTest Connect
3.
Importing Data
The RFUK PostGIS Upload Plugin can be used to upload the following geometry types to the database:
Points
Multilinestrings
Multipolygons
The plugin supports the upload of the following types of data:
Villages (Point)
External Actors (Point and Multipolygon)
Livelihood and Cultural Activities (Point and Multipolygon)
Natural Features (Point and Multipolygon)
Routes and Local Rivers (Point and Multilinestring)
For more information on the types of data that can be uploaded to the database and their supported attributes, refer to theRFUK PostGIS Table Attribute Standard (version 008).
3.1
Overview of the process
When the RFUK PostGIS Upload Plugin's Upload button is clicked, the plugin does the following:
Checks that the input layer is a vector layer
Checks that the input layer is in WGS84 Lat/Lon projection
Checks that some features are selected
Checks that the table name matches the data type
Connects to the PostGIS database and creates a new, empty PostGIS table with the correct attributes for the data type
Copies each selected feature into the PostGIS database, re-projecting each feature to a sensible projection for the given country and copies any relevant data from the GPS survey into the correct columns of the database
3.2
Selecting features
In order to upload to the database using the RFUK PostGIS Upload Plugin, features to be uploaded will first need to be selected. Selection can be performed by one of the following methods:
3.2.1 Manual selection (within Quantum GIS)
3.2.2 Select by attributes (within Quantum GIS)
Features can be selected based on their attributes using thesearchoradvanced searchoptions in a layer's Attribute Table dialog.
3.2.3 Select all (within the RFUK PostGIS Upload Plugin)
The Select All button will select all features in the current layer.
3.2.4 Select based on dates (within the RFUK PostGIS Upload Plugin)
The select based on dates feature allows the user to select features based on the GPS date stamp present in layers loaded directly from GPS devices or GPX files. This feature could be used, for example, to quickly select survey data from a particular day from a much larger collection of survey information.
It is important to note that GPS time stamps will be in universal time (UTC) where the dates used for selection entered by the user are in local time.
3.3
3.4
Uploading data – an example
According to theRFUK PostGIS Table Attribute Standard (version 008), points can be used to represent villages, external actors, livelihood activities and cultural activities, natural features and routes.
In this example, we'll add two surveyed villages, Carefour and Ngamakossou, from a GPS file containing multiple surveyed points.
Zoom in to ensure that the selection is correct
The dialog consists of controls associated with the upload of the data as well as controls associated with the selection of data to be uploaded.
The selection tools allow the user to select features based on the date they were surveyed. This method of selection requires that the survey date is included in the comment attribute by the GPS device (it usually is). If the plugin cannot find the date in the comment attribute for some features, a warning will be issued to the user.
The upload controls allow the user to specify options relating to how the data should be inserted into the database.
The first option is the PostGIS connection to use for the upload. It is important that the correct connection is used for a given country as the name of the schema that the data will be uploaded to is derived from the connection name. In this case we are uploading data located in Congo, so are using theremote_congoPostGIS connection.
The next option describes the type of data we are uploading. In this case, the points being uploaded are villages, so we have chosen the Villages option. The data types correspond to theRFUK PostGIS Table Attribute Standard (version 008).
The next option is the name to give the new PostGIS layer. Layer names can contain only lower case letters, numbers and underscores (the '_' character). The RFUK database specification specifies a naming convention for PostGIS layers enabling them to be easily identified. The name prefixes required for different data types are described below.
Data Type Table name prefix
Villages v__
External Actors ea__
Livelihood Activities la__ Cultural Activities ca__
Natural Features nf__
Routes or Local Rivers rr__
3. Ensure that thePostGIS Connectionis set to remote_congo, theType of Datais set to Villages and enter a name for the new layer, such as v__test_layer_001
4. ClickUpload
5. Next, open the attribute table of the PostGIS layer using theOpen Attribute Tablebutton,
The table attributes for the two imported points should now be visible(your attributes may differ slightly
from the image below).
It can be seen that information from the GPS data has been copied to the database, such as the name of the waypoint and the date the waypoint was surveyed.
Additional attributes such as the population of adult males and females has not been automatically populated. This data will need to be entered manually from within Quantum GIS.
4.
Loading PostGIS survey layers
In this chapter, the user will learn how to view survey data that already exists in the PostGIS database.
PostGIS layers are loaded using theAdd PostGIS Layerbutton,
1. Click theAdd PostGIS Layerbutton to open theAdd PostGIS Table(s)dialog
2. Ensure that the remote_congo connection is selected and clickConnect
A list of PostGIS layers should now be displayed.
Layers are grouped into containers called schemas. Background data will be located in schemas starting withbg_while survey data will be located in schemas prefixed with the name of the country associated with the data.
Background data relevant to multiple countries will be located in the bg_general schema while, for example, background data specific to congo will be located in the bg_congo schema.
example, we'll be uploading data to the congo_draft schema. Surveyors in Congo have read/write access to the congo_draft schema.
Once layers have been reviewed and finalised by Rainforest Foundation UK, they will be moved from the _draft schema to the _approved schema. Surveyors in Congo have read only access to the
congo_approved schema.
3. Select the layer v__test_layer_001 and click Add The layer should now be loaded.
5.
Uploading polygon data
Polygons may be added to the PostGIS database for the External Actors, Livelihood Activities, Cultural Activities and Natural Features data types.
It is assumed that GPS track data will be used to define a polygon in Quantum GIS which will then be uploaded to the PostGIS database. This is demonstrated in the following example where a track around a lake is used to define a polygon.
A track can bee seen in the image above representing the shore of a lake.
In order to import the lake into the PostGIS database, we must first create a polygon from the track which in currently a polyline.
1. Create a new shapefile by using theNew Shapefile Layerbutton,
2. Ensure the shapefile is set to contain polygons and is in WGS84 Latitude/Longitude (EPSG code 4326).
If the table contains a text attribute called name, the contents of this attribute will be used to update the name of the feature in the PostGIS database.
3. Save the new shapefile in a sensible location.
Next we must digitise the polygon representing the lake, using the track as a guide. Quantum GIS's snapping feature is very useful to ensure that the new polygon follows the surveyed shore of the lake. 4. Digitise the lake polygon and optionally, give it name by filling out the name attribute.
5. Save the polygon shapefile.
With the polygon layer selected, the user should be able to upload the polygon to the PostGIS database as was done previously in the villages example.
6.
Editing PostGIS Layer attributes
Once features have been uploaded to the database, their extended attributes can be populated / edited. PostGIS layer attributes can be edited in the normal way in Quantum GIS using theOpen Attribute
Tablebutton, , or through theEdit Featureform which is available through a right click on the
Identifyform.
TheRFUK PostGIS Table Attribute Standard (version 008)lists a complete set of available attributes for each data type along with a human-readable description.
6.1
Enumerations
Some attributes are set as enumerations. One example of this is the village layer'sinvolvedattribute. Enumerated types may only be set to one of a pre-defined set of values. In the above example, the village layer'sinvolvedattribute can only be set to one of the following values:
UNSET (no value has been set yet)
yes
no
The value of an enumerated attribute can either be typed in manually (it will have to be typed exactly), or can be set using one of Quantum GIS' advanced attribute editing features as described below. A full list of the enumerated types used in the RFUK PostGIS database can be found in theRFUK PostGIS Table Attribute Standard (version 008).
6.1.1 Enabling enumeration drop-down menus
The following instructions describe how to make entering enumerated attribute values easier by enabling drop-down lists.
1. Open the layer'sLayer Propertiesdialog 2. Select theAttributestab
3. For each attribute with a type starting with “enum_”, change the edit widget fromLine editto
4. Click OK to close theLayer Propertiesdialog.
7.
Deleting PostGIS Layers
Layers in_draftschemas can be deleted using thePostGIS Managerplugin.