You are on page 1of 3

For U & Me

Let's Try

Map-Making

with QGIS
In Part I of this tutorial, we looked at how to visualise a shapefile, add styles and query the attribute table. In this part, let us explore how to perform geoprocessing, plot custom data and prepare a map for publishing.

e will continue to use QGIS version 1.7.3 (http://download.qgis.org) and the Alaska dataset (http://download.osgeo.org/qgis/data/ qgis_sample_data.zip).

Geometrical operations

QGIS has a number of tools for geoprocessing and data management, like nearest-neighbour analysis, buffers, union, polygon centroids, split vector layer, merge shapefiles, etc. Lets perform some of the most commonly used operations.

Part2
airports as the Input vector layer and tundra as the Intersect layer. 4. Give a name to the output file, e.g., airports_in_tundra. 5. Hit OK and click Yes on the resultant dialogue box to add the output layer to the map canvas.

The intersection of two layers

First, lets try to find out all the airports that lie in the tundra region: 1. Open tundra.shp and airports.shp as vector layers. 2. From the menu, select Vector > Geoprocessing Tools > Intersect. 3. In the Intersect dialogue box (Figure 1), select the

Polygon centroids

A layer with polygon geometry can be converted to a point layer, each point representing the centroid of the polygon: 1. Click Vector > Geometry Tools > Polygon Centroids.

Figure 1: Intersection dialogue box

Figure 2: Polygon centroid dialogue

54 | JULY 2012 | LINUX For YoU | www.LinuxForU.com

Let's Try

For U & Me

Figure 3: Split vector layer dialogue

Figure 5: New vector layer dialogue

Merge shapefiles into one

Figure 4: Merge files dialogue

2. In the dialogue box (Figure 2), select the polygon layer to be converted (in our case, add regions.shp and select it as the Input polygon vector layer). 3. Enter the path and name (e.g., regions_centroid) of the new point file. 4. Hit OK and click Yes on the resultant dialogue box to add the output layer to the map canvas.

Different shapefiles can be merged into one, provided they are of the same geometry type: 1. Click Vector > Data Management Tools. 2. Tick the check-box Select by layers in the folder. (See Figure 4.) 3. Browse to the source folder, select majrivers.shp and rivers.shp files. 4. Browse to the target folder and enter the name of the shapefile (alaska_rivers_combined.shp). 5. Mark the Add result to map canvas to directly add the result to the map canvas, and click OK.

Plotting custom features

Split vector layer

This feature allows you to split a vector file into a number of separate shapefiles, based on some attribute value: 1. Click Vector > Data Management Tools > Split Vector Layer. 2. Select the Input vector layer (see Figure 3) and the attributes to be used to split the layer (in our case, airports and the Unique ID field, respectively). 3. Browse to the folder to save output files (ours is airport_ split_by_name) and click OK.

QGIS allows us to create new layers by plotting geometries and entering attribute data. In a shapefile, one map layer can contain only one type of geometrypoint, line or polygon. Now, lets learn to draw a new point layer by assuming you want to plot sites for new airports. Let this layer have two attributes: id, name. The id attribute is a unique identifieran integer and added by default. 1. Go to the menu Layer > New > New Shapefile Layer. 2. Select Point as the geometry (see Figure 5). 3. In the New attribute section: i. Add text (e.g., name) to the Name field. ii. Select Text data from the Type drop-down. iii. Set Width to 100.
www.LinuxForU.com | LINUX For YoU | JULY 2012 | 55

For U & Me

Let's Try
You will see the new point on the map canvas. For plotting roads, rivers and mountain ranges, you could choose line as the geometry, while polygon geometry is chosen for closed entities like lakes, parks, parcels of land, etc.

Figure 6: Attributes dialogue

A map ready for publishing should contain the following details: the title, legend, data source, date, projection information, distribution licence, scale, north arrow and information about the creator. Let us now publish a map with the regions, major rivers, and trees layers. The map composer in QGIS provides a canvas to structure the map and add these data fields. Click File > New Print Composer. Use the General tab on the right to modify parameters like the size of the paper, orientation, the quality and the grid style. To add a map to the composer, click Layout > Add Map and then draw the canvas in the white area of the screen. The layout will display the layers as seen in the map canvas of the QGIS. Click the Move item content icon to pan across the map. To add a label, click Layout > Add a label. Click on the map canvas where you want to place the label. Use the Item tab on the right to style the text. Elements like the title, publishers name, data source and the date of publishing can be added as labels. Other elements like the legend, north arrow and scalebar can be added using the controls in the menu. These can be styled using the fields on the Item tab.

Map publishing

Exporting the map


Figure 7: Sample map

4. 5. 6. 7. 8.

Click the Add to Attribute List button. Click OK. Save the layer as new_airports.shp. Right-click New Airports in the Layers window. Select Toggle Editing on the pop-up. Now you are ready to plot new points. 9. Go to Edit > Capture Point. Click on those places in the map where you want to plot new airports. In the Attributes pop-up (Figure 6), type in the desired values, and hit OK.

Click File > Export as image to export the map as an image. The map can also be exported as a PDF or an SVG file.

By: Sagar Arlekar & Niket Narang


The authors are researchers at the Center for Study of Science, Technology and Policy (CSTEP), Bengaluru. They work in the fields of GIS and Agent-Based Simulation. At CSTEP they have built a web-based GIS framework to simulate and visualise disaster impact. They love working with open source tools and are active contributors to Openstreetmaps.

THE COMPLETE M AGAZINE ON OPEN SOURCE


BETA

Your favourite Linux Magazine is now on the Web, too.

LinuxForU.com
Follow us on Twitter@LinuxForYou

56 | JULY 2012 | LINUX For YoU | www.LinuxForU.com

You might also like