29
TUTORIAL GEOCOPROCESSING & SPATIAL QUERIES BY ANDREA BLINDENBACHER FALL 2012

(Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

Embed Size (px)

Citation preview

Page 1: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

TUTORIAL

GEOCOPROCESSING & SPATIAL QUERIES

BY ANDREA BLINDENBACHER

FALL 2012

Page 2: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

2

Contents INSTALL QGIS 1.8.0 Lisboa ......................................................................................................................................... 3

Windows ................................................................................................................................................................ 3

MacOS X ................................................................................................................................................................. 3

QGIS 1.8 Overview ..................................................................................................................................................... 5

DATA .......................................................................................................................................................................... 6

Tabular Data with coordinates (syringes.csv)........................................................................................................ 6

Vector Data (2010_parks_all_parkland.shp) ......................................................................................................... 7

Adding Tabular- & Vectordata ................................................................................................................................... 8

Geocoding Tabular Data (Syringes.csv) ................................................................................................................. 8

Add Vector Data (2010_parks_all_parkland.shp) ............................................................................................... 14

Saving your Project .................................................................................................................................................. 18

Geoprocessing ......................................................................................................................................................... 19

Data Analysis using the Spatial Query Tool ............................................................................................................. 22

Troubleshooting ...................................................................................................................................................... 28

“Add Delimited Text Layer”-icon missing: ........................................................................................................... 28

Layers don’t have the same Coordinate Reference System (CRS) ...................................................................... 29

Page 3: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

3

INSTALL QGIS 1.8.0 Lisboa Download page: http://hub.qgis.org/projects/quantum-gis/wiki/Download

Scroll down on the page to find your operating system(e.g. Windows, Mac, Linux) HINT: Make sure to properly download all files. If you have an unstable internet connection use a Downloadmanager like DownThemAll, which is a Firefox Add-on (https://addons.mozilla.org/en-US/firefox/addon/downthemall/).

Windows If you have a Windows platform, choose the installation files from the “Windows” section:

Select “Download QGIS”, save the download file.

Make sure to properly download it, if you have an unstable internet connection use a Download Manager like MyTorrent or DownThemAll, which is a Firefox Add-on (https://addons.mozilla.org/de/firefox/addon/downthemall/).

MacOS X If you have a Mac platform, choose the installation files from the “MacOS X” section:

1. Select “KyngChaos Qgis download page”, on this next page you first need to download the GDAL Complete and GSL frameworks.

Page 4: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

4

2. Select “GDAL Complete 1.9 framework package”

3. Select the “GDAL 1.9 Complete” Download link and save the file and install.

4. Select the “GSL framework vl. 15-2” Download link and save the file and install.

5. Select the “QGIS 1.8 0-2 for Lion & Snow Leopard” Download link and save the file and install.

Page 5: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

5

QGIS 1.8 Overview This is how QGIS looks when you open it. How many tools/icons you see might be different from this screen capture.

TOC = Table Of Contents

Shapefiles and Tables show here as so called “Layers”.

Main Window or Canvas

Data display area.

Projection Type Coordinates and Scales

Page 6: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

6

DATA

Tabular Data with coordinates (syringes.csv) http://http-server.carleton.ca/~dmckie/Algonquin%20outline_2011.htm

Download and save the file to a folder, that is dedicated to the project.

Open the file with Excel and check if your data looks like this:

IMPORTANT RULES for data to be used in QGIS

Field names (column descriptors like “Latitude”, “Longitude” or “Month”): • Must not be longer than 10 characters • Must not contain spaces, use Underscore instead “_” • Must not contain special characters: *&^%$#!@

Note: CSV stands for Comma

C Joining:

Separated Values

3 Types of Spreadsheet data

A Geocoding from Coordinates: In order to geocode points in a GIS system or Google Earth, Maps you need a column stating the X coordinate and another column, which states the Y coordinate.

B Geocoding from Adresses: The spreadsheet has to contain address information, but the information has to be separated into different columns like “Street”, “Postal Code”, “City”.

Page 7: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

7

Therefore you will need the spreadsheet containing your data plus a shapefile (e.g. Wards_2010.shp) containing geographic information. These two datasets will need a common attribute.

Example: A spreadsheet containing data about the average income of a country and a shapefile containing all country boundaries. In your Spreadsheet you will have a column containing the country NAME and your shapefile will have an attribute (column) called NAME. This common attribute will allow you to join the tabular data about the income per country to the boundary shapefile.

If you want to know more about this go to: http://qgis.spatialthoughts.com/2012/03/using-tabular-data-in-qgis.html

In this tutorial we will geocode spreadsheet data from coordinates (see A).

Vector Data (2010_parks_all_parkland.shp) http://www.ottawa.ca/en/city_hall/statisticsdata/opendata/info/index.htm Scroll down to “W” and download the “Wards 2010” data as SHP file and unzip to the same project folder as you used for the tabular data:

NOTE: The unzipped folder will contain these 6 files. Don’t do anything with them (e.g. copy to a different folder, rename, delete…)!!! The data that we will import into QGIS depends on all 6 files.

Page 8: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

8

Adding Tabular- & Vectordata

Geocoding Tabular Data (Syringes.csv)

1. Before adding the table in QGIS, open the file in Excel and create a new column called “ObjectID”. Populate it with numbers from 1 to 207. This field ensures that each syringe finding location has a unique identity. This will be important for future analysis.

2. Open QGIS and open the “Add Delimited Text Layer”- Tool Refer to the Chapter on Troubleshooting, if you don’t have this icon.

Page 9: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

9

Adjust the dialog window as follows:

1 1. Browse to your .csv file Syringes.csv 2. Choose a Layer Name 3. Select the delimiter Comma

(because a csv-file is Comma Separated Values) Note: In the bottom window you can check if your file is values are separated the way you want.

4. Choose the fields that represent your coordinates: “X field” is equal to your Y column and the ”Y field” is equal to your X column for this dataset.

5. Click OK

2

3

4

5

Page 10: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

10

Now in this window make sure to pick the coordinate reference system: “WGS 84”

Click OK Now your syringes finding locations should appear as points in your QGIS-Canvas:

NOTE: Your points might have a different color. Styling the layers can be done through the Layer properties, which is done later on in this tutorial.

Page 11: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

11

The next step is very important, although it may not be clear to you yet why it has to be done. Follow the instructions exactly.

These points have to be saved as a shapefile. Therefore R-Click the layer “syringes” and go to “Save As”

NOTE: The syringes layer is so far just a layer. If you would close your QGIS now and reopen the project, nothing would be in there. You would have to add and geocode the layer again. Therefore the layer has to be exported using the “Save As” option. This converts the layer into a shapefile, that can be added or removed without geocoding at any point in time.

Page 12: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

12

Fill in following values:

1. C Browse to the folder where you want to save the file and give it a name.

2. CRS means Coordinate Reference System. This is the most important step!: For now, don’t adjust anything, just leave it at WGS 84.

3. Select to “Add saved file to map”, this will add the shapefile directly to QGIS. If you forget, you have to add the new syringes shapefile by using the “Add Vector Layer” button:

1

2

3

NOTE: Remember that a map is a drawing of a 3D object, the earth. Imagine the earth as an inflatable ball. Now when you let the air out, it will never become completely flat, there will always be bumps and wrinkles, except you cut it open with scissors. But then you end up with holes in your earth. This is what happens when you apply a projection. A projection is an algorithm that tries to fix the holes and reduce the distortion of the shape as much as possible. There are many different projections out there to choose from, but it is vital to any project you do with GIS software, that all files (shapefiles, respectively layers) have the same projection.

Follow this link, if you want to know more about projections: http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html

Page 13: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

13

QGIS should look now like this: 2 layers, both syringes, though colors are different for each syringes layer and from this example.

Remove the old syringes layer (here with the blue point symbol) by R-Click Remove.

R-Click on the new syringes layer (here with the green point symbol) and click “Zoom to Layer Extent”.

Page 14: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

14

Add Vector Data (2010_parks_all_parkland.shp) 1. R-Click on the “Syringes” layer in the content window and select – “Set Project CRS from Layer”

The right-bottom corner of your QGIS-Canvas states now : EPSG 2951

Page 15: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

15

2. Click the “Add Vector Layer” button and brows to your “2010_parks_all_parkland.shp” shapefile Open

Make sure, that you browse for a “.shp”-file!

Page 16: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

16

The 2010_parks_all_parkland.shp shapefile will show up on top of your syringes finding locations points. Just grab the layer in the content-menu (TOC) and drag it below the syringes layer.

Data in your TOC is called “Layer”, “Shapefile” denotes the storage type in your Folder.

Page 17: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

17

Before we save our project and start geoprocessing, go to: Settings Project Properties

Here select “Enable ‘on the fly’ and the “NAD83(CRS)/MTM zone 9”Coordinate Reference System OK

Page 18: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

18

Saving your Project Before we start playing with our data, the project has to be saved:

Save your project: File/ Save Project

The project file has a “.qgs”-extension.

To open your project: L-Click on “File” and choose “Open Project”.

The advantage to open your project directly is, that you don’t have to import all the files again and worry about the Projection.

3 4

Page 19: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

19

Geoprocessing

The fundamental purposes of geoprocessing are to allow you to automate your GIS tasks and perform spatial analysis and modeling. Almost all uses of GIS involve the repetition of work, and this creates the need for methods to automate, document, and share multiple-step procedures known as workflows. Geoprocessing supports the automation of workflows by providing a rich set of tools and a mechanism to combine a series of tools in a sequence of operations using models and scripts.

The kinds of tasks to be automated can be mundane—for example, to wrangle herds of data from one format to another. Or the tasks can be quite creative, using a sequence of operations to model and analyze complex spatial relationships—for example, calculating optimum paths through a transportation network, predicting the path of wildfire, analyzing and finding patterns in crime locations, predicting which areas are prone to landslides, or predicting flooding effects of a storm event.

Geoprocessing is based on a framework of data transformation. A typical geoprocessing tool performs an operation on an GIS dataset (such as a feature class, raster, or table) and produces a new dataset as the result of the tool.

For this tutorial you will use the Buffer Tool in conjunction with a Spatial Query in order to find out which syringe-finding-places lay closest to parks. Also it might be interesting to find out which parks these are and in which ward they are located in.

Creating the Buffers around your “2010_parks_all_parkland.shp”.

Vector Geoprocessing Tools Buffer(s)

Page 20: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

20

Note: The Buffer distance is in meters. You can choose different Buffer distances and see how this affects your results.

When asked if the new shapefile should be added to the Table of Contents, add by choosing “yes”.

Close the Buffer-Tool.

1. Choose the Input vecor layer 2010_parks_all_parkland

2. Buffer distance, if your CRS is projected your distance will be in meters. Choose any distance you like (note that the results might defer).

3. Choose an output location 4. OK

1.

2.

3.

Page 21: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

21

Maybe now you want to go and rearrange your layers. Drag your parks_buffered layer to the bottom. Also it might be time to adjust the colors in the layer-properties of each layer.

Page 22: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

22

Data Analysis using the Spatial Query Tool A spatial query is a selection method that selects features in a layer based on a spatial relationship to features in another layer. For example in this tutorial we want to investigate if the syringe-finding-places are close to parklands, or in other words, we try to find a spatial relationship between parklands and syringe-finding places.

Vector Spatial Query Spatial Query

In the following window you need to define your spatial query:

1. Select the layer you want to select features from syringes

2. Select what kind of analysis, respectively which spatial relationship you want to use Within

3. Select the reference feature layer. This is the new layer of the buffered parks parks_buffered

4. Apply

Your spatial query explores now if any of the syringes-finding- places lay within 250m (since this is our buffer distance) of a parkland.

1.

2.

3.

4.

Page 23: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

23

After the query is done, this result window will pop up.

This result tells you that 140 of the syringe-finding-places lay within 250m from a park.

You can also run a spatial query using the original parkland layer without the buffering. Or you might want to try different buffer distances and then run a spatial query based on them.

Page 24: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

24

Besides your result in the spatial query result window, you will also find, that some of your syringes-points are highlighted. Zooming in, these points are the ones that fall into the buffer of 250m around the parklands.

The third place to check out the query results is the attribute table of the

Page 25: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

25

The rows highlighted in blue are the syringes-finding-places, that fall within that 250m buffer around the parklands. Using the icons at the bottom of the window you can play with your selection or you can sort by a field (column), simply by clicking a field name, R-Click and sort descending or ascending.

Page 26: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

26

So far this analysis was only done be selecting or unselecting features. But now, once you are happy with your analysis and you want to keep you selected features, maybe using them to create a nice map-image of your findings you will have to “hardcode” your selection (If you close QGIS now, you will loose your results).

R-Click on the syringes layer and select “Save Selection As”. As file type in the next window select SHAPEFILE.

Page 27: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

27

Page 28: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

28

Troubleshooting

“Add Delimited Text Layer”-icon missing: If you don’t find the “Add Delimited Text Layer” icon, follow this procedure:

1. Open the Plugin-Manager

2. Enable the “Add Delimited Text Layer” Plugin:

If you don’t find the “Add Delimited Text Layer” Tool in your Plugin Manager, follow this procedure, of course choosing the appropriate tool.

http://qgis.spatialthoughts.com/2010/10/using-plugins-in-quantum-gis_05.html

Page 29: (Andrea Blindenbacher, Oct. 21, 2012) QGIS Tutorial_SyringesNearParks

QGIS 1.8.0 Lisboa Tutorial

29

Layers don’t have the same Coordinate Reference System (CRS) If this warning appears, stop whatever you were up to.

This means that your layers don’t have the same coordinate reference system(CRS).

Do this for every layer in your TOC (Table of Content):

1. R-Click on layer 2. Save As 3. Specify the coordinate Reference system by using the “Browse” button. Specify the same CRS

for each layer in your TOC.