How to load and interact with data in QGIS

المشرف العام

Administrator
طاقم الإدارة
In recent years, QGIS has become the most popular open source desktop geographic information system (GIS) software. Some people are using it just to view and query data, while others are using it for much deeper analyses. Maybe you are an ecologist or a town planner needing to use GIS as part of your job. Maybe you have a background in proprietary GIS software and want to migrate some of your common workflows to open source. Or maybe you are a student that needs to use GIS for a project.

At the core of any GIS is data. Without it, we cannot create maps or perform spatial analysis. If you are familiar with GIS, then you will already know that we often work with vector data, namely points, lines, polygons, and raster data, as pixels. Vector and raster data are the core data types that we use in a GIS. However, text files, databases, and web services can also be integrated into GIS. We can use a location associated with a file (such as a coordinate), or we can perform joins to extend or spatially enable our existing data.

This article is taken from the book Learn QGIS – Fourth Edition by Anita Graser and Andrew Cutts. By the end of the book, you will have become proficient in geospatial analysis using QGIS and Python. To follow along with the examples implemented in this article, you can download the code from the book’s GitHub repository.

In this article, we will first briefly have a look at the data formats supported by QGIS 3.4. We will then learn how to load and interact with data within QGIS.

Data formats​


QGIS supports many GIS data formats. It makes use of the OGR library for vector data and the GDAL library for raster data. Shapefiles are the most common form of vector data today, and QGIS supports this format. Similarly, GeoTIFF are probably the most common form of raster data, and QGIS also supports these.

Note​


To see the latest list of OGR vector formats and GDAL raster formats check out the GDAL documentation. If you can’t find your format on the list, it is probably not supported in QGIS at this time.

GeoPackage​


QGIS 3 has chosen GeoPackage as its default format. This is an open format, unlike the Shapefile, which is proprietary. GeoPackage also supports rasters. It is built on a SpatiaLite database, has no file size limitations, and works as one file. The format was developed by the Open Geospatial Consortium and is increasingly being adopted by organizations around the world. A GeoPackage has a .gpkg extension, which unlike the Shapefile has several extensions.

Loading data​


We are going to start by loading data into QGIS 3.4. You may have some of your own data that you wish to use, but all of the techniques are applicable to any GIS data you have. We will use the QGIS sample data for these examples.

Note​


Download the QGIS sample data from QGIS download data page and look for the qgis_sample_data.zip file. Download and extract this data to a folder on your computer.

Getting data into QGIS​


Loading data into QGIS can be done in several ways. The three most common ways are as follows:

  • You can drag data directly from a folder straight into the map.
  • You can drag data from the browser panel onto the map.
  • You can click [B]Layer [/B]| [B]Add Layer[/B] and choose what type of layer to add.

In the following screenshot, we are choosing to load a Vector Layer, which can also be done using the Ctrl + Shift + V shortcut:


Adding a vector layer

By choosing this method, the [B]Data Source Manager[/B] window will appear, with [B]Vector[/B] highlighted, as follows:

The QGIS Data Source Manager

The QGIS Data Source Manager

Click on the ellipsis for [B]Vector Dataset(s)[/B] and navigate to the layer you wish to load. In the following example, the alaska Shapefile is selected. You can load more than one layer at the same time by holding down the Ctrl button and clicking on multiple files:

Loading data in the data source manager

Loading data in the data source manager

If you then click the [B]Add[/B] button at the bottom of the [B]Data Source Manager[/B] window, the data will be added to your [B]Map[/B] window as well as the [B]Layers[/B] window. The [B]Data Source Manager[/B] window will remain open, and you can also load other layers. Close the window and your Shapefile will appear in the map, as follows:


Data loaded into the map panel in QGIS

In the next section, we will look at how to interact with the data to zoom in and inspect its attributes.

Interacting with data​


When you loaded the Alaska layer, you probably noticed that the data appeared as a relatively small object. In this section, we will cover some of the basic interactions we can perform with data. Let’s start with zooming in.

Navigation​


Later, we will show you how to zoom in on a layer to look at it in more detail. But first, let’s remind ourselves of the project and navigation toolbar:


Project and Navigation toolbar

These tools are the workhorse of the GIS. They allow us to move around, inspect, measure, and select data. All are critical in any GIS, and if you have used mapping software before, you should be familiar with them.

Start by clicking on the zoom-in icon (a magnifying glass icon with a + in it). When this option is selected, it will be highlighted in a different shade, just like any other interactive button in QGIS. This is demonstrated in the following screenshot:


Clicking on the zoom tool in the navigation toolbar

Left-click and draw around the Alaska shape. The map window will quickly refresh around the shape you have drawn. You can then click on the white hand to pan around the map to adjust to your preference. You can also use the scroll button on your mouse to zoom in and out of the map. Some of these navigational tools are grayed out; this is because a setting or event has not happened yet to enable them.

The bookmark tool is shown in the following screenshot and highlighted in the red box:


Spatial bookmarks

[B]Spatial Bookmarks[/B] allow you to save your current map extent. This means that you can return to this bookmarked view later, or in another project. In the preceding example, I have created a bookmark called my_first_bookmark.

Data attributes toolbar​


Here is the attributes toolbar:

Attributes toolbar

Attributes toolbar

This contains tools to inspect, measure, and select data, among other tools. In order to be able to use these tools, we need to have a layer selected in the layers window. Left-click once on the Alaska layer and this toolbar will have all of its options available.

Inspecting the data​


Click on the blue [B]i[/B] button in the attributes toolbar and then click on the layer in the map. This will display the feature attributes in a new panel, which will dock by default. Like all panels, you can move them around and resize as needed. Your QGIS project should look similar to the following diagram:

Inspecting data in QGIS

Inspecting data in QGIS

The new panel is called identify results. In this case, attributes include a [B]Category[/B], a [B]Name[/B], and an [B]Area value[/B].

Measuring data​


The measure tool does not require a layer to be selected in the layer panel in order for it to work. This means that it is independent of a layer(s). The measure tool can measure length, area, or angle, and you can use the drop-down button next to the tool to select the required option. In this example, let’s measure length. Select the measure line option and then left-click on the map to begin the measurement. After doing this, left-click again to measure the segment. Continue to left-click to measure segments of the line or right-click on the end point to finish measuring.

The following diagram shows a series of left clicks on the Alaska layer:

Measuring distance in QGIS

Measuring distance in QGIS

Use the drop-down boxes to adjust the units of measurement you require. The default is set to [B]meters[/B]; we have changed ours to [B]kilometers[/B] to obtain a more usable distance unit.

If you expand the arrow next to [B]Info[/B] in the [B]Measure[/B] toolbox, you will get more information about how the measure tool is calculating the distance/area. An example is shown in the following screenshot:

The measure tool info box

The measure tool info box

Selecting data​


Selecting data is very useful in GIS. We can create a new layer from a selection, or we could add new data specific to that selection. QGIS allows multiple ways of selecting data, and we will cover some of these here. The data attributes toolbar allows selecting by area (this means drawing on the map by hand) and selecting by value (this means passing a query to select the data). The selection tools are highlighted in the following screenshot:

The select data tools

The select data tools

Working from left to right, the tools are Select by Area, Select by Attribute, and Clear Selection. Click on the Select by Location button and click on the largest area associated with the Alaska layer. It will change to yellow to highlight the selected layer. The following screenshot shows the other Select by Area options in the drop-down list:

Feature selected in QGIS

Feature selected in QGIS

Click on [B]Clear Selection[/B] to remove any selections from the layer.

The [B]Select by Value[/B] button is the second button on the toolbar described previously. Click on this button to open a new window:

Map showing the selected features by value option

Map showing the selected features by value option

In the [B]Select Features by Value[/B] window, we have clicked on the [B]Exclude field[/B] button associated with [B]AREA_MI[/B] and selected [B]Less than or equal to (<=)[/B]. As a parameter, we have typed 1000 into the box. We then clicked [B]Select features[/B] and QGIS selected the features that match this expression. At the top of the screen, a notification tells us how many features have been selected. In this case, it is 640.

If we click on close and then press F6 or click on the button immediately to the right of the [B]Clear Selection[/B] button, the attribute table will appear with the selected rows highlighted. This attribute table for the [B]Alaska[/B] layer is shown as follows:

Attribute table with features selected

Attribute table with features selected

When you are finished inspecting this table, close it down by clicking the close button, on Windows this is an Χ symbol in the top-right corner.

There is one more very useful tool worth mentioning, and that is the [B]Field Calculator[/B] tool. This button looks like an abacus and is next to the [B]Attribute Table[/B] button. We will use this tool next to begin creating our own data.

This article walked you through the steps for loading and interacting with data in QGIS. If you found this post useful, do check out the book, Learn QGIS – Fourth Edition on Packt Publishing. This book will help you get started on your QGIS journey, guiding you to develop your own processing pathway. You will explore the user interface, loading your data, editing, and then creating data. QGIS often surprises new users with its mapping capabilities; you will discover how easily you can style and create your first map.

The post How to load and interact with data in QGIS appeared first on GIS Crack.

متابعة القراءة...
 
أعلى