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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

sji367
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
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to use the GDALRasterize function. Spefically GDALRasterizeOptions.

Even Rouault-2
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
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to use the GDALRasterize function. Spefically GDALRasterizeOptions.

sji367
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
>


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev