[gdal-dev] How to use the GDALRasterize function. Spefically GDALRasterizeOptions.

sji367 sreed at ccom.unh.edu
Mon May 28 19:08:38 PDT 2018


Hey all,

I have a few questions with the GDALRasterize fuction. 

1) How do I set the GDALRasterizeOptions?
I have tried:

    /// Create the list of options. Use the same as found on the command
line gdal_rasterize utility
    //  http://www.gdal.org/gdal_rasterize.html
    char *options[] = {
                            "-at", // All touched (all pixels touched by
lines or polygons will be
                                   //   updated, not just those whose center
point is within the polygon)
                            "-a_nodata", "-10", // Set the value to be used
if there is no data
                            "-tr", resolution_str, resolution_str, // Set
the X and Y resolution (grid size)
                            "-ot", dtype, // Set the output type (in this
case we are using double)
                            "-a", attribute,  // Set which attribute you
want to use to determines the raster's value
                            "-te", xMin, yMin, xMax, yMax, // Set the X,Y
bounds of the raster (i.e. touched extent)
                            "-q" // Quiet option
                    };/

where resolution_str, attribute, xMin, yMin, xMax, and yMax are char*s.

when I remove any of the options from the above code, this later line in the
code segfaults:
      /GDALRasterizeOptions *Options = GDALRasterizeOptionsNew(options,
NULL);/


The other method that I have tried is:
    /char** options = nullptr;
    options = CSLSetNameValue(options, "ALL_TOUCHED", "TRUE");
    options = CSLSetNameValue(options, "ATTRIBUTE", "Depth");
    options = CSLSetNameValue(options, "NO_DATA", "-10");/

The error that I get when I try this method is:
    /ERROR 6: Too many command options 'ALL_TOUCHED=TRUE'/


2) I am want to read the file I created with the GDALRasterize function
immediately. When I try to do that by passing in a filename into the const
char *pszDest (GD/ALRasterize(rasterfile.c_str(), NULL, ds_shp, Options,
NULL);/), the get the no data value is what is read. After the program is
finished, I can read the file normally. Therefore I do not think the file is
closing until after the program has exited. 

The other method that I tried was passing in a new datasource through the
GDALDatasetH hDstDS option (/GDALRasterize(NULL, ds_tiff, ds_shp, Options,
NULL);/). When I tried this, the dataset is empty. 

I was wondering is there a way to grid the data (it is a shapefile) through
a utility like GDALRasterize and then collect it through a utility like
RasterIO.


Thanks,
Sam
  



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html


More information about the gdal-dev mailing list