Book Image

QGIS By Example

By : Alexander Bruy, Daria Svidzinska
Book Image

QGIS By Example

By: Alexander Bruy, Daria Svidzinska

Overview of this book

Table of Contents (17 chapters)
QGIS By Example
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Dealing with projections


Projections define how real-world objects on the curved surface of the earth will be flattened and projected on a map-like planar surface. Different data sources are usually created and distributed in different projections, depending on acquisition techniques and the scope of application. To be able to manipulate and analyze them properly in QGIS, it is important to understand how it interprets and manages information about projections.

QGIS supports about 2,700 CRS. They constitute a database, each item of which is described by an ESPG identifier, and a description line in the format of the PROJ.4 projection library. To store and read information about projection, QGIS uses its own format stored in .qpj files. There are two important points to keep in mind while working with projections: a data source projection and project projection—which are not always the same.

Data source projection

When you load your data into QGIS, it tries to automatically define information about the projection from the accompanying projection description file and set it to a newly added layer. You can check the layer's projection information in the Layer Properties dialog. To open it, double-click on the layer name in Layers panel, or use the right-click contextual shortcut Properties. Information about the projection is shown in the Coordinate reference system section of the General tab, like this:

There are numerous projection description file formats, and they mostly depend on the data format and origin. One of the most common among them is a .prj file. This file format sometimes provides information about the projection in a reduced form, and QGIS cannot define it properly. If information about the projection is absent or incomplete, you will see that the projection description is missing or looks like this: USER:100000 - * Generated CRS (+proj=etc.). It means that QGIS didn't find an appropriate projection within its own database and added it as a custom CRS. If you are sure that the projection is standard but QGIS fails to interpret it properly because of a reduced description, specify it manually. There are different ways to assess the Coordinate Reference System Selector dialog as follows:

  • Double-click on the layer name in Layers panel to open the Layer Properties dialog. Under the General tab, click on the Select CRS button to select the necessary CRS from the Coordinate reference system selector dialog window.
  • By going to Layer | Set CRS of Layer(s).

  • Using the Ctrl + Shift + C keyboard shortcut.

  • By right-clicking on the layer shortcut Set Layer CRS.

In the Coordinate reference system selector dialog, choose the necessary CRS from the list and click on OK. Note that you can use a filter by key words or the EPSG code to hide unnecessary projections. With time, often used projections will be added to the list of the recently used CRS.

Note

If QGIS doesn't define a projection for your data automatically and you are not sure about projection name and EPSG code, use the Prj2EPSG website at http://prj2epsg.org/. In this service, you just need to upload your .prj file, and well-known text projection information from it will be converted into standard EPSG code.

Note that specifying the projection manually from the Properties dialog is a temporary solution; it does not persist after closing a file and/or exiting QGIS. This means that whenever you are loading this file into QGIS, you will have to specify the projection again. If you are going to work with the file in other projects, it is better to use the Define Current Projection tool by going to Vector | Data Management Tools | Define Current Projection. In this dialog, you can choose a predefined spatial reference system from the Coordinate reference system Selector dialog or Import spatial reference system from existing layer with a known CRS. In both the cases, the existing .prj file will be overwritten by QGIS with all the necessary parameters, and you will not have to adjust the projection manually next time.

All of this is true when you import files from external sources. If you create a shapefile in QGIS, both .prj and .qpj files are created, so you don't need to define the projection manually. The files projection will be interpreted correctly in the other GIS applications that read it from .prj files.

You can also maintain QGIS behavior when loading or creating a new layer that has no CRS information by going to Settings | Options | CRS, where three alternatives of CRS for new layers are available:

  1. Prompt for CRS: In this case, you will always be asked to manually specify the CRS for the layer.

  2. Use project CRS: The data will be automatically assigned a CRS set for a project. This is a convenient choice if you are using files in the same projection, but if their projection differs from what is specified, you will not be able to see them.

  3. Use default CRS displayed below: Conventionally, EPSG:4326 - WGS 84 is used, but you can specify your own choice.

Working with projections can be tricky, unless you recognize the difference between the specify and define projection options. It's all about assigning information about the projection properly, but when you specify it, the result is temporary within a current working session. Once you define a projection, it becomes permanent unless redefined again. In both cases, if you choose the wrong projection, you will not be able to see your data on the map (at least in the area where you expect it to be). Usually it is good practice to specify the projection at first, comparing your data to the correctly projected dataset. If everything is okay, define it to make projection assignment permanent.

Project projection

When you load QGIS, its map canvas projection is, by default, set to EPSG:4326 – WGS 84. This behavior is defined by the global default projection, which can be changed by going to Settings | Options | CRS | Always start new projects with this CRS.

However, when you start adding data, projection identifier automatically changes to the projection of the first loaded layer. So, by default, project projection is defined by the first loaded layer. Data source projection and project projection are not always the same. If they are different, QGIS can apply the so-called on-the-fly transformation. This means that it reads the data projection, and if it differs, automatically aligns it with the project projection, applying the necessary transformations. There are a few ways to specify the projection for the project and enable on-the-fly transformation:

  • By going to Project | Project Properties | CRS.

  • Click on the Current CRS button on the Status bar, and activating Enable 'on the fly' CRS transformation in the Project properties | CRS window.
  • Go to Settings | Options | CRS | Default CRS for new projects. Activate either Automatically enable 'on the fly' reprojection if layers have different CRS or Enable 'on the fly' reprojection by default.

In the last way, the difference is very subtle and is mainly obvious when adding the first layer to the project. In the case of automatically enabled reprojection, the default map canvas CRS will be superseded by the first layer projection, and the following layers will be automatically adjusted to it too. In the case of reprojection by default, all layers will be reprojected into the project initial CRS (this is usually default global projection, unless you've changed it).

After on-the-fly transformation is enabled, you will see an OTF abbreviation near the current CRS on the status bar, and the icon will become solid.

If you want to quickly change the project CRS according to a specific layer in the Layers panel, right-click on a layer and choose the Set Project CRS from Layer shortcut.