Using the postgisquerybuilder plugin in QGIS desktop to carry out spatial and attribute queries

This post will demonstrate how to use the postgisQUERYBUILDER plugin for QGIS to carry out basic queries on data in the Postgis database.

1. First install the plugin. On  the main menu bar, Go to  the Plugins – Manage and Install Plugins


2. In the dialog box, use the search bar to find postgisQueryBulder. Install it. On our screenshot below, you can view the already installed plugin in the ‘Installed’ list.


3. Once installed, the icon will appear on the menu bar. . See red encircled on the screenshot below. Click on the icon to launch the plugin.


4. Go to PostgreSQl tab and Click on the dropdown button to select a postgis connection.


5. Go to Schema and select Public. Once a connection is established, the tables will appear in the pane below.


6. A) We select a table to query-northcentral; and then B) select SQL option


7. Write the SQL expression for the query. Here we ask for districts within the northcentral region that have more female population  than male population. Note that the Add to Map option is checked. Click on ‘Run Query’ and the result will automatically be added to the map canvas.


8. On the screenshot below, the result is displayed as an untitled layer. This gives the user the opportunity to name as appropriate. The blue polygons satisfy the query criteria.


9. Next, we carry out a spatial analysis – ST_Buffer. In this series of screenshot, we wil create a buffer around a line feature- rail.shp.

We select another table stored in our postgis database-rail.shp. Go down to the options below and choose Query.


10.  In the next page, Click on ‘Select Query type’ and choose ST_Buffer from the dropdown list.


11. A) Make sure the option here is ST_Buffer. B) Select the rail table  to buffer. C) Input a buffer distance around the rail, in our case we choose 0.01DD. D) Run the query.


12. The result Buffer_of_rail is seen on the screenshot.


13. We will perform another query ST_Intersection. This will give us the overlap areas between the buffer we just created and a polygon layer- Ido.shp. *Make sure the result of the last query is uploaded in the PostGIS database, Click Query and select ST_Intersection fro the dropdown list.


14. Select the layers to intersect and run the query


15.Result from the query is seen encircled in yellow on the  screenshot below.


16. Another useful query tool is Measure Features, In this section, we will query to know the area and perimeter of a polygon feature-Ikeja_district.


17. In the Measure Feaures window, select the layer to be measured and run query.


18. To see the results of the query we have to open the attribute table of the table created as result of the query.

. 23

19. The screenshot displays the table showing results of the mesaureents (red enclosed).


Thank you for following the blog.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s