QGIS User Guide - OSGeo Server

QGIS User Guide - OSGeo Server

5 WORKING WITH VECTOR DATA

5. Working with Vector Data

QGIS supports vector data in a number of formats, including those supported by the OGR library data provider plugin, such as ESRI shapefiles, MapInfo MIF (interchange format) and MapInfo TAB

(native format). You find a list of OGR supported vector formats in Appendix

A.1

.

QGIS also supports PostGIS layers in a PostgreSQL database using the PostgreSQL data provider plugin. Support for additional data types (eg. delimited text) is provided by additional data provider plugins.

This section describes how to work with several common formats: ESRI shapefiles, PostGIS layers, and SpatialLite layers. Many of the features available in QGIS work the same, regardless of the vector data source. This is by design and includes the identify, select, labeling and attributes functions.

Working with GRASS vector data is described in Section

9 .

5.1. ESRI Shapefiles

The standard vector file format used in QGIS is the ESRI Shapefile. Support is provided by the OGR

Simple Feature Library ( http://www.gdal.org/ogr/

) . A shapefile actually consists of several files.

The following three are required:

• .shp

file containing the feature geometries.

• .dbf

file containing the attributes in dBase format.

• .shx

index file.

Shapefiles also can include a file with a .prj

suffix, which contains the projection information.

While it is very useful to have a projection file, it is not mandatory.

A shapefile dataset can contain additional files.

For further details see the ESRI technical specification at http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf

.

Problem loading a shape .prj file

If you load a shapefile with .prj

file and QGIS is not able to read the coordinate reference system from that file, you have to define the proper projection manually within the General tab of the

Layer Properties dialog. This is due to the fact, that .prj

files often do not provide the complete projection parameters, as used in QGIS and listed in the CRS dialog.

For that reason, if you create a new shapefile with QGIS, two different projection files are created. A

.prj

file with limited projection parameters, compatible with ESRI software, and a

.qpj

file, providing the complete parameters of the used CRS. Whenever QGIS finds a .qpj

file, it will be used instead

QGIS 1.4.0 User Guide 36

.

of the .prj

.

5.1.1. Loading a Shapefile

Figure 6: Add Vector Layer Dialog

5.1

ESRI Shapefiles type

To load a shapefile, start QGIS and click on the

Add Vector Layer toolbar button or simply

¨

Ctrl-Shift-V . This will bring up a new window (see Figure 6 ).

§

¥

¦

From the available options check ⊙ File. Click on Browse . That will bring up a standard open file dialog (see Figure

7 ) which allows you to navigate the file system and load a shapefile or other

supported data source. The selection box Files of type . . .

H supported file formats.

allows you to preselect some OGR

You can also select the Encoding type for the shapefile if desired.

Selecting a shapefile from the list and clicking Open loads it into QGIS. Figure

8

shows QGIS after loading the alaska.shp

file.

Tip 8 L

AYER

C

OLORS

When you add a layer to the map, it is assigned a random color. When adding more than one layer at a time, different colors are assigned to each layer.

Once loaded, you can zoom around the shapefile using the map navigation tools. To change the symbology of a layer, open the Layer Properties dialog by double clicking on the layer name or

QGIS 1.4.0 User Guide 37

5 WORKING WITH VECTOR DATA

Figure 7: Open an OGR Supported Vector Layer Dialog by right-clicking on the name in the legend and choosing Properties from the popup menu. See

Section

5.4.1

for more information on setting symbology of vector layers.

Tip 9 L

OAD LAYER AND PROJECT FROM MOUNTED EXTERNAL DRIVES ON

OS X

On OS X, portable drives that are mounted besides the primary hard drive do not show up under File -> Open

Project as expected. We are working on a more OSX-native open/save dialog to fix this. As a workaround you can type ’/Volumes’ in the File name box and press return. Then you can navigate to external drives and network mounts.

5.1.2. Improving Performance

To improve the performance of drawing a shapefile, you can create a spatial index. A spatial index will improve the speed of both zooming and panning. Spatial indexes used by QGIS have a .qix

extension.

Use these steps to create the index:

• Load a shapefile.

• Open the Layer Properties dialog by double-clicking on the shapefile name in the legend or

QGIS 1.4.0 User Guide 38

Figure 8: QGIS with Shapefile of Alaska loaded

5.1

ESRI Shapefiles by right-clicking and choosing Properties from the popup menu.

In the tab General click the Create Spatial Index button.

5.1.3. Loading a MapInfo Layer

To load a MapInfo layer, click on the

Add Vector Layer toolbar bar button or type

¨

Ctrl-Shift-V ,

§

¥

¦ change the file type filter to Files of Type [OGR] MapInfo (*.mif *.tab *.MIF *.TAB)

H and select the layer you want to load.

QGIS 1.4.0 User Guide 39

5 WORKING WITH VECTOR DATA

5.1.4. Loading an ArcInfo Binary Coverage

To load an ArcInfo binary coverage click on the type

Add Vector Layer toolbar button or

¨

Ctrl-Shift-V to open the Add Vector Layer dialog.

Select

Directory.

Change to

§

¥

¦

Type Arc/Info Binary Coverage

H

. Navigate to the directory that contains the coverage files and select it.

Similarly, you can load directory based vector files in the UK National Transfer Format as well as the raw TIGER Format of the US Census Bureau.

5.2. PostGIS Layers

PostGIS layers are stored in a PostgreSQL database. The advantages of PostGIS are the spatial indexing, filtering and query capabilities it provides. Using PostGIS, vector functions such as select and identify work more accurately than with OGR layers in QGIS.

To use PostGIS layers you must:

• Create a stored connection in QGIS to the PostgreSQL database (if one is not already defined).

Connect to the database.

Select the layer to add to the map.

• Optionally provide a SQL where clause to define which features to load from the layer.

• Load the layer.

5.2.1. Creating a stored Connection

The first time you use a PostGIS data source, you must create a connection to the PostgreSQL database that contains the data. Begin by clicking on the selecting the

Add PostGIS Layer toolbar button,

Add PostGIS Layer... option from the Layer menu or typing

¨

Ctrl-Shift-D . You can

§

¥

¦ also open the Add Vector Layer dialog and select

Database. The

Add PostGIS Table(s)

dialog will be displayed. To access the connection manager, click on the New button to display the

Create a New PostGIS Connection dialog. The parameters required for a connection are shown in table

1 .

Optional you can activate follwing checkboxes:

QGIS 1.4.0 User Guide 40

5.2

PostGIS Layers

Table 1: PostGIS Connection Parameters

Name

Host

A name for this connection. Can be the same as Database.

Name of the database host. This must be a resolvable host name the same as would be used to open a telnet connection or ping the host. If the database is on the same computer as QGIS, simply enter ’localhost’ here.

Database Name of the database.

Port Port number the PostgreSQL database server listens on. The default port is 5432.

Username User name used to login to the database.

Password Password used with Username to connect to the database.

SSL mode How the SSL connection will be negotiated with the server. These are the options:

• disable: only try an unencrypted SSL connection;

• allow: try a non-SSL connection, if that fails, try an SSL connection;

• prefer (the default): try an SSL connection, if that fails, try a non-SSL connection;

• require: only try an SSL connection.

Note that massive speedups in PostGIS layer rendering can be achieved by disabling SSL in the connection editor.

• x Save Password

• x Only look in the geometry_columns table

• x Only look in the ’public’ schema

Once all parameters and options are set, you can test the connection by clicking on the

Test Connect button.

Tip 10 QGIS U

SER

S

ETTINGS AND

S

ECURITY

Your customized settings for QGIS are stored based on the operating system.

, the settings are stored in your home directory in .qt/qgisrc .

, the settings are stored in the registry. Depending on your computing environment, storing passwords in your QGIS settings may be a security risk.

QGIS 1.4.0 User Guide 41

5 WORKING WITH VECTOR DATA

5.2.2. Loading a PostGIS Layer

Once you have one or more connections defined, you can load layers from the PostgreSQL database. Of course this requires having data in PostgreSQL. See Section

5.2.4

for a discussion on importing data into the database.

To load a layer from PostGIS, perform the following steps:

If the

Add PostGIS Table(s)

dialog is not already open, click on the

Add PostGIS Layer toolbar button.

Choose the connection from the drop-down list and click Connect .

Find the layer you wish to add in the list of available layers.

Select it by clicking on it. You can select multiple layers by holding down the

¨ shift key while

§

¥

¦ clicking. See Section

5.6

for information on using the PostgreSQL Query Builder to further define the layer.

Click on the Add button to add the layer to the map.

Tip 11 P

OST

GIS L

AYERS

Normally a PostGIS layer is defined by an entry in the geometry_columns table. From version 1.3.0 on, QGIS can load layers that do not have an entry in the geometry_columns table. This includes both tables and views.

Defining a spatial view provides a powerful means to visualize your data. Refer to your PostgreSQL manual for information on creating views.

5.2.3. Some details about PostgreSQL layers

This section contains some details on how QGIS accesses PostgreSQL layers. Most of the time

QGIS should simply provide you with a list of database tables that can be loaded, and load them on request. However, if you have trouble loading a PostgreSQL table into QGIS, the information below may help you understand any QGIS messages and give you direction on changing the PostgreSQL table or view definition to allow QGIS to load it.

QGIS requires that PostgreSQL layers contain a column that can be used as a unique key for the layer. For tables this usually means that the table needs a primary key, or a column with a unique constraint on it. In QGIS, this column needs to be of type int4 (an integer of size 4 bytes). Alternatively the ctid column can be used as primary key. If a table lacks these items, the oid column will be used instead. Performance will be improved if the column is indexed (note that primary keys are automatically indexed in PostgreSQL).

QGIS 1.4.0 User Guide 42

5.2

PostGIS Layers

If the PostgreSQL layer is a view, the same requirement exists, but views don’t have primary keys or columns with unique constraints on them. In this case QGIS will try to find a column in the view that is derived from a suitable table column. It does this by parsing the view definition SQL. However there are several aspects of SQL that QGIS ignores - these include the use of table aliases and columns that are generated by SQL functions.

If a suitable column cannot be found, QGIS will not load the layer. If this occurs, the solution is to alter the view so that it does include a suitable column (a type of int4 and either a primary key or with a unique constraint, preferably indexed).

When dealing with views, QGIS parses the view definition and

5.2.4. Importing Data into PostgreSQL shp2pgsql

Data can be imported into PostgreSQL using a number of methods. PostGIS includes a utility called shp2pgsql that can be used to import shapefiles into a PostGIS enabled database. For example, to import a shapefile named lakes.shp

into a PostgreSQL database named gis_data

, use the following command: shp2pgsql -s 2964 lakes.shp lakes_new | psql gis_data

This creates a new layer named lakes_new in the gis_data database. The new layer will have a spatial reference identifier (SRID) of 2964. See Section

8

for more information on spatial reference systems and projections.

Tip 12 E

XPORTING DATASETS FROM

P

OST

GIS

Like the import-tool shp2pgsql there is also a tool to export PostGIS-datasets as shapefiles: pgsql2shp . This is shipped within your PostGIS distribution.

SPIT Plugin

QGIS comes with a plugin named SPIT (Shapefile to PostGIS Import Tool). SPIT can be used to load multiple shapefiles at one time and includes support for schemas. To use SPIT, open the Plugin

Manager from the Plugins menu, check the box next to the x SPIT plugin and click OK . The

SPIT icon will be added to the plugin toolbar.

To import a shapefile, click on the

SPIT tool in the toolbar to open the

SPIT - Shapefile to PostGIS Import Tool dialog. Select the PostGIS database you want to con-

QGIS 1.4.0 User Guide 43

5 WORKING WITH VECTOR DATA nect to and click on Connect . Now you can add one or more files to the queue by clicking on the

Add button. To process the files, click on the OK button. The progress of the import as well as any errors/warnings will be displayed as each shapefile is processed.

Tip 13 I

MPORTING

S

HAPEFILES

C

ONTAINING

P

OSTGRE

SQL R

ESERVED

W

ORDS

If a shapefile is added to the queue containing fields that are reserved words in the PostgreSQL database a dialog will popup showing the status of each field. You can edit the field names prior to import and change any that are reserved words (or change any other field names as desired). Attempting to import a shapefile with reserved words as field names will likely fail.

ogr2ogr

Beside shp2pgsql and SPIT there is another tool for feeding geodata in PostGIS: ogr2ogr . This is part of your GDAL installation. To import a shapefile into PostGIS, do the following: ogr2ogr -f "PostgreSQL" PG:"dbname=postgis host=myhost.de user=postgres \ password=topsecret" alaska.shp

This will import the shapefile alaska.shp

into the PostGIS-database postgis using the user postgres with the password topsecret on host myhost.de.

Note that OGR must be built with PostgreSQL to support PostGIS. You can see this by typing ogrinfo --formats | grep -i post

If you like to use PostgreSQL’s COPY -command instead of the default INSERT INTO method you can export the following environment-variable (at least available on and ): export PG_USE_COPY=YES ogr2ogr does not create spatial indexes like shp2pgsl does. You need to create them manually using the normal SQL-command

CREATE INDEX afterwards as an extra step (as described in the next section

5.2.5

).

5.2.5. Improving Performance

Retrieving features from a PostgreSQL database can be time consuming, especially over a network.

You can improve the drawing performance of PostgreSQL layers by ensuring that a spatial index exists on each layer in the database. PostGIS supports creation of a GiST (Generalized Search Tree) index to speed up spatial searches of the data.

QGIS 1.4.0 User Guide 44

5.2

PostGIS Layers

The syntax for creating a GiST

3 index is:

CREATE INDEX [indexname] ON [tablename]

USING GIST ( [geometryfield] GIST_GEOMETRY_OPS );

Note that for large tables, creating the index can take a long time. Once the index is created, you should perform a VACUUM ANALYZE . See the PostGIS documentation [? ] for more information.

The following is an example of creating a GiST index: [email protected]:~/current$ psql gis_data

Welcome to psql 8.3.0, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms

\h for help with SQL commands

\? for help with psql commands

\g or terminate with semicolon to execute query

\q to quit gis_data=# CREATE INDEX sidx_alaska_lakes ON alaska_lakes gis_data-# USING GIST (the_geom GIST_GEOMETRY_OPS);

CREATE INDEX gis_data=# VACUUM ANALYZE alaska_lakes;

VACUUM gis_data=# \q [email protected]:~/current$

5.2.6. Vector layers crossing 180

longitude

Many GIS packages don’t wrap vector maps, with a geographic reference system (lat/lon), crossing the

180 ◦ longitude line. As result, if we open such map in QGIS, we will see two far, distinct locations, that should show near each other. In Figure

9

the tiny point on the far left of the map canvas (Chatham

Islands), should be within the grid, right of New Zealand main islands.

A workaround is to transform the longitude values using PostGIS and the ST_Shift_Longitude

4 function. This function reads every point/vertex in every component of every feature in a geometry, and if the longitude coordinate is <

0

◦ adds

360

◦ to it. The result would be a

0

◦ -

360

◦ version of the data to be plotted in a

180 ◦ centric map.

3

GiST index information is taken from the PostGIS documentation available at http://postgis.refractions.net

4 http://postgis.refractions.net/documentation/manual-1.4/ST_Shift_Longitude.html

QGIS 1.4.0 User Guide 45

5 WORKING WITH VECTOR DATA

Figure 9: Map in lat/lon crossing the

180 ◦ longitude line

Figure 10: Map crossing

180 ◦ longitude applying the ST_Shift_Longitude function

Usage

Import data to PostGIS ( 5.2.4

) using for example the PostGIS Manager plugin or the SPIT plugin

Use the PostGIS command line interface to issue the following command (this is an example where "TABLE" is the actual name of your PostGIS table) gis_data=# update TABLE set the_geom=ST_shift_longitude(the_geom);

If everything went right you should receive a confirmation about the number of features that were updated, then you’ll be able to load the map and see the difference (Figure

10 )

5.3. SpatiaLite Layers

The first time you load data from a Spatialite database, begin by clicking on the

Add SpatiaLite Layer toolbar button or by selecting the

Add SpatiaLite Layer... option from the

Layer menu or by typing

¨

L . This will bring up a window, which will allow you to either connect to

§

¥

¦

QGIS 1.4.0 User Guide 46

5.4

The Vector Properties Dialog a Spatialite database already known to QGIS, which you can choose from the dropdown menu or to define a new connection to a new database. To define a new connection, click on New and use the file browser to point to your SpatiaLite database, which is a file with a

.sqlite

extension.

5.4. The Vector Properties Dialog

The Layer Properties dialog for a vector layer provides information about the layer, symbology settings and labeling options. If your vector layer has been loaded from a PostgreSQL/PostGIS datastore, you can also alter the underlying SQL for the layer by invoking the Query Builder dialog on the General tab. To access the Layer Properties dialog, double-click on a layer in the legend or right-click on the layer and select Properties from the popup menu.

Figure 11: Vector Layer Properties Dialog

QGIS 1.4.0 User Guide 47

5 WORKING WITH VECTOR DATA

5.4.1. Symbology Tab

QGIS supports a number of symbology renderers to control how vector features are displayed. Currently the following renderers are available:

Single symbol - a single style is applied to every object in the layer.

Graduated symbol - objects within the layer are displayed with different symbols classified by the values of a particular field.

Continuous color - objects within the layer are displayed with a spread of colours classified by the numerical values within a specified field.

Unique value - objects are classified by the unique values within a specified field with each value having a different symbol.

To change the symbology for a layer, simply double click on its legend entry and the vector

Layer Properties dialog will be shown.

Style Options

Within this dialog you can style your vector layer. Depending on the selected rendering option you have the possibility to also classify your mapfeatures.

At least the following styling options apply for nearly all renderers:

Fill options Fill style - Style for filling. Beside the given brushes you can select ? Texture

H and click the

. . .

button for selecting your own texture file. Currently the fileformats

*.jpeg, *.xpm, and *.png

are supported.

Fill color - fill-color of your features.

Outline options Outline style - pen-style for your outline of your feature. You can also set this to

’no pen’.

Outline color - color of the ouline of your feature

Outline width - width of your features

Once you have styled your layer you also could save your layer-style to a separate file (with

*.qml

ending). To do this, use the button Save Style . . .

. No need to say that Load Style . . .

loads your saved layer-style-file.

If you wish to always use a particular style whenever the layer is loaded, use the Save As Default button to make your style the default. Also, if you make changes to the style that you are not happy with, use the Restore Default Style button to revert to your default style.

QGIS 1.4.0 User Guide 48

Figure 12: Symbolizing Options

5.4

The Vector Properties Dialog

(a) Single symbol (b) Graduated symbol

(c) Continous color (d) Unique value

Vector transparency

QGIS allows to set a transparency for every vector layer.

This can be done with the slider

Transparency 0%

▽ inside the symbology tab (see fig.

11 ). This is very useful for

overlaying several vector layers.

5.4.2. New Generation Symbology

In QGIS 1.4.0 a new symbology was integrated in parallel with the symbology described above. This new generation symbology provides a variety of improvements and new features and will replace the current symbology in one of the upcoming releases. To switch to the new symbolgy you currently have to click on the new symbology button in the General tab of the Layer Properties dialog.

QGIS 1.4.0 User Guide 49

5 WORKING WITH VECTOR DATA

Understanding the new generation symbology

There are three types of symbols: marker symbols (for points), line symbols and fill symbols (for polygons). Symbols can consist of one or more symbol layers. It is possible to define the color of a symbol and this color is then defined for all symbol layers. Some layers may have the color locked for those the color can not be altered. This is useful when you define the color of a multilayer symbol.

Similarly, it is possible to define the width for line symbols, as well as size and angle for marker symbols.

Available symbol layer types

Simple marker: Rendering with one of hardcoded markers.

Simple line: Usual rendering of a line (with specified width, color and pen style)

Simple fill: Usual rendering of a polygon (with defined fill color, fill pattern and outline)

SVG marker: Rendering with a SVG picture

Marker line: A line rendered by repeating a marker symbol

Color ramps

Color ramps are used to define a range of colors that can be used during the creation of renderers.

The symbol’s color will be set from the color ramp. There are two types of color ramps:

Gradient: Linear gradient from one color to some other.

random: Randomly generated colors from a specified area of color space

Styles

A style groups a set of various symbols and color ramps. You can define your prefered or frequently used symbols, and can use it without having to recreate it everytime. Style items (symbols and color ramps) have always a name by which they can be queried from the style. There is one default style in QGIS (modifiable) and the user can add further styles.

Renderers

The renderer is responsible for drawing a feature together with the correct symbol. There are three types of renderers: single symbol, categorized (called unique color in the old symbology), and graduated. There is no continuous color renderer, because it is in fact only a special case of the graduated renderer. The categorized and graduated renderer can be created by specifying a symbol and a color ramp - they will set the colors for symbols appropriately.

QGIS 1.4.0 User Guide 50

5.4

The Vector Properties Dialog

5.4.3. Working with the New Generation Symbology

First you have to enable the new generation symbology clicking on the new symbology button in the General tab of the Layer Properties dialog. The new dialog allows to choose one of the three renderers: single symbol, categorized and graduated. Depending on the chosen renderer, the symbology tab provides different settings and options, that will be described in the following sections.

Single Symbol Renderer

The Single Symbol Renderer is used to render all features of the layer using a single user-defined symbol. The properties, that can be adjusted in the Symbology tab, depend partially on the type of the layer, but all types share the following structure. In the top left part of the tab, there is a preview of the current symbol to be rendered. In the bottom part of the tab, there is a list of symbols already defined for the current style, prepared to be used via selecting them from the list. The current symbol can be modified using the Properties button, which opens a Symbol Properties dialog, or the

Set Color button, which opens an ordinary Color dialog. After having done any needed changes, the symbol can be added to the list of current style symbols (using the Add to style button) and then easily be used in the future.

Figure 13: New Single Symbolizing options

(a) Single symbol point properties (b) Single symbol line properties (c) Single symbol area properties

Categorized Renderer

The Categorized Renderer is used to render all features from a layer, using a single user-defined symbol, which color reflects the value of a selected feature’s attribute. The Symbology tab allows you to select:

• The attribute (using the Column listbox)

• The symbol (using the Symbol Properties dialog)

The colors (using the Color Ramp listbox)

QGIS 1.4.0 User Guide 51

5 WORKING WITH VECTOR DATA

For convenience, the list in the bottom part of the tab lists the values of all currently selected attributes together, including the symbols that will be rendered.

The example in figure

14

shows the category rendering dialog used for the rivers layer of the qgis sample dataset.

Figure 14: New Categorized Symbolizing options

Graduated rendering

The Graduated Renderer is used to render all the features from a layer, using a single user-defined symbol, whose color reflects the classification of a selected feature’s attribute to a class.

Analogue to the categorized rendered, the symbology tab allows you to select:

• The attribute (using the Column listbox)

• The symbol (using the Symbol Properties button)

The colors (using the Color Ramp list)

Additionally, you can specify the number of classes and also the mode how to classify features inside the classes (using the Mode list). The listbox in the bottom part of the symbology tab lists the classes together with their ranges, labels and symbols that will be rendered.

The example in figure

15

shows the category rendering dialog for the rivers layer of the qgis sample dataset.

QGIS 1.4.0 User Guide 52

5.4

The Vector Properties Dialog

Figure 15: New Graduated Symbolizing options

Symbol Properties

The symbol properties dialog allows the user to specify different properties of the symbol to be rendered. In the top left part of the dialog, you find a preview of the current symbol as it will be displayed in the map canvas. Below the preview is the list of symbol layers. To start the symbol properties dialog, click the

Properties button in the General tab of the Layer Properties dialog.

The control panels allow adding or removing layers, changing the position of layers, or locking layers for color changes. In the right part of the dialog, there are shown the settings applicable to the single symbol layer selected in the symbol layer list. The most important is the ’Symbol Layer Type’ combo box, which allows you to choose the layer type. The available options are SimpleLine , SvgMarker and SimpleFill .

Depending on the chosen value, these settings are available in the right part of the dialog:

SimpleLine: Color, Pen width, Pen style, Offset, Join style and Cap style;

SvgMarker: Size, Angle, Offset X, Offset Y and SVG Image

SimpleFill: Color, Border color, Fill style.

Example: A picture showing a line symbol composed from three simple lines with different pen widths.

Example: Symbol properties for a point layer Example: Symbol properties filling pattern for a polygon layer

QGIS 1.4.0 User Guide 53

5 WORKING WITH VECTOR DATA

Figure 16: Defining symbol properties

(a) Line composed from three simple lines

(b) Symbol properties for point layer (c) Filling pattern for a polygon

5.4.4. Style Manager to manage symbols and color ramps

The Style Manger is a small helper application, that lists symbols and color ramps available in a style.

It also allows you to add and/or remove items. To launch the Style Manager, click on Settings >

Style Manager in the mai menu.

Figure 17: Style Manager to manage symbols and color ramps

QGIS 1.4.0 User Guide 54

5.4

The Vector Properties Dialog

5.4.5. Labels Tab

The Labels tab allows you to enable labeling features and control a number of options related to fonts, placement, style, alignment and buffering.

We will illustrate this by labelling the lakes shapefile of the qgis_example_dataset

:

1. Load the Shapefile alaska.shp

and GML file lakes.gml

in QGIS.

2. Zoom in a bit to your favorite area with some lake.

3. Make the lakes layer active.

4. Open the Layer Properties dialog.

5. Click on the Labels tab.

6. Check the x Display labels checkbox to enable labeling.

7. Choose the field to label with. We’ll use Field containing label NAMES

H

.

8. Enter a default for lakes that have no name. The default label will be used each time QGIS encounters a lake with no value in the NAMES field.

9. If have labels extending over several lines, check x Multiline labels? . QGIS will check for a true line return in your label field and insert the line breaks accordingly. A true line return is a

single character \n, (not two separate characters, like a backlash \ followed by the character n).

10. Click Apply .

Now we have labels. How do they look? They are probably too big and poorly placed in relation to the marker symbol for the lakes.

Select the Font entry and use the Font and Color buttons to set the font and color. You can also change the angle and the placement of the text-label.

To change the position of the text relative to the feature:

1. Click on the Font entry.

2. Change the placement by selecting one of the radio buttons in the Placement group. To fix our labels, choose the

Right radio button.

3. the Font size units allows you to select between

Points or

Map units.

4. Click Apply to see your changes without closing the dialog.

QGIS 1.4.0 User Guide 55

5 WORKING WITH VECTOR DATA

Things are looking better, but the labels are still too close to the marker. To fix this we can use the options on the Position entry. Here we can add offsets for the X and Y directions. Adding an X offset of 5 will move our labels off the marker and make them more readable. Of course if your marker symbol or font is larger, more of an offset will be required.

The last adjustment we’ll make is to buffer the labels. This just means putting a backdrop around them to make them stand out better. To buffer the lakes labels:

1. Click the Buffer tab.

2. Click the x Buffer Labels? checkbox to enable buffering.

3. Choose a size for the buffer using the spin box.

4. Choose a color by clicking on Color and choosing your favorite from the color selector. You can also set some transparency for the buffer if you prefer.

5. Click Apply to see if you like the changes.

If you aren’t happy with the results, tweak the settings and then test again by clicking Apply .

A buffer of 1 points seems to give a good result. Notice you can also specify the buffer size in map units if that works out better for you.

The remaining entries inside the Label tab allow you control the appearance of the labels using attributes stored in the layer. The entries beginning with Data defined allow you to set all the parameters for the labels using fields in the layer.

Not that the Label tab provides a preview-box where your selected label is shown.

5.4.6. Attributes Tab

Within the Attributes tab the attributes of the selected dataset can be manipulated. The buttons

New Column and Delete Column can be used, when the dataset is editing mode . At the moment only columns from PostGIS layers can be removed and added. The

OGR library supports to add new columns, but not to remove them, if you have a GDAL version >=

1.6 installed.

QGIS 1.4.0 User Guide 56

edit widget

5.4

The Vector Properties Dialog

Figure 18: Dialog to select an edit widget for an attribute column

Within the Attributes tab you also find an edit widget column. This column can be used to define values or a range of values that are allowed to be added to the specific attribute table column. If you click on the edit widget button, a dialog opens, where you can define different widgets. These widgets are:

• Line edit: an edit field which allows to enter simple text (or restrict to numbers for numeric attributes).

Classification: Displays a combo box with the values used for classification, if you have chosen

’unique value’ as legend type in the symbology tab of the properties dialog.

• Range: Allows to set numeric values from a specific range. The edit widget can be either a slider or a spin box.

Unique value: The user can select one of the values already used in the attribute table. If editable is activated, a line edit is shown with autocompletion support, otherwise a combo box is used.

File name: Simplifies the selection by adding a file chooser dialog.

QGIS 1.4.0 User Guide 57

5 WORKING WITH VECTOR DATA

Value map: a combo box with predefined items. The value is stored in the attribute, the description is shown in the comboo box. You can define values manually or load them from a layer or a csv file.

Enumeration: Opens a combo box with values that can be used within the columns type. This is currently only supported by the postgres provider.

• Immutable: The immutable attribute column is read-only. The user is not able to modify the content.

5.4.7. General Tab

The General tab is essentially like that of the raster dialog. It allows you to change the display name, set scale dependent rendering options, create a spatial index of the vector file (only for OGR supported formats and PostGIS) and view or change the projection of the specific vetor layer.

The Query Builder button allows you to create a subset of the features in the layer - but this button currently only is available when you open the attribute table and select the ...

button next to

Advanced search.

5.4.8. Metadata Tab

The Metadata tab contains general information about the layer, including specifics about the type and location, number of features, feature type, and the editing capabilities. The Extents section, providing layer extent information, and the Layer Spatial Reference System section, providing information about the CRS of the layer. This is a quick way to get information about the layer, but is not yet editable.

5.4.9. Actions Tab

QGIS provides the ability to perform an action based on the attributes of a feature. This can be used to perform any number of actions, for example, running a program with arguments built from the attributes of a feature or passing parameters to a web reporting tool.

Actions are useful when you frequently want to run an external application or view a web page based on one or more values in your vector layer. An example is performing a search based on an attribute value. This concept is used in the following discussion.

QGIS 1.4.0 User Guide 58

5.4

The Vector Properties Dialog

Defining Actions

Attribute actions are defined from the vector Layer Properties dialog. To define an action, open the vector Layer Properties dialog and click on the Actions tab. Provide a descriptive name for the action. The action itself must contain the name of the application that will be executed when the action is invoked. You can add one or more attribute field values as arguments to the application.

When the action is invoked any set of characters that start with a % followed by the name of a field will be replaced by the value of that field. The special characters %% will be replaced by the value of the field that was selected from the identify results or attribute table (see Using Actions below). Double quote marks can be used to group text into a single argument to the program, script or command.

Double quotes will be ignored if preceded by a backslash.

If you have field names that are substrings of other field names (e.g., col1 and col10 ) you should indicate so, by surrounding the field name (and the % character) with square brackets (e.g., [%col10] ).

This will prevent the

%col10 field name being mistaken for the

%col1 field name with a

0 on the end.

The brackets will be removed by QGIS when it substitutes in the value of the field. If you want the substituted field to be surrounded by square brackets, use a second set like this: [[%col10]] .

The Identify Results dialog box includes a (Derived) item that contains information relevant to the layer type. The values in this item can be accessed in a similar way to the other fields by using preceeding the derived field name by (Derived).

. For example, a point layer has an X and Y field and the value of these can be used in the action with

%(Derived).X

and

%(Derived).Y

. The derived attributes are only available from the Identify Results dialog box, not the Attribute Table dialog box.

Two example actions are shown below:

• konqueror http://www.google.com/search?q=%nam

• konqueror http://www.google.com/search?q=%%

In the first example, the web browser konqueror is invoked and passed a URL to open. The URL performs a Google search on the value of the nam field from our vector layer. Note that the application or script called by the action must be in the path or you must provided the full path. To be sure, we could rewrite the first example as:

/opt/kde3/bin/konqueror http://www.google.com/search?q=%nam

.

This will ensure that the konqueror application will be executed when the action is invoked.

The second example uses the %% notation which does not rely on a particular field for its value.

When the action is invoked, the %% will be replaced by the value of the selected field in the identify results or attribute table.

QGIS 1.4.0 User Guide 59

5 WORKING WITH VECTOR DATA

Using Actions

Actions can be invoked from either the Identify Results dialog or an Attribute Table dialog.

(Recall that these dialogs can be opened by clicking

Identify Features or

Open Attribute Table .) To invoke an action, right click on the record and choose the action from the popup menu. Actions are listed in the popup menu by the name you assigned when defining the actions. Click on the action you wish to invoke.

If you are invoking an action that uses the %% notation, right-click on the field value in the

Identify Results dialog or the Attribute Table dialog that you wish to pass to the application or script.

Here is another example that pulls data out of a vector layer and inserts them into a file using bash and the echo command (so it will only work or perhaps ). The layer in question has fields for a species name taxon_name

, latitude lat and longitude long

. I would like to be able to make a spatial selection of a localities and export these field values to a text file for the selected record (shown in yellow in the QGIS map area). Here is the action to achieve this: bash -c "echo \"%taxon_name %lat %long\" >> /tmp/species_localities.txt"

After selecting a few localities and running the action on each one, opening the output file will show something like this:

Acacia mearnsii -34.0800000000 150.0800000000

Acacia mearnsii -34.9000000000 150.1200000000

Acacia mearnsii -35.2200000000 149.9300000000

Acacia mearnsii -32.2700000000 150.4100000000

As an exercise we create an action that does a Google search on the lakes layer. First we need to determine the URL needed to perform a search on a keyword. This is easily done by just going to Google and doing a simple search, then grabbing the URL from the address bar in your browser.

From this little effort we see that the format is: http://google.com/search?q=qgis , where qgis is the search term. Armed with this information, we can proceed:

1. Make sure the lakes layer is loaded.

2. Open the Layer Properties dialog by double-clicking on the layer in the legend or right-click and choose Properties from the popup menu.

3. Click on the Actions tab.

4. Enter a name for the action, for example Google Search .

QGIS 1.4.0 User Guide 60

5.4

The Vector Properties Dialog

5. For the action, we need to provide the name of the external program to run. In this case, we can use Firefox. If the program is not in your path, you need to provide the full path.

6. Following the name of the external application, add the URL used for doing a Google search, up to but not included the search term: http://google.com/search?q=

7. The text in the Action field should now look like this: firefox http://google.com/search?q=

8. Click on the drop-down box containing the field names for the lakes layer. It’s located just to the left of the Insert Field button.

9. From the drop-down box, select NAMES

H and click Insert Field .

10. Your action text now looks like this: firefox http://google.com/search?q=%NAMES

11. Fo finalize the action click the Insert action button.

This completes the action and it is ready to use. The final text of the action should look like this: firefox http://google.com/search?q=%NAMES

We can now use the action. Close the Layer Properties dialog and zoom in to an area of interest.

Make sure the lakes layer is active and identify a lake. In the result box you’ll now see that our action is visible:

Figure 19: Select feature and choose action

QGIS 1.4.0 User Guide 61

5 WORKING WITH VECTOR DATA

When we click on the action, it brings up Firefox and navigates to the URL http://www.google.com/search?q=Tustumena . It is also possible to add further attribute fields to the action. Therefore you can add a “+” to the end of the action text, select another field and click on

Insert Field . In this example there is just no other field available that would make sense to search for.

You can define multiple actions for a layer and each will show up in the Identify Results dialog.

You can think of all kinds of uses for actions. For example, if you have a point layer containing locations of images or photos along with a file name, you could create an action to launch a viewer to display the image. You could also use actions to launch web-based reports for an attribute field or combination of fields, specifying them in the same way we did in our Google search example.

5.4.10. Diagram Tab

The Diagram tab allows you to add a grahic overlay to a vector layer. To activate this feature, open the Plugin Manager and select the Diagram Overlay’ plugin. After this, there is a new tab in the vector

Layer Properties dialog where the settings for diagrams may be entered (see figure

20 ).

The current implementation of diagrams provides support for pie- and barcharts and for linear scaling of the diagram size according to a classification attribute. We will demonstrate an example and overlay the alaska boundary layer a barchart diagramm showing some temperature data from a climate vector layer. Both vector layers are part of the QGIS sample dataset (see Section

3.2

.

1. First click on the

Load Vector icon, browse to the QGIS sample dataset folder and load the two vector shape layers alaska.shp

and climate.shp

.

2. Double click the climate layer in the map legend to open the Layer Properties dialog.

3. Click on the Diagram Overlay and select Bar chart as Diagram type.

4. In the diagram we want to display the values of the three columns T_F_JAN, T_F_JUL and T_-

F_MEAN . First select T_F_JAN as Attributes and click Add attribute , then T_F_JUL and finally

T_F_MEAN

.

5. For linear scaling of the diagram size we define T_F_JUL as classification attribute.

6. Now click on find maximum value , choose a size value and unit and click Apply to display the diagram in the QGIS main window.

7. You can now adapt the chart size, or change the attribute colors double clicking on the color values in the attribute field. Figure

21

gives an impression.

8. Finally click Ok .

QGIS 1.4.0 User Guide 62

Figure 20: Vector properties dialog with diagram tab

5.5

Editing

5.5. Editing

QGIS supports basic capabilities for editing vector geometries. Before reading any further you should note that at this stage editing support is still preliminary. Before performing any edits, always make a backup of the dataset you are about to edit.

Note - the procedure for editing GRASS layers is different - see Section

9.7

for details.

Tip 14 C

ONCURRENT

E

DITS

This version of QGIS does not track if somebody else is editing a feature at the same time as you. The last person to save their edits wins.

5.5.1. Setting the Snapping Tolerance and Search Radius

Before we can edit vertices, we must set the snapping tolerance and search radius to a value that allows us an optimal editing of the vector layer geometries.

QGIS 1.4.0 User Guide 63

5 WORKING WITH VECTOR DATA

Figure 21: Diagram from temperature data overlayed on a map

Snapping tolerance

Snapping tolerance is the distance QGIS uses to search for the closest vertex and/or segment you are trying to connect when you set a new vertex or move an existing vertex. If you aren’t within the snap tolerance, QGIS will leave the vertex where you release the mouse button, instead of snapping it to an existing vertex and/or segment. The snapping tolerance setting affects all tools which work with tolerance.

1. A general, project wide snapping tolerance can be defined choosing Settings >

Options .

(On Mac: go to QGIS > Preferences, on Linux: Edit >

Options .) In the Digitizing tab you can select between to vertex, to segment or to vertex and segment as default snap mode. You can also define a default snapping tolerance and a search radius for vertex edits.

The tolerance an be set either in map units or in pixels. The advantage of choosing pixels, is that the snapping tolerance doesn’t have to be changed after zoom operations. In our small digitizing project (working with the Alaska dataset), we define the snapping units in feet. Your results may vary, but something on the order of 300ft should be fine at a scale of 1:10 000 should be a reasonable setting.

QGIS 1.4.0 User Guide 64

5.5

Editing

2. A layer based snapping tolerance can be defined by choosing

Settings

(or

File )

>

Project Properties. . . .

In the

General tab, section Digitize you can click on

Snapping options. . .

to enable and adjust snapping mode and tolerance on a layer basis

(see Figure

22 ).

Note that this layer based snapping overrides the global snapping option set in the Digitizing tab.

So if you need to edit one layer, and snap its vertices to another layer, then enable snapping only on the snap to layer, then decrease the global snapping tolerance to a smaller value. Furthermore, snapping will never occur to a layer which is not checked in the snapping options dialog, regardless of the global snapping tolerance. So be sure to mark the checkbox for those layers that you need to snap to.

Figure 22: Edit snapping options on a layer basis

Search radius

Search radius is the distance QGIS uses to search for the closest vertex you are trying to move when you click on the map. If you aren’t within the search radius, QGIS won’t find and select any vertex for editing and it will pop up an annoying warning to that effect. Snap tolerance and search radius are set in map units or pixels, so you may find you need to experiment to get them set right. If you specify too big of a tolerance, QGIS may snap to the wrong vertex, especially if you are dealing with a large number of vertices in close proximity. Set search radius too small and it won’t find anything to move.

The search radius for vertex edits in layer units can be defined in the Digitizing tab under Settings

>

Options . The same place where you define the general, project wide snapping tolerance.

QGIS 1.4.0 User Guide 65

5 WORKING WITH VECTOR DATA

5.5.2. Zooming and Panning

Before editing a layer, you should zoom in to your area of interest. This avoids waiting while all the vertex markers are rendered across the entire layer.

Apart from using the pan and zoom-in / zoom-out icons on the toolbar with the mouse, navigating can also be done with the mouse wheel, spacebar and the arrow keys.

Zooming and panning with the mouse wheel

While digitizing you can press the mouse wheel to pan inside of the main window and you can roll the mouse wheel to zoom in and out on the map. For zooming place the mouse cursor inside the map area and roll it forward (away from you) to zoom in and backwards (towards you) to zoom out.

The mouse cursor position will be the center of the zoomed area of interest. You can customize the behavior of the mouse wheel zoom using the Map tools tab under the Settings > Options menu.

Panning with the arrow keys

Panning the Map during digitizing is possible with the arrow keys. Place the mouse cursor inside the map area and click on the right arrow key to pan east, left arrow key to pan west, up arrow key to pan north and down arrow key to pan south.

You can also use the spacebar to temporarily cause mouse movements to pan then map. The PgUp and PgDown keys on your keyboard will cause the map display to zoom in or out without interrupting your digitising session.

5.5.3. Topological editing

Besides layer based snapping options the

General tab in menu

Settings

->

Project Properties. . . also provides some topological functionalities. In the Digitizing option group you can x Enable topological editing and/or activate x Avoid intersections of new polygons .

Enable topological editing

The option x Enable topological editing is for editing and maintaining common boundaries in polygon mosaics. QGIS "detects" a shared boundary in a polygon mosaic and you only have to move the vertex once and QGIS will take care about updating the other boundary.

QGIS 1.4.0 User Guide 66

5.5

Editing

Avoid intersections of new polygons

The second topological option called x Avoid intersections of new polygons avoids overlaps in polygon mosaics. It is for quicker digitizing of adjacent polygons. If you already have one polygon, it is possible with this option to digitise the second one such that both intersect and qgis then cuts the second polygon to the common boundary. The advantage is that users don’t have to digitize all vertices of the common boundary.

5.5.4. Digitizing an existing layer

By default, QGIS loads layers read-only: This is a safeguard to avoid accidentally editing a layer if there is a slip of the mouse. However, you can choose to edit any layer as long as the data provider supports it, and the underlying data source is writable (i.e. its files are not read-only). Layer editing is most versatile when used on PostgreSQL/PostGIS data sources.

In general, editing vector layers is divided into a digitizing and an advanced digitizing toolbar, described in Section

5.5.5

. You can select and unselect both under Settings > Toolbars . Using the

basic digitizing tools you can perform the following functions:

Icon Purpose

Table 2: Vector layer basic editing toolbar

Icon Purpose

Toggle editing

Adding Features: Capture Line

Adding Features: Capture Point

Adding Features: Capture Polygon

Move Feature

Delete Selected

Copy Features

Node Tool

Cut Features

Paste Features

All editing sessions start by choosing the

Toggle editing option. This can be found in the context menu after right clicking on the legend entry for that layer.

Alternately, you can use the

Toggle editing button from the digitizing toolbar to start or stop the editing mode. Once the layer is in edit mode, markers will appear at the vertices, and additional tool buttons on the editing toolbar will become available.

QGIS 1.4.0 User Guide 67

5 WORKING WITH VECTOR DATA

Tip 15 S

AVE

R

EGULARLY

Remember to toggle

Toggle editing off regularly. This allows you to save your recent changes, and also confirms that your data source can accept all your changes.

Adding Features

You can use the

Capture point , Capture line or toolbar to put the QGIS cursor into digitizing mode.

Capture polygon icons on the

For each feature, you first digitize the geometry, then enter its attributes. To digitize the geometry, left-click on the map area to create the first point of your new feature.

For lines and polygons, keep on left-clicking for each additional point you wish to capture. When you have finished adding points, right-click anywhere on the map area to confirm you have finished entering the geometry of that feature.

The attribute window will appear, allowing you to enter the information for the new feature.

Figure

23

shows setting attributes for a fictitious new river in Alaska.

In the

Digitising tab under the

Settings

> Options menu, you can also activate the x Suppress attributes pop-up windows after each created feature .

Figure 23: Enter Attribute Values Dialog after digitizing a new vector feature

With the

Move Feature icon on the toolbar you can move existing features.

QGIS 1.4.0 User Guide 68

5.5

Editing

Tip 16 A

TTRIBUTE

V

ALUE

T

YPES

At least for shapefile editing the attribue types are validated during the entry. Because of this, it is not possible to enter a number into the text-column in the dialog Enter Attribute Values or vica versa. If you need to do so, you should edit the attributes in a second step within the Attribute table dialog.

Node Tool

For both PostgreSQL/PostGIS and shapefile-based layers, the

Node Tool provides manipulation capabilites of feature vertices similar to CAD programs. It is possible to simply select multiple vertices at once and to move, add or delete them alltogether. The node tool also works with ’on the fly’ projection turned on and supports the topological editing feature. This tool is, unlike other tools in

Quantum GIS, persistent, so when some operation is done, selection stays active for this feature and tool.

Important is to set the property Settings >

Options > Digitizing > Search Radius 10

N

H number greater than zero. Otherwise QGIS will not be able to tell which vertex is being edited.

to a

Tip 17 V

ERTEX

M

ARKERS

The current version of QGIS supports three kinds of vertex-markers - Semi transparent circle, Cross and

None. To change the marker style, choose

Options from the Settings menu and click on the Digitizing tab and select the appropriate entry.

Basic operations

Start by activating the

Node Tool and selecting some features by clicking on it. Red boxes appear at each vertex of this feature. This is basic select of the feature. Functionalities are:

Selecting vertex: Selecting is easy just click on vertex and color of this vertex will change to blue. When selecting more vertices

¨ ¥

¨

§

¥

Shift key can be used to select more vertices. Or also the

¦

Ctrl key can be used to invert selection of vertices (if selected then it will be unselected and

§ ¦ when not selected vertex will be selected). Also more vertices can be selected at once when clicking somewhere outside feature and opening a rectangle where all vertices inside will be selected. Or just click on an edge and both adjacent vertices should be selected.

Adding vertex: Adding vertex is simple, too. Just double click near some edge and a new vertex will appear on the edge near to the cursor. Note that vertex will appear on edge not on cursor position, there it has to be moved if necessary.

Deleting vertex: After selecting vertices for deletion, click the

¨

Delete key and vertices will

§

¥

¦ be deleted. Note that according to standard Quantum GIS behavior, it will leave a necessary number of vertices for the feature type you are working on. To delete a complete feature, another tool has to be used.

QGIS 1.4.0 User Guide 69

5 WORKING WITH VECTOR DATA

Moving vertex: Select all vertices you want to move. All selected vertices are moving in the same direction as the cursor. If snapping is enabled, the whole selection can jump to the nearest vertex or line.

The Release button stores all changes and a new entry appears in the undo dialog. Remember that all operations support topological editing when turned on. On the fly projection is also supported.

Cutting, Copying and Pasting Features

Selected features can be cut, copied and pasted between layers in the same QGIS project, as long as destination layers are set to

Toggle editing beforehand.

Features can also be pasted to external applications as text: That is, the features are represented in

CSV format with the geometry data appearing in the OGC Well-Known Text (WKT) format.

However in this version of QGIS, text features from outside QGIS cannot be pasted to a layer within

QGIS. When would the copy and paste function come in handy? Well, it turns out that you can edit more than one layer at a time and copy/paste features between layers. Why would we want to do this? Say we need to do some work on a new layer but only need one or two lakes, not the 5,000 on our big_lakes layer. We can create a new layer and use copy/paste to plop the needed lakes into it.

As an example we are copying some lakes to a new layer:

1. Load the layer you want to copy from (source layer)

2. Load or create the layer you want to copy to (target layer)

3. Start editing for target layer

4. Make the source layer active by clicking on it in the legend

5. Use the

Select tool to select the feature(s) on the source layer

6. Click on the

Copy Features tool

7. Make the destination layer active by clicking on it in the legend

8. Click on the

Paste Features tool

9. Stop editing and save the changes

What happens if the source and target layers have different schemas (field names and types are not the same)? QGIS populates what matches and ignores the rest. If you don’t care about the attributes being copied to the target layer, it doesn’t matter how you design the fields and data types. If you want

QGIS 1.4.0 User Guide 70

5.5

Editing to make sure everything - feature and its attributes - gets copied, make sure the schemas match.

Tip 18 C

ONGRUENCY OF

P

ASTED

F

EATURES

If your source and destination layers use the same projection, then the pasted features will have geometry identical to the source layer. However if the destination layer is a different projection then QGIS cannot guarantee the geometry is identical. This is simply because there are small rounding-off errors involved when converting between projections.

Deleting Selected Features

If we want to delete an entire polygon, we can do that by first selecting the polygon using the regular

Select Features tool. You can select multiple features for deletion. Once you have the selection set, use the

Delete Selected tool to delete the features.

The

Cut Features tool on the digitizing toolbar can also be used to delete features. This effectively deletes the feature but also places it on a “spatial clipboard". So we cut the feature to delete. We could then use the paste tool to put it back, giving us a one-level undo capability.

Cut, copy, and paste work on the currently selected features, meaning we can operate on more than one at a time.

Tip 19 F

EATURE

D

ELETION

S

UPPORT

When editing ESRI shapefiles, the deletion of features only works if QGIS is linked to a GDAL version 1.3.2 or greater. The OS X and Windows versions of QGIS available from the download site are built using GDAL

1.3.2 or higher.

Saving Edited Layers

When a layer is in editing mode, any changes remain in the memory of QGIS. Therefore they are not committed/saved immediately to the data source or disk. When you turn editing mode off (or quit

QGIS for that matter), you are then asked if you want to save your changes or discard them.

If the changes cannot be saved (e.g. disk full, or the attributes have values that are out of range), the

QGIS in-memory state is preserved. This allows you to adjust your edits and try again.

Tip 20 D

ATA

I

NTEGRITY

It is always a good idea to back up your data source before you start editing. While the authors of QGIS have made every effort to preserve the integrity of your data, we offer no warranty in this regard.

QGIS 1.4.0 User Guide 71

5 WORKING WITH VECTOR DATA

Icon Purpose

Undo

Simplify Feature

Add Part

Delete Part

Split Features

Rotate Point Symbols

Table 3: Vector layer advanced editing toolbar

Icon Purpose

Redo

Add Ring

Delete Ring

Reshape Features

Merge Selected Features

5.5.5. Advanced digitizing

Undo and Redo

The

Undo and Redo tools allow the user to undo or redo the last or a certain step within the vector editing operations. Basic view of Undo/Redo operations is a widget, where all operations are shown (see Figure

24 ). This widget is not displayed by default. Widget can be displayed

by right clicking on toolbar and activating the Undo/Redo check box. Undo/Redo is however active, even if the widget is not displayed.

When Undo is hit, the state of all features and attributes are reverted to the state before the reverted operation happened. Changes which are done elsewhere (for example from some plugin), can show unspecific behavior for some operations which appears in this box. The operations can be reverted or they stay the same.

An action can be triggered by clicking on Undo or Redo buttons or by clicking directly on the item to which you want to return to. Another possibility to trigger an undo operation is to click on the undo/redo buttons in the advanced digitizing tool bar.

Simplify Feature

The

Simplify Feature tool allows to reduce the number of vertices of a feature, as long as the geometry doesn’t change. You need to select one or several features, they will be highlighted by a red rubber band and a slider appears. Moving the slider, the red rubber band is changing its shape to show how the feature is being simplified. Clicking OK the new, simplified geometry will be stored.

If a feature cannot be simplified, a message shows up.

QGIS 1.4.0 User Guide 72

Figure 24: Redo and Undo digitizing steps

5.5

Editing

Add Ring

You can create ring polygons using the

Add Ring icon in the toolbar. This means inside an existing area it is possible to digitize further polygons, that will occur as a ’hole’, so only the area in between the boundaries of the outer and inner polygons remain as a ring polygon.

Add Part

You can add part polygons to a selected multipolygon. The new part polygon has to be digitized outside the selected multipolygon.

Delete Ring

The

Delete Ring tool allows to delete ring polygons inside an existing area. This tool only works with polygon layers. It doesn’t change anything when it is used on the outer ring of the polygon.

QGIS 1.4.0 User Guide 73

5 WORKING WITH VECTOR DATA

This tool can be used on polygon and mutli-polygon features. Before you select the vertices of a ring, adjust the vertex edit tolerance.

Delete Part

The

Delete Part tool allows to delete parts from multifeatures (e.g. to delete polygons from a multipolygon feature). It won’t delete the last part of the feature, this last part will stay untouched.

This tool works with all multi-part geometries point, line and polygon. Before you select the vertices of a part, adjust the vertex edit tolerance.

Reshape Features

You can reshape line and polygon features using the

Reshape Features icon on the toolbar.

It replaces the line or polygon part from the first to the last intersection with the original line. With polygons this can sometime lead to unintended results. It is mainly useful to replace smaller parts of a polygon, not major overhauls and the reshapeline is not allowed to cross several polygon rings as this would generate an invalide polygon.

Note: The reshape tool may alter the starting position of a polygon ring or a closed line. So the point that is represented ’twice’ will not be the same any more. This may not be a problem for most applications, but it is something to consider.

Split Features

You can split features using the feature you want to split.

Merge selected features

Split Features icon on the toolbar. Just draw a line across the

The

Merge Selected Features tool allows to merge features that have common boundaries and the same attributes.

Rotate Point Symbols

The

Rotate Point Symbols tool allows to change the rotation of point symbols in the map canvas, if you have defined a rotation column from the attribute table of the point layer in the Symbology tab of the Layer Properties . Otherwise the tool is inactive.

To change the rotation, select a point feature in the map canvas and rotate it holding the left mouse

QGIS 1.4.0 User Guide 74

Figure 25: Rotate Point Symbols

5.5

Editing button pressed. A red arrow with the rotation value will be visualized (see Figure

25 ). When you

release the left mouse button again, the value will be updated in the attribute table.

Note: If you hold the

¨

Ctrl key pressed, the rotation will be done in 15 degree steps.

§

¥

¦

5.5.6. Creating a New Layer

To create a new layer for editing, choose

New Vector Layer from the Layer menu. The

New Vector Layer dialog will be displayed as shown in Figure

26 . Choose the type of layer (point,

line or polygon).

Note that QGIS does not yet support creation of 2.5D features (i.e. features with X,Y,Z coordinates) or measure features. At this time, only shapefiles can be created. In a future version of QGIS, creation of any OGR or PostgreSQL layer type will be supported.

Creation of GRASS-layers is supported within the GRASS-plugin. Please refer to section

9.6

for more information on creating GRASS vector layers.

To complete the creation of the new layer, add the desired attributes by clicking on the Add button and specifying a name and type for the attribute. Only Type real

H

, Type integer

H

, and

Type string

H attributes are supported. Additionally and according to the attribute type you can also define the width and precision of the new attribute column. Once you are happy with the attributes, click OK and provide a name for the shapefile. QGIS will automatically add a .shp

extension to the name you specify. Once the layer has been created, it will be added to the map and you can edit it in the same way as described in Section

5.5.4

above.

QGIS 1.4.0 User Guide 75

5 WORKING WITH VECTOR DATA

Figure 26: Creating a New Vector Dialog

5.5.7. Working with the Attribute Table

The attribute table displays features of a selected layer. Each row in the table represents one map feature with its attributes shown in several columns. The features in the table can be searched, selected, moved or even edited.

To open the attribute table for a vector layer, make the layer active by clicking on it in the map legend area. Then use Layer from the main menu and and choose

Open Attribute Table from the menu.

It is also possible to rightlick on the layer and choose

Open Attribute Table from the dropdown menu. This will open a new window which displays the attributes for every feature in the layer (figure

27 ).

Selecting features in an attribute table

A selected row in the attribute table represents all attributes of a selected feature in the layer. The attribute table reflects any changes in the layer selection in the main window and vice versa. A changed selection in the attribute table also causes a change in the selected feature set in the main

QGIS 1.4.0 User Guide 76

Figure 27: Attribute Table for Alaska layer

5.5

Editing window and different layer feature selection means different rows are to be selected.

Rows can be selected by clicking on the row number on the left side of the row. Selecting a row doesn’t change the current cursor position. Multiple rows can be marked by holding the

A continuous selection can be made by holding the

¨ ¥

¨ ¥

Ctrl key.

§ ¦

Shift key and clicking on several row headers

§ ¦ on the left side of the rows. All rows between the current cursor position and the clicked row are selected.

Each column can be sorted by clicking on its column header. A small arrow indicates the sort order (downward pointing means descending values from the top row down, upward pointing means ascending values from the top rown down).

For a simple search by attributes on only one column the Look for field can be used. Select the field (column) from which the search should be performed from the dropdown menu and hit the

Search button. The number of matching rows will appear in the status bar. For more complex searches use the Advanced search ... , which will lauch the Search Query Builder described in

Section

5.6

.

To show selected records only, use the checkbox x Show selected records only . To search selected records only, use the checkbox x Search selected records only . The other buttons at the bottom left of the attribute table window provide following functionality:

Remove selection

Move selected to top

QGIS 1.4.0 User Guide 77

5 WORKING WITH VECTOR DATA

Invert selection

Copy selected rows to clipboard also with

¨

Ctrl-C

§

¥

¦

Zoom map to selected rows also with

¨

Ctrl-J

§

¥

¦

• toggle editing mode to edit single values of attribute table and to enable functionalities described below.

Delete Selected Features

New Column for PostGIS layers and for OGR layers with GDAL version >= 1.6.

Delete Column only for PostGIS layers yet.

Open field calcultor

Tip 21 M

ANIPULATING

A

TTRIBUTE DATA

Currently only PostGIS layers are supported for adding or dropping attribute columns within this dialog. In future versions of QGIS, other datasources will be supported, because this feature was recently implemented in GDAL/OGR > 1.6.0

5.6. Query Builder

The Advanced search. . .

button opens the Query Builder and allows you to define a subset of a table using a SQL-like WHERE clause, display the result in the main window and save it as a

Shapefile. For example, if you have a towns layer with a population field you could select only larger towns by entering population > 100000 in the SQL box of the query builder. Figure

28

shows an example of the query builder populated with data from a PostGIS layer with attributes stored in PostgreSQL. The Fields, Values and Operators sections help the user to construct the SQL-like

WHERE clause easily in the text field SQL where clause window.

The Fields list contains all attributes of the attribute table to be searched. To add an attribute to the

SQL where clause field, double click its name in the Fields list. Generally you can use the various fields, values and operators to construct the query or you can just type it into the SQL box.

The Values list lists the values of an attribute. To list all possible values of an attribute, select the

QGIS 1.4.0 User Guide 78

Figure 28: Query Builder

5.6

Query Builder attribute in the Fields list and click the All button. To list all values of an attribute that are present in the sample table, select the attribute in the Fields list and click the Sample button. To add a value to the SQL where clause field, double click its name in the Values list.

The Operators section contains all usable operators. To add an operator to the SQL where clause field, click the appropriate button. Relational operators ( = , > , . . . ), string comparison operator (

LIKE ), logical operators ( AND , OR , . . . ) are available.

The Clear button clears the text in the SQL where clause text field. The Test button shows a message box with the number of features satisfying the current query, which is usable in the process of query construction. The OK button closes the window and selects the features satisfying the query. The Cancel button closes the window without changing the current selection.

Select by query

With QGIS it is possible also to select features using a similar query builder interface to that used in

5.6

. In the above section the purpose of the query builder is to only show features meeting the

QGIS 1.4.0 User Guide 79

5 WORKING WITH VECTOR DATA

Tip 22 C

HANGING THE

L

AYER

D

EFINITION

You can change the layer definition after it is loaded by altering the SQL query used to define the layer. To do this, open the vector Layer Properties dialog by double-clicking on the layer in the legend and click on the

Query Builder button on the General tab. See Section

5.4

for more information.

filter criteria as a ’virtual layer’ / subset. The purpose of the select by query function is to highlight all features that meet a particular criteria. Select by query can be used with all vector data providers.

To do a ‘select by query’ on a loaded layer, click on the button

Open Table to open the attribute table of the layer. Then click the Advanced...

button at the bottom. This starts the Query Builder that allows to define a subset of a table and display it as described in Section

5.6

.

5.7. Field Calculator

The

Field Calculator button in the attribute table allows to perform calculations on basis of existing attribute values or defined functions, e.g to calculate length or area of geometry features.

The results can be written to a new attribute column or it can be used to update values in an already existing column. The creation of new attribute fields is currently only possible in PostGIS and with

OGR formats, if GDAL version is >= 1.6.0.

You have to bring the vector layer in editing mode, before you can click on the field calculator icon to open the dialog (see Figure

29 ). In the dialog you first have to select, whether you want to update an

existing field, only update selected features or create a new attribute field, where the results of the calculation will be added.

If you choose to add a new field, you need to enter a field name, a field type (integer, real or string), the total field width, and the field precision. For example, if you choose a field width of 10 and a field precision of 3 it means you have 6 signs before the dot, then the dot and another 3 signs for the precision.

The Fields list contains all attributes of the attribute table to be searched. To add an attribute to the

Field calculator expression field, double click its name in the Fields list. Generally you can use the various fields, values and operators to construct the calculation expression or you can just type it into the box.

The Values list lists the values of an attribute field. To list all possible values, select the attribute field in the Fields list and click the All button. To list all values of an attribute field that are present in the sample table, select the attribute in the Fields list and click the Sample button. The procedure is the same as for the Query Builder. To add a value to the Field calculator expression box, double click its name in the Values list.

QGIS 1.4.0 User Guide 80

Figure 29: Field Calculator

5.7

Field Calculator

The Operators section contains all usable operators. To add an operator to the Field calculator expression box, click the appropriate button. Mathematical calculations ( + , - , * . . . ), trigonometric functions ( sin, cos, tan, . . . ), extract geometric information ( length and area ) are available and will be extended in future versions.

A short example illustrates how the field calculator works. We want to calculate the length of the

’railroads’ layer from the qgis_example_dataset :

1. Load the Shapefile railroads.shp

in QGIS and open the Attribute Table dialog.

2. Click on

Toggle editing mode and open the Field Calculator dialog.

3. Unselect the x Update existing field checkbox to enable the new field box.

4. Add ’length’ as output field name, ’real’ as output field type and define output field width 10 and

QGIS 1.4.0 User Guide 81

5 WORKING WITH VECTOR DATA a precision of 3.

5. Now double click on Operator ’length’ to add it as $length into the field calculator expression box and click Ok .

QGIS 1.4.0 User Guide 82

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement

Table of contents