More

QGIS 2.8 Convert a vector to a raster layer

QGIS 2.8 Convert a vector to a raster layer


When I change a vector layer to raster usingraster button->converse->Vector rasterizationin QGIS2.8. I get only a black picture.
Why is that so and how can I convert a vector layer to a raster layer.


Rasterization depends of the field that you select. For example, in the following case I selected (in vector layer point_2) the 'field' field whose values are all 0. The result, point_2_raster.tif, is the same that you are obtaining (a black picture):

However, if the 'id' field is selected, whose values are between 1 and 5, the result (point_raster.tif) is totally different:

It could be your problem.


Chapter 4 Creating Maps in QGIS

Throughout this course you will use the same steps to create a map.

  1. Prepare your data
  2. Add your data to QGIS
  3. Make sure your layer CRS values are correct, and choose a project CRS
  4. Make your map look pretty
  5. Use a Print Composer to export your map

We will introduce these steps not in the order listed above, but in order of difficulty (more or less). In Chapter 5 you will learn how to add data to the map, change the Project CRS, and use the Print Composer to export a map from QGIS in Chapter 6 and Chapter ?? you will learn how to style vector layers in Chapter 7 and Chapter 9 you will learn how to download freely available GIS data from the internet and prepare our own data to import to QGIS. In Chapter 10 you will practice these five steps by creating a minimalist study stue map, and in Chapters 11 and 12 you will learn how to create, edit, and process vector and raster layers.


Coordinate reference systems (CRS) are encapsulated by the QgsCoordinateReferenceSystem class. Instances of this class can be created in several different ways:

QGIS uses three different IDs for every reference system:

InternalCrsId — ID used in the internal QGIS database.

PostgisCrsId — ID used in PostGIS databases.

EpsgCrsId — ID assigned by the EPSG organization.

If not specified otherwise with the second parameter, PostGIS SRID is used by default.

specify CRS by its well-known text (WKT)

create an invalid CRS and then use one of the create* functions to initialize it. In the following example we use a Proj4 string to initialize the projection.

It’s wise to check whether creation (i.e. lookup in the database) of the CRS has been successful: isValid() must return True .

Note that for initialization of spatial reference systems QGIS needs to look up appropriate values in its internal database srs.db . Thus in case you create an independent application you need to set paths correctly with QgsApplication.setPrefixPath() , otherwise it will fail to find the database. If you are running the commands from the QGIS Python console or developing a plugin you do not care: everything is already set up for you.

Accessing spatial reference system information:


QGIS 2.8 Convert a vector to a raster layer - Geographic Information Systems

Open Source Geospatial Books

QGIS for Hydrological Applications

Recipes for Catchment Hydrology and Water Management

by Hans van der Kwast and Kurt Menke

Learn GIS skills for catchment hydrology and water management with QGIS for Hydrological Applications!

This workbook introduces professionals in the water sector to the state of the art functionality of QGIS 3.x for hydrological applications. The book can also be used as a beginner’s course introducing GIS concepts in a problem based learning manner.

Designed to take advantage of the latest QGIS features, this book will guide you in improving your maps and analysis.

With this book you'll learn to:

  • Georeference scanned maps
  • Digitize vectors
  • Import tabular data
  • Join attribute tables
  • Interpolate points to a raster
  • Apply map algebra
  • Delineate streams and catchments
  • Find and use Open Data
  • Calculate the percentage of land cover per subcatchment
  • Design beautiful catchment maps

In addition to the core functionality of QGIS, you’ll be introduced to many useful plugins.

The book is a complete resource and includes:

  • Lab exercises
  • Discussion questions
  • Links to videos with theory and explanations of the exercises

By purchasing the book you support the attendance of students at FOSS4G and QGIS events.

Coming Soon: QGIS Training Manual

We are happy to provide discounts on bulk orders. Contact us directly to place an order. For bookstores used to ordering through Ingram Book Distributors, they also distribute all our books. Please see our Return Policy.


Table of contents

  1. Chapter 1 : A Refreshing Look at QGIS
    1. The Course Overview 00:05:28
    2. Installation and Tour 00:04:04
    3. Loading Data 00:03:20
    4. Working with Coordinate Reference Systems and Tables 00:06:28
    5. Editing Data 00:06:17
    6. Composing Maps and Adding Functionality with Plugins 00:04:08
    1. Fundamental Database Concepts 00:03:01
    2. Creating a Spatial Database 00:02:44
    3. Importing Data into a SpatiaLite Database 00:08:14
    4. Exporting Tables out of SpatiaLite and Managing Tables 00:05:53
    5. Creating Queries and Views 00:05:46
    1. Choosing and Managing Colors 00:06:33
    2. Managing Color Ramps 00:06:33
    3. Styling Single Band Rasters 00:09:25
    4. Styling Multiband Rasters 00:02:14
    5. Raster Color Rendering and Resampling 00:04:34
    1. Styling Vectors 00:14:15
    2. Vector Layer Rendering 00:02:22
    3. Using Diagrams to Display Thematic Data 00:05:22
    4. Saving, Loading, and Setting Default Styles 00:03:07
    1. Merging Shapefiles 00:01:49
    2. Creating Spatial Indices and Checking for Geometry Errors 00:02:30
    3. Converting Vector Geometries 00:09:45
    4. Using Basic Vector Geoprocessing Tools 00:08:25
    5. Defining Coordinate Reference Systems 00:05:09
    6. Advanced Field Calculations 00:07:07
    7. Complex Spatial and Aspatial Queries 00:04:47
    1. Resampling Rasters 00:04:18
    2. Creating a Raster Mosaic 00:02:55
    3. Generating Raster Overviews Pyramids 00:03:07
    4. Converting between Raster and Vector Data Models 00:03:56
    5. Creating Raster Surfaces Via Interpolation 00:04:34
    1. Creating Points from Coordinate Data 00:08:52
    2. Geocoding Address-Based Data 00:06:21
    3. Georeferencing Imagery 00:18:02
    4. Checking the Topology of Vector Data 00:07:10
    5. Repairing Topological Errors Via Topological Editing 00:06:28
    1. Graphical Modeler 00:04:18
    2. Adding Inputs and Algorithms 00:05:05
    3. Running and Editing a Model 00:03:39
    4. Documenting, Saving, Loading, and Exporting Models 00:02:55
    5. Executing Model Algorithms Iteratively 00:01:48
    6. Nesting Models 00:02:54
    7. Using Batch Processing with Models 00:01:45
    1. Webography 00:06:05
    2. The Python Console 00:03:22
    3. Exploring iface, QGis, and QGIS API 00:02:35
    4. Creating a Plugin Structure 00:11:57
    5. A Simple Plugin Example 00:08:23
    1. Loading Layers 00:07:55
    2. Vector Structure 00:06:50
    3. Iterating Over Features 00:02:20
    4. Editing Features 00:05:03
    5. Running Processing Toolbox Algorithms 00:06:32
    6. Running an External Algorithm or Command 00:01:28
    7. Interacting with the Map Canvas 00:07:19

    CRS Settings¶

    By default, QGIS starts each new project using a global default projection. This default CRS is EPSG:4326 (also known as “WGS 84”), and it is a global latitude/longitude based reference system. This default CRS can be changed via the CRS for New Projects setting in the CRS tab under Settings ‣ Options . There is an option to automatically set the project’s CRS to match the CRS of the first layer loaded into a new project, or alternatively you can select a different default CRS to use for all newly created projects. This choice will be saved for use in subsequent QGIS sessions.

    The CRS tab in the QGIS Options Dialog ¶

    When you use layers that do not have a CRS, you can define how QGIS responds to these layers. This can be done globally in the CRS tab under Settings ‣ Options .

    If you want to define the Coordinate Reference System for a certain layer without CRS information, you can also do that in the Source tab of the raster and vector properties dialog (see Source Properties for rasters and Source Properties for vectors). If your layer already has a CRS defined, it will be displayed as shown in Source tab in vector Layer Properties dialog . Note that changing the CRS in this setting does not alter the underlying data source in any way, rather it just changes how QGIS interprets the raw coordinates from the layer in the current QGIS project only.

    CRS in the Layers Panel

    Right-clicking on a layer in the Layers Panel (section Layers Panel ) provides two CRS shortcuts. Set layer CRS takes you directly to the Coordinate Reference System Selector dialog (see figure_projection_project). Set project CRS from Layer redefines the project CRS using the layer’s CRS.


    Practical examples with real-world projects in GIS, Remote sensing, Geospatial data management and Analysis using the R programming language

    Key Features

    • Understand the basics of R and QGIS to work with GIS and remote sensing data
    • Learn to manage, manipulate, and analyze spatial data using R and QGIS
    • Apply machine learning algorithms to geospatial data using R and QGIS

    Book Description

    Managing spatial data has always been challenging and it's getting more complex as the size of data increases. Spatial data is actually big data and you need different tools and techniques to work your way around to model and create different workflows. R and QGIS have powerful features that can make this job easier.

    This book is your companion for applying machine learning algorithms on GIS and remote sensing data. You'll start by gaining an understanding of the nature of spatial data and installing R and QGIS. Then, you'll learn how to use different R packages to import, export, and visualize data, before doing the same in QGIS. Screenshots are included to ease your understanding.

    Moving on, you'll learn about different aspects of managing and analyzing spatial data, before diving into advanced topics. You'll create powerful data visualizations using ggplot2, ggmap, raster, and other packages of R. You'll learn how to use QGIS 3.2.2 to visualize and manage (create, edit, and format) spatial data. Different types of spatial analysis are also covered using R. Finally, you'll work with landslide data from Bangladesh to create a landslide susceptibility map using different machine learning algorithms.

    By reading this book, you'll transition from being a beginner to an intermediate user of GIS and remote sensing data in no time.

    What you will learn

    • Install R and QGIS
    • Get familiar with the basics of R programming and QGIS
    • Visualize quantitative and qualitative data to create maps
    • Find out the basics of raster data and how to use them in R and QGIS
    • Perform geoprocessing tasks and automate them using the graphical modeler of QGIS
    • Apply different machine learning algorithms on satellite data for landslide susceptibility mapping and prediction

    Who this book is for

    This book is great for geographers, environmental scientists, statisticians, and every professional who deals with spatial data. If you want to learn how to handle GIS and remote sensing data, then this book is for you. Basic knowledge of R and QGIS would be helpful but is not necessary.


    Welcome

    This book is being developed as part of my effort to put together course materials for my data science course targeted at upper-level undergraduate and graduate students at the University of Nebraska Lincoln. This book aims particularly at spatial data processing for econometric projects, where spatial variables become part of an econometric analysis. Over the years, I have seen many students and researchers who spend so much time just processing spatial data (often involving clicking the ArcGIS (or QGIS) user interface to death), which is a waste of time from the perspective of academic productivity. My hope is that this book will help researchers become more proficient in spatial data processing and enhance the overall productivity of the fields of economics for which spatial data are essential.

    I am an Assistant Professor at the Department of Agricultural Economics at the University of Nebraska Lincoln, where I also teach Econometrics for Master’s students. My research interests lie in precision agriculture, water economics, and agricultural policy. My personal website is here.

    Contributors of the book

    Here is the list of contributors to the book and the parts they contributed to:

    • Bowen Chen, Postdoctoral researcher, Department of Agricultural and Consumer Economics, University of Illinois at Urbana-Champaign
      • Section 9.2
      • Section 8

      Comments and Suggestions?

      Any constructive comments and suggestions about how I can improve the book are all welcome. Please send me an email at [email protected] or create an issue on the github page of this book.

      />
      This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


      R as GIS for Economists

      R has extensive capabilities as GIS software. In my opinion, (99\%) of your spatial data processing needs as an economist will be satisfied by R. But, there are several popular options for GIS tasks other than R:

      Here I compare them briefly and discuss why R is a good option.

      R vs Python

      Both R and Python are actually heavily dependent on open source software GDAL and GEOS for their core GIS operations (GDAL for reading spatial data, and GEOS for geometrical operations like intersecting two spatial layers). 1 So, when you run GIS tasks on R or Python you basically tell R or Python what you want to do and they talk to the software, let it do the job, and return the results to you. This means that R and Python are not much different in their capability at GIS tasks as they are dependent on the common open source software for many GIS tasks. When GDAL and GEOS get better, R and Python get better (with a short lag all thanks to those who make updates available on R). Both of them have good spatial visualization tools as well. Moreover, both R and Python can communicate with QGIS and ArcGIS (as long you as have them installed of course) and use their functionalities from within R and Python via the bridging packages: RQGIS and PyQGIS for QGIS, and R-ArcGIS and ArcPy . 2 So, if you are more familiar with Python than R, go ahead and go with Python. From now on, my discussions assume that you are going for the R option, as otherwise, you would not be reading the rest of the book anyway.

      R vs ArcGIS or QGIS

      ArcGIS is commercial software and it is quite expensive (you are likely to be able to get a significant discount if you are a student at or work for a University). On the other hand, QGIS is open source and free. It has seen significant development over the decade, and I would say it is just as competitive as ArcGIS. QGIS also uses open source geospatial software GDAL, GEOS, and others (SAGA, GRASS GIS). Both of them have a graphical interface that helps you implement various GIS tasks unlike R which requires programming.

      Now, since R can use ArcGIS and QGIS through the bridging packages, a more precise question we should be asking is whether you should program GIS tasks using R (possibly using the bridging packages) or manually implement GIS tasks using the graphical interface of ArcGIS or QGIS. The answer is programming GIS tasks using R. First, manual GIS operations are hard to repeat. It is often the case that in the course of a project you need to redo the same GIS task except that the underlying datasets have changed. If you have programmed the process with R, you just run the same code and that’s it. You get the desired results. If you did not program it, you need to go through many clicks on the graphical interface all over again, potentially trying to remember how you actually did it the last time. 3 Second and more important, manual operations are not scalable. It has become much more common that we need to process many large spatial datasets. Imagine you are doing the same operations on (1,000) files using a graphical interface, or even (50) files. Do you know what is good at doing the same tasks over and over again without complaining? A computer. Just let it do what it likes to do. You have better things do.

      Finally, should you learn ArcGIS or QGIS in addition to (or before) R? I am doubtful. As economists, the GIS tasks we need to do are not super convoluted most of the time. Suppose (Omega_R) and (Omega_) represent the set of GIS tasks R and (ArcGIS/QGIS) can implement, respectively. Further, let (Omega_E) represent the set of skills economists need to implement. Then, (Omega_E in Omega_R) (99\%) (or maybe (95\%) to be safe) of the time and (Omega_E otsubset Omega_setminusOmega_R) (99\%) of the time. Personally, I have never had to rely on either ArcGIS or QGIS for my research projects after I learned how to use R as GIS.

      One of the things ArcGIS and QGIS can do but R cannot do ( (Omega_setminusOmega_R) ) is create spatial objects by hand using a graphical user interface, like drawing polygons and lines. Another thing that R lags behind ArcGIS and QGIS is 3D data visualization. But, I must say neither of them is essential for economists at the moment. Finally, sometime it is easier and faster to make a map using ArcGIS and QGIS especially for a complicated map. 4

      Using R as GIS, however, comes with a learning curve for those who have never used R because basic knowledge of R and general programming is required. On the other hand, the GUI-based use of ArcGIS and QGIS has a very low start-up cost. For those who have used R for other purposes like data wrangling and regression analysis, you have already (or almost) climbed up the hill and are ready to learn how to use R as GIS.

      Summary

      Learn how to use R as GIS first. If you find out you really cannot complete the GIS tasks you would like to do using R, then turn to other options.

      This is tough. If you expect significant amount of GIS work, learning R basics and how to use R as GIS is a good investment of your time.

      Why don’t you try R? 5 You may realize you actually do not need them.

      • You have used ArcGIS or QGIS before and are very comfortable with them, but you need to program repetitive GIS tasks?

      Learn R and maybe take advantage of R-ArcGIS or RQGIS , which this book does not cover.

      • You know for sure that you need to run only a simple GIS task once and never have to do any GIS tasks ever again?

      Stop reading and ask one of your friends to do the job. Pay him/her ($20) per hour, which is way below the opportunity cost of setting up either ArcGIS or QGI and learning to do that simple task.

      For example, see the very first sentence of this page↩︎

      We do not learn them in this lecture note because I do not see the benefits of using them.↩︎

      You could take a step-by-step note of what you did though.↩︎

      Let me know if you know something that is essential for economists that only ArcGIS or QGIS can do. I will add that to the list here.↩︎

      I am not saying R does not crash. R does crash. But, often times, the fault is yours, rather than the software’s.↩︎


      1.6. QGIS interface¶

      Typical appearance of QGIS main graphical user interface ( Fig. 1.6.1 ) consists of:

      1. Bar Menu: main features and functions
      2. Toolbar: common features in a single click
      3. Layer panel: list of the project layers
      4. Map panel: geographic display of active layers
      5. Status bar: current coordinates, scale, rotation, and coordinate system

      Additional panels and toolbars can be activated or deactivated from View (1) → Panels (2) or View (2) → Toolbars(3). Alternatively, we can right-click on an empty space (without icons) (4) in the Toolbars or Menu bar section and we will get a full list of available panels and toolbars ( Fig. 1.6.2 ).

      Fig. 1.6.2 – Adding Panels and Toolbars to QGIS interface ¶

      Moreover, we can choose/modify QGIS project properties. It can be done from menu Project (1) → Properties (2). Here we can modify different points of project properties such as general project properties, metadata, CRS, default style, etc. ( Fig. 1.6.3 )

      Fig. 1.6.3 – Checking/modifying QGIS project properties - General ¶

      Finally, the appearance of QGIS can be affected by the settings of the software itself. From menu Settings (1) select Options (2) to configure the ways to use QGIS ( Fig. 1.6.4 ). For example, we can change the general settings, or settings related to the system, CRS, data sources, etc.

      To continue with the lecture, you are requested to download the data that will be used for the following exercises


      Watch the video: QGIS - Polygonize - Raster to Vector