[gdal-dev] problem in GDALRasterize

Ahmet Temiz ahmettemiz88 at gmail.com
Sun May 28 07:56:10 PDT 2023


Hi,
I want to use GDALRasterize.
here is the code: (GDALRasterizeOptions is problematic)

#include "/usr/include/gdal/gdal_priv.h"
#include </usr/include/gdal/gdal.h>
#include </usr/include/gdal/gdal_utils.h>
#include <gdal/ogr_geometry.h>
#include <iostream>
#include <errno.h>

int main()
{
    // Register GDAL drivers
    GDALAllRegister();

    // Set the driver for the output raster dataset
    GDALDriver* driver = GetGDALDriverManager()->GetDriverByName("GTiff");

    // Define the dimensions and properties of the output raster dataset
    int width = 100;
    int height = 100;
    int num_bands = 1;
    GDALDataType data_type = GDT_Byte;  // Data type of the raster values
    const char* output_path = "output.tif";  // Path to the output raster
dataset

    // Create an empty raster dataset
    GDALDataset* dataset = driver->Create(output_path, width, height,
num_bands, data_type, nullptr);

    // Set the spatial reference system of the raster dataset (optional)
    OGRSpatialReference srs;
    srs.importFromEPSG(4326);  // WGS84
    char* srs_wkt = nullptr;
    srs.exportToWkt(&srs_wkt);
    dataset->SetProjection(srs_wkt);
    CPLFree(srs_wkt);

    // Open the vector file and get the layer
    const char* vector_path = "test.shp";  // Path to the input vector file
    GDALDataset* vector_dataset = (GDALDataset*)GDALOpenEx(vector_path,
   GDAL_OF_VECTOR, nullptr, nullptr, nullptr);
    OGRLayer* layer = vector_dataset->GetLayer(0);

    // Set the rasterization options
    GDALRasterizeOptions options;
    options.width = width;
    options.height = height;
    options.outputType = data_type;
    options.burnValues = nullptr;  // Optional array of values to burn into
the raster

    // Rasterize the vector layer into the output raster dataset
    GDALRasterize(dataset, num_bands, &layer, &options, nullptr, nullptr);
    // Cleanup
    GDALClose(vector_dataset);
    GDALClose(dataset);

    // Cleanup GDAL
    GDALDestroyDriverManager();

    return 0;
}

Can you tell me what is wrong ?

regards


-- 
Ahmet Temiz
Jeoloji Müh.
Afet ve Acil Durum Yönetimi Başkanlığı
Deprem  Dairesi Başkanlığı


________________________

Ahmet Temiz
Geological Eng.

Disaster and Emergency Management
of Presidency
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230528/03c042b9/attachment.htm>


More information about the gdal-dev mailing list