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

sreed at ccom.unh.edu sreed at ccom.unh.edu
Tue May 29 12:29:23 PDT 2018


Even,

Thank you so much! This fixed my problem!

Thanks again,
Sam




> Sam,
>
>>
>> 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
>>                     };/
>
> You need to add a final NULL pointer at the end of the options[] array,
> otherwise GDALRasterize() has no way to know where the array ends.
>
>>
>>
>> 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.
>
> GDALRasterize() returns a dataset handle that you can potentially
> immediately
> use for reading its content with RasterIO().But at some point you
> explicitly
> need to GDALClose() it otherwise the dataset might not be completely
> serialized to disk
>
> If you GDALOpen() this dataset before it has been closed, then you may
> read a
> partially flushed dataset.
>
> Even
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
>




More information about the gdal-dev mailing list