23 January 2014

QGIS basic tutorial 1 - attribute table, sorting, filtering

I use QGIS to prepare shape files for creation of maps in Tableau. Some shape files demand changes to match my Tableau projects so I decided to share few tips how to work with them.

In the tutorial I work with QGIS 2.0.1. and the shape file of Ukrainian administrative districts from GADM.


Importing a shape file to QGIS, there are three options:
1. upper menu => Layer => Add Vector Layer
2. by clicking on the icon
3. combination of Ctrl+Shift+V


Add a vector layer and confirm by 'Open'


Working environment 
You can make your working environment more handy by adding Panels and Toolbars.
View => Panels => check boxes
View => Toolbars => check boxes

At the beginning of work with QGIS, it is normal that you don't know which panels and toolbars are useful to you, but you can keep this tip in mind for your future adventures with QGIS :)


After importing the shape file you see map consisting polygons [in this example I work with the shape file composed of polygons but also files can include lines or points], you have right to feel disappointed ('where are names of administrative districts?' 'Is this everything?'), each heavy file is a promise of something more... To discover more about your file you have to enter an attribute table.

Opening an attribute table
There is a variety of options:
1. Clicking the layer to highlight it and then clicking on the icon 'Open Attribute Table'.
Marking the layer is important when we have few layers so it is a must to inform QGIS which Attribute Table you would like to see.

2. Right clicking on the layer name and selecting 'Open Attribute Table'.
3. Upper menu: Layer => 'Open Attribute Table'.

Each row of the table is composed of information about a polygon (in this case administrative district of Ukraine - NAME_2).


This file has 629 administrative districts, but many are even bigger, what makes browsing for certain regions time consuming. Sorting and filtering are solutions for this problem.

Sorting
By clicking on the column heading you sort the column in ascending or descending order.


Link between the attribute table and the map
When you click on the row number (at the left side) you highlight the row and the corresponding polygon on the map (yellow polygon).
Opposite way also works, clicking on the polygons on the map to mark proper rows in the attribute table.
If you want to select more records which are not placed next to each other keep pressed Ctrl when you mark second, third... record.
To select few records that are placed in a bloc next to each other, select first, press Shift and select the last one. All records between become highlighted.


Filtering
The left bottom corner of the attribute table has filters.
Let's try 'Column Filter', to see all administrative districts in Kiev City, it is enough to select Column Filter  = > NAME_1 (name of column, which is searched for matching records).


New box appears at the bottom ready to place search term.
To highlight all selected rows click on the grey square in the upper left corner, what results with turning colour of the districts into yellow.


Zooming map is handy when you want to check if everything is as you expected.


If you want to create a map of Kiev in Tableau, you need only the selected districts, so you can save them as new shape file that will have much smaller size. Right-click on the name of layer and 'Save Selection As...'

Browse to find a proper place for a new file with Kiev's districts and give it a name (which you will remember :)


'Advanced Filter' offers more options.


The functions are grouped by types. 'Fields and Values' are worth checking, selecting a column name and pressing 'Load all unique values' gives overview of the field. The same we can do with columns consisting values.


The command below was created with the functions from 'Operators' group, it searches for ID <= 3 or >= 625.
After clicking on each function, you receive tips how to use them, it is great:)


The command box appears at the bottom and gives chance to implement changes.


No comments:

Post a Comment