6 Attribute actions to vector layer
QGIS can perform an action based on the attributes of a feature. The actions,for example, running a program with arguments built from the attributes or
passing parameters to a web reporting software.

Set new database “koshigaya” of PostgreSQL using pgAdminIII. This procedure
has been described in “1_installation&Setting.ppt”.
Open pgAdminIII and login as “superuser”.
Click the right button on “Database” and select “New Database” by clicking the left.
“New Database” dialog opens.
Type in Name of new database “koshigaya”.
Select Owner ‘yokoi’.
Select ‘template_postgis’ to activate PostGISfunctionality.

Then, click on ‘OK’.

1

Click on the node of “Databases”,
that of “koshigaya”,
that of “Schemas”,and “Public”.
Then, click on the button ‘SQL’.

“pgAdmin III Query” dialog appears.
Type in “select postgis_full_version();” and push F5 key of the keyboard.

Verify ‘OK’ at the left bottom. Close ‘pgAdmin III Query’ clicking on ‘File’ and ‘Exit’.
It is not necessary to save the change.

2

Click on the nodes of “koshigaya”, “schemas”, “public” and“table”.
Click the right button on “geometry_columns” and select“Properties”.
Then, “Table geometry_columns” dialog opens.
Change Owner to “yokoi” and click “OK”.

Click on the nodes of “koshigaya”, “schemas”, “public” and “table”.
Click the right button on “spatial_ref_sys” and select “Properties”.
Then, “Table spatial_ref_sys” dialog opens.
Change Owner to “yokoi” and click “OK”.

Close ‘pgAdmin III’ clicking on ‘File’ and ‘Exit’.

3Add new table “obspoints” in the new database “koshigaya”. This procedure hasbeen described in “2_creating_vecor_layer.ppt”.
Copy the sql batch file “D:/batch_sql/mkpoint.sql” to “C:/TEMP/mkkoshigaya.sql”.
Edit “C:/TEMP/mkkoshigaya.sql” using WordPad as shown below.
CREATE TABLE obspoints (id1 integer NOT NULL, CONSTRAINT
obspoints_pkey PRIMARY KEY (id1)) WITHOUT OIDS;
ALTER TABLE obspoints OWNER TO yokoi;
select AddGeometryColumn('obspoints', 'the_geom', 4326, 'POINT', 2);
where the changed parts are shown blue, “4326” denotes latitude and longitude inwgs84.
Execute the sql batch file “C:/TEMP/mkkoshigaya.sql” using “¥i” command.
¥i C:/TEMP/koshigaya/mkkoshigaya.sql

Add new table “phopoints” in the database “koshigaya”.
Edit “C:/TEMP/mkkoshigaya.sql” using WordPad as shown below.
CREATE TABLE phopoints (id1 integer NOT NULL, CONSTRAINT
phopoints_pkey PRIMARY KEY (id1)) WITHOUT OIDS;
ALTER TABLE phopoints OWNER TO yokoi;
select AddGeometryColumn(‘phopoints', 'the_geom', 4326, 'POINT', 2);
where the changed parts are shown blue, “4326” denotes latitude and longitude inwgs84.
Execute the sql batch file “C:/TEMP/mkkoshigaya.sql” using “¥i” command.
¥i C:/TEMP/koshigaya/mkkoshigaya.sql

Confirm the creation of column “obspoints” and “phopoints”.
Then, “¥q” and “exit”.

4Open QGIS and load a raster layer that is used as Basemap.
For this example, a part of Koshigaya city is used with geographicalcoordinates of wgs84 .

Capture observation points and register them in postGIS layer “obspoints”
The procedure is described in “3_Input_Data_To_Vector_Layers.ppt”.
First, connect to the PostGIS layer “obspoints”.
Open “Add PostGIS” dialog using“Add a postGIS layer” button.
Then, click “New” button.

5Type in as shown left.
Name: Connect to Koshigaya (arbitrary)
Host: localhost (fixed)
Database: koshigaya (target database)
Port: 5432 (Fixed)
Username: yokoi
Password: *****
Check it by clicking on “Text Connect”button.
Then, click “OK”.
Click on “Connect” button of “AddPostGIS” dialog.
“obspoints” and “phopoints” layers
are shown.

Select both of “obspoints” and“phopoints” layers and click “Add”.

“obspoints” and “phopoints” layers
are connected to QGIS.

6

Select “obspoints” layer.

Open “Attribute Table” using“Open Table” button.
Click “Start Editing” button.

Click “New Column” button.
“Add Attribute” dialog opens.
Type “latitude” in Name and select“double precision”.
Click “OK”.

Click “New Column” button.
“Add Attribute” dialog opens.
Type “longitude” in Name andselect “double precision”.
Click “OK”.

7

Click “New Column” button.
“Add Attribute” dialog opens.
Type “rest_path” in Name and select“text”.
Click “OK”.

Click “New Column” button.
“Add Attribute” dialog opens.
Type “photo_path” in Name and select“text”.
Click “OK”.

Add “sta_id”, “obs1”, “obs2” and“obs3” by following the same way with
type “text”.
Click “Stop Editing” button of “AttributeTable”. Then “Save” and “Close”.
Then, create POINT data on “obspoints” layer. The procedure is described in“3_Input_Data_To_Vector_Layers.ppt”.

Observation points are captured on QGIS.

8Convert the PostGIS layer (“obspoints”) to Shape file.
The current version of QGIS does not automatically re-connect to PostGIS layer
when the Project once saved is open again. Then, it is necessary to set Action
again. In order to prevent this troublesome procedure that require every time, thePostGIS layer including Action is converted to Shape file and stored in adirectory.
Open “Command Prompt” of PostgreSQL.

pgsql2shp –h localhost –u yokoi –P ******-f C:/TEMP/koshigaya/obspoints.shp koshigaya obspoints
Host name
Username of inputdatabase and its
password
Output Shape file namewith its path

Input Database Name

Input Table Name

Shape file created in“C:/TEMP/koshigaya”.
Close “CommandPrompt” using “exit”.

9Back to QGIS. Remove PostGIS layer “obspoints” and add vector layer“obspoints.shp” using “Add a Vector Layer” button.
Nothing is changed in its outlooking.

Select “obspoints” layer and click on it with the right button.
“Layer Properties” dialog opens. Select “Action” tag.

10

Type in as shown left:
Name: name of action (arbitrary)
Action: application name with full path
For this example, Internet Explorer isselected. Use “Browse” button ifnecessary.
Add a space after program name withfull path
Select “PHOTO_PATH” column.
Then click “Insert field” button.

“%PHOTO_PATH” is added to theapplication name in “Action”.
Confirm that there is a space
between program name and “%”.

11

Enclose the application nameand %PHOTO_PATH by the
double quotation marks (“ “).
Activate “Capture output”.
Click “Insert Action” button.

Action “View_Photo” is inserted.

Click “Apply” then “OK”.

12Next step is to input the name of photograph files with full path to table of vector
layer “obspoints”. There are two ways.
One way:
Click “Toggle Editing” button and “Identify feature” button. Then, click on a mark ofvector layer “obspoints”.

“Enter Attribute Values” dialog opens.
Type in the file name with full path.
Then click “OK”.

After inputting all the file names, click“Toggle Editing” button. Then click “Save”
to save the edited information in the shape
file “obspoints.shp”.

Another way:
Click “Open Table” button. “Attribute Table” opens.

Click “Start Editing” button and type in the file name with full path in the target cells.
After inputting all the data, click “Stop editing” button and “Save” and “Close”.

13Save Project using “File” and “Save Project”. Choose the directory where Project( .qgs) is saved.

Launch the action:
On QGIS click “Identify Feature” button. “Identify Result” dialog opens.

Click the right button on the mark of “action”.

14Internet Explorer is launched with “C:/TEMP/Ks_photo/IMG_1279.jpg”.

Attribute one more action:“Properties” of “obspoints” and“Action” tag.
Application is Excel. File names
are stored in the column“RES_PATH”.

15

“Identify Feature” button, “Toggle Editing” button anda mark on “obspoints” layer.
Excel file “C:/TEMP/Ks_SPAC/Site_A.xls” isattributed.

“Identify Feature” buttonand a mark on“obspoints” layer.
Two actions are attributed.
Click the right button on the action“View_Worksheet”.

Excel is launched with “C:/TEMP/Ks_SAPC/Site_A.xls”.

16Save project otherwise the setting of actions is lost.
Note that the setting of actions is saved not in the shape file orin the table of PostgreSQL, but the project of QGIS.

17