TransWikia.com

gdal_rasterize incorrect values scale after rasterization

Geographic Information Systems Asked by traveller on January 8, 2021

I am trying to rasterize a .shp file (in particular it is made up by several Polygon) into .tif one by using python and the gdal_rasterize command.

According to the gdal_rasterize function, I was able to set the options:

  • a (the attribute that I want to be mirrored within the raster)
  • tr (since I know the width and heigth pixel of each polygon)
  • te (also in this case I have the boundary of the .shp)

The conversion is correctly in terms of positions within the map. But the range of values is different w.r.t the .shp file.

The command called was:

 import subprocess

 def rasterize(source_shape_file, layer_name, attribute, dest_file,
               width, height, xmin, ymin, xmax, ymax, dest_file):

   subprocess.check_output("gdal_rasterize -a " + str(attribute) + " -l " + str(layer_name) + " -tr " 
                           + str(width) + " " +  str(height) +  "-a_nodata -1.0 -te " + str(xmin) + " 
                           " + str(ymin) + " " + str(xmax) + " " + str(ymax) + " -of GTiff " + "'" + 
                           str(source_shape_file) + "'"+ " " +str(dest_file) + "")

By executing this, within QGIS I was able to saw the result:

enter image description here

The raster value with some blue transparency completely overlap the vector layer as expected.

However the data range:

enter image description here

As it is possible to see, is different between the two layer.
I mean for the max and min value.

Am I doing something wrong during the execution of the command?
Or is there some option that I have ignored?

I would like to know if there is some way to obtain the same values of the vector layer inside the raster one.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP