Getting Started with QGIS (DeGroot @ KDMC)

THIS IS REVISION OF http://multimedia.journalism.berkeley.edu/tutorials/qgis-basics-journalists/loading-shp/


Understand, load, export map files

There are several formats that QGIS and other GIS apps will open and export. The most common is the SHP or "shape" format. While other filetypes are important, we will work with SHP files in this tutorial.

How SHP files work

SHP files are made of editable "vectors." All that really means is that it calculates the distance between points on a map and draws lines.

There are three types of SHP files:

Point files include one or more specific locations. This is essentially what you see on a Google map.

Line files connect groups of points. These can be used to draw roads, rivers, etc.

Polygon files connect points into closed shapes. The shapes usually form boundaries such as ZIP Codes or tracts.

And if they all use the same projection, they can be accurately layered together.

shps-to-layers.jpg

And finally, SHP files are really a collection of files:

shp.jpg

SHP contains the drawing information.

DBF contains the data about each shape, such as name, address, etc.

SHX is an index file that ties the two together.

PRJ contains the projection information.

Some agencies will also include metadata which describes properties of the files.

Import a shape file

So lets get started. Download the project files and unzip them. We're going to be working with 2010 census tract files of Alameda County, Calif.

Go to the Layer menu and select Add vector layer (Command-shift-V). Navigate to the project files and open SHP files - source folder, then the alameda-2010-tracts folder and then click on the file that ends in .shp and click Open. A map will appear in the layout area and a layer is added to the panel.

new-shp-layer.jpg

Edit the layer properties

Go to the Layer menu and select Properties. A new window will appear. Style should be selected by default. Click the Properties button:

QGIS%201.9%20Layer%20Style%20Dialog

In the new window, change the Fill color and the Border color by selecting a Saved style and click the Apply button on the bottom left corner to see the changes or click OK.

Search data to select boundaries

One of the quickest ways to select shapes in a layer is with search. Go to the Layer menu and select Open Attributes Table. This opens the information in the DBF file. The initial columns usually identify each record. In this case, we see six columns of Federal Information Processing Standards (FIPS) IDs.

attribute-table.jpg

NOTE: FIPS abbreviates names of places to make files smaller and make it easier to join data with SHP files. In this case, 06 is the state of California, 001 is Alameda County, 437800 is the name of a tract and 06001437800 is the complete Geographic ID.

OLD The row of buttons let you edit the data and the Search field lets you find specific records. QGIS can search inside individual cells and select ranges based on the content of cells.
OLD 
OLD Scroll the window to the right until you see the column NAMELSAD10. In the search field, type 4378. Then change the pull-down menu to NAMELSAD10. Click Search and the field will highlight and tract 4378 is selected in your map. It's small and you may have to look closely.

QGIS-AttTableColFilter-Dialog.gif

In the lower left click on the drop down labeled Show All Features and select the option Column Filter and then select the column NAMELSAD10. In the search box that opens, type 4378 and click Apply. The attribute table now shows only the records that match this value in the field NAMELSAD10. You can select this record by clicking on it in the left margin. The row will be highlighted. If you look back at the map you will see the tract highlighted there as well. It is small; you may have to look closely.

Advanced search

OLD Click the Advance Search button. In the Fields area, click on AWATER10. Look in the Values area and click the All button. This gives you all the values in the AWATER10 field — the square meters of surface water in each tract.

Click the Advance Filter option under the pulldown menu at the lower left of the attribute table. In the Fields area, click on AWATER10 and the Load Unique Values buttons. This gives you all the values in the AWATER10 field — the square meters of surface water in each tract.

QGIS-AttTableAdvSearch.png
QGIS-ExpressionBasedFilter01.png

The Operators buttons help you build search queries. Once you are comfortable with the syntax, you can type them directly into the text field. If there is anything in the text field now, select and delete it.

OLD *Double-click AWATER10** to add it to the text field. Click the Greater Than ( > ) button and then type 1000000. This will search for tracts with more than 1 million square meters of surface water. Click the test button and it tells you how many tracts will be selected. If you get an error, make sure the query matches the image below.

Double-click AWATER10 to add it to the text field. Scroll up in the function list box to Operators. Expand the entry and click the Greater Than ( > ) button and then type 1000000. This will search for tracts with more than 1 million square meters of surface water. Click the OK button and it will show you the tracts that meet this criterion. If you get an error, make sure the query matches the image below.

advanced-search.jpg

Click OK and return to the Layer Properties window. Click OK again to close it. You should see several tracts selected.

Save selection as a new SHP file

This is a handy tool when you need to extract a few boundaries from a large map file. You can search for and select the boundaries you need, go to the Layer menu and select Save Selections as Vector File.

Create a new folder to keep all the files organized and Voila! — a new shape file.

Save your work.