[gdal-dev] How to use wrapper_GDALRasterizeDestName with C# bindings

Paul Meems bontepaarden at gmail.com
Tue Mar 14 07:12:20 PDT 2017


I'm trying to use this gdal_rasterize command in my C# application:
gdal_rasterize -a DN -a_srs "EPSG:28992" -tr 5 5 -a_nodata 0 -l test
test.shp test.shp

My goal is to convert a shapefile to a tiff-file. The above command does
what I want.
I need to call it from within my C# application.
I'm already successfully using wrapper_GDALTranslate
and wrapper_GDALWarpDestName but I'm struggling
with wrapper_GDALRasterizeDestName.

I have this code:
            using (var ds = Ogr.Open(shapefile, 0)) // 0 means read-only. 1
means writeable.
            {
                if (ds == null)
                {
                    throw new Exception("Can't open OGR dataset: " +
shapefile);
                }
                var gdalOptions = new GDALRasterizeOptions(options);
                using (var newDs =
Gdal.wrapper_GDALRasterizeDestName(output, ds, gdalOptions, null, null))
                {
                    if (newDs == null)
                    {
                        throw new Exception("GdalRasterize failed: " +
Gdal.GetLastErrorMsg());
                    }
                }
                return true;
            }

The problem is with ds, the second parameter of
wrapper_GDALRasterizeDestName. Because it is a shapefile I open it with
Ogr, but a Gdal dataset is expected.
When I open my shapefile with Gdal.Open() I get an error saying my
shapefile is not recognized as a supported file format.

What do I need to do to get this working in my C# application?

Thanks,

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170314/cbd6ecbf/attachment.html>


More information about the gdal-dev mailing list