3

I'm taking the first steps in QGIS (version 2.2 Valmiera) and I am having some difficulties in knowing what mathematical criterion that QGIS uses when converting polygons (shapefile) to raster. I'm using a resolution of 100 by 100 pixels.

Commands: Raster - Conversion

What is the percentage that the program uses?When I overlap the shapefile and raster that the information is not 100% coincidental. I understand that the information is not completely coincident, because the raster consists in squares (pixels).

As I understand the raster is a binary system 0 (absence) and 1 (presence of what is to be studied). This "1" corresponds to a square (pixel). what is your percentage? What is the mathematical mechanism? I'm losing information?


In Figure 4 you can see how the overlap is not complete (marked with circles). What I would like to know which algorithm that QGIS uses the rasterization? What is your standard? Is there a percentage to exclude certain information? I understand that in geometric terms the result of a shapefile is not the same as a raster. For the program to do the rasterization process will have to be a mathematical foundation?

enter image description here

enter image description here

enter image description here

enter image description here

6
  • 1
    Odds are, it's not a percentage threshold, just a Bresenham's line algorithm ( en.wikipedia.org/wiki/Bresenham%27s_line_algorithm ) or the polygon equivalent. You can inspect the source if you like. If you're losing information, it's because you're using the wrong pixel size.
    – Vince
    Commented Jun 4, 2014 at 17:47
  • 3
    please edit your question instead of posting again. As I said, in my previous answer, it uses a binary decision rule (is the center of the pixel within the polygon). I don't see what you want to point out with your illustration.
    – radouxju
    Commented Jun 5, 2014 at 11:09
  • 1
    You could have edited the previous question to contain the graphics necessary to clarify your question (not that this is much clearer)
    – Vince
    Commented Jun 5, 2014 at 11:15
  • If you choose too coarse a pixel size, the result of vector to raster conversion looks blocky. I don't see anything in these new graphics that indicate algorithm failure.
    – Vince
    Commented Jun 5, 2014 at 12:12
  • The code is here trac.osgeo.org/gdal/browser/trunk/gdal/alg/gdalrasterize.cpp?
    – user30184
    Commented Jun 5, 2014 at 12:29

3 Answers 3

5

Explained with pictures:

  • Take a polygon
  • Place it on the raster canvas
  • Remove all pixels which are totally outside of the polygon

enter image description here enter image description here enter image description here

  • Select pixels with their centre points lying outside of the polygon.
  • Remove selected pixels
  • What remains is the result of rasterization.

enter image description here enter image description here enter image description here

This is the default behaviour of rasterization in QGIS. However, if the gdal_rasterize command is run with the -at (ALL TOUCHED) switch all the pixels which intersect the polygon will be selected and the result will be as in the third image above where only the totally outlying pixels were removed. The ALL TOUCHED setting should be used with care because it may lead to odd results when the layer that is to be rasterized contains adjacent polygons or other close objects.

5
  • It would be nice if rasterization procedures actually had this option, but it would require quite a bit more computation than the usual algorithm (which selects cells whose centers lie within the polygon). Could you therefore provide us an authoritative citation which supports your description--or, better yet, indicate software that actually does what you say?
    – whuber
    Commented Jun 5, 2014 at 12:36
  • 1
    Meaning of my edited description "probably based simply on the position of the centre of the pixel" was the same. Definitive answer can be found from trac.osgeo.org/gdal/browser/trunk/gdal/alg/gdalrasterize.cpp. I will make a new edit.
    – user30184
    Commented Jun 5, 2014 at 12:44
  • Thanks for that link. It's actually a little more complicated than your new answer makes out. There are several options related to how cells near the polygon's boundary are treated. See the comments at lines 542-544.
    – whuber
    Commented Jun 5, 2014 at 12:54
  • 2
    Thanks for pointing out the comment. However, perhaps in the QGIS context it does not change much because the user interface in QGIS does not have an option to set the -at (ALL TOUCHED) switch. It is not impossible because the command can be edited manually, though.
    – user30184
    Commented Jun 5, 2014 at 13:03
  • 1
    As I said, in QGIS rasterize does not use the proportion. Note that ArcGIS polygon to raster allows for more complex (and more time consuming) options: cell center, maximum area and maximum combined area.
    – radouxju
    Commented Jun 5, 2014 at 18:19
3

for polygons, the algorithm is based on the position of the center of the pixel with respect to the polygon. Pixels whose center point is within the polygon will have the value of this polygon.

0
2

The standard raster algorithm used in QGIS is gdal_rasterize from the GDAL library. You can increase your results' accuracy by using a smaller pixel size for the raster. The parameters needed are described in the link. I hope that helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.