Book Image

Mastering QGIS

Book Image

Mastering QGIS

Overview of this book

Table of Contents (18 chapters)
Mastering QGIS
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Loading data


One strength of QGIS is its ability to load a large number of data types. In this section, we will cover loading various types of data into QGIS Desktop.

In general, data can be loaded in four ways. The first way, which will be covered in detail in this section, is to use the Add Layer menu under Layer and select the appropriate type of data that you wish to load. The second way is to open the Browser panel, navigate to the data you wish to load, and then drag the data onto the map display or onto the Layers panel. The third way to load data is to enable the Manage Layers toolbar and click on the button representing the data type that you wish to load. The fourth way is to locate the data in QGIS Browser, drag the data, and drop it onto the QGIS Desktop map display or the Layers panel.

Loading vector data

To load vector files, click on Add Vector Layer by navigating to Layer | Add Layer. This will open the Add Vector Layer dialog that will allow us to choose the source type and source of the dataset that we wish to load.

The source type contains four options: File, Directory, Database, and Protocol. When you choose a source type, the source interface will change to display the appropriate options. Let's take a moment to discuss what type of data these four source types can load:

  • File: This can load flat files that are stored on disk. The commonly used flat file types are as follows:

    • ESRI shapefile (.shp)

    • AutoCAD DXF (.dxf)

    • Comma separated values (.csv)

    • GPS eXchange Format (.gpx)

    • Keyhole Markup Language (.kml)

    • SQLite/SpatiaLite (.sqlite/.db)

  • Directory: This can load data stored on disk that is encased in a directory. The commonly used directory types are as follows:

    • U.S. Census TIGER/Line

    • Arc/Info Binary Coverage

  • Database: This can load databases that are stored on disk or those available through service connections. The commonly used database types are as follows:

    • ODBC

    • ESRI Personal GeoDatabase

    • MSSQL

    • MySQL

    • PostgreSQL

  • Protocol: This can load protocols that are available at a specific URI. QGIS currently supports loading the GeoJSON protocol.

Loading raster data

To load raster data into QGIS, click on Add Raster Layer by navigating to Layer | Add Layer. This will open a file browser window and allow you to choose a GDAL-supported raster file. The commonly used raster types supported by GDAL are as follows:

  • ArcInfo ASCII Grid (.asc)

  • Erdas Imagine (.img)

  • GeoTIFF (.tif/.tiff)

  • JPEG/JPEG-2000 (.jpg or .jpeg/.jp2 or .j2k)

  • Portable Network Graphics (.png)

  • Rasterlite (.sqlite)

  • USGS Optional ASCII DEM (.dem)

To add an Oracle GeoRaster, click on Add Oracle GeoRaster Layer by navigating to Layer | Add Layer, then connect to an Oracle database to load the raster. More information about loading database layers is in the following section.

Note

The Geospatial Data Abstraction Library (GDAL) is a free and open source library that translates and processes vector and raster geospatial data formats. QGIS, as well as many other programs, use GDAL to handle many geospatial data processing tasks.

You may see references to OGR or GDAL/OGR as you work with QGIS and GDAL. OGR is short for OGR Simple Features Library and references the vector processing parts of GDAL. OGR is not really a standalone project, as it is part of the GDAL code now; however, for historical reasons, OGR is still used.

More information about GDAL and OGR can be found at http://gdal.org. GDAL is an Open Source Geospatial Foundation (http://osgeo.org) project.

Loading databases

QGIS supports PostGIS, SpatiaLite, MSSQL, and Oracle databases. Regardless of the type of database you wish to load, the loading sequence is very similar. Therefore, instead of covering specific examples, the general sequence will be covered.

First, click on Add Layer under Layer and then choose the database type you wish to load. This will open a window with options for adding the data stored in a database. As an example, the following screenshot shows the window that opens when you navigate to Layer | Add Layer | Add SpatiaLite Layer:

Note

Note that the window will look the same for any database you choose, except for the window name.

To load data from a database, we must first create a connection to the database. To create a new connection, click on the New button to open a connection information window. Depending on the database type you are connecting to, different connection options will be shown. Once you have created a database connection, select it from the drop-down list and click on Connect; you will see a list of all layers contained within the database display. If there are a large number of tables, you can select Search options and perform a search on the database. To load a layer, select it in the list and click on Add. If you only wish to load a portion of the layer, select the layer and then click on Set Filter to open the query builder. If you set a query and then add the layer, only the filtered features will be added.

Web services

QGIS supports the loading of OGC-compliant web services such as WMS/WMTS, WCS, and WFS. Loading a web service is similar to loading a database service. In general, you will create a new server connection, connect to the server to list the available services, and add the service to the QGIS project.