<div dir="ltr">I'm trying to use this gdal_rasterize command in my C# application:<div><div><font face="monospace, monospace">gdal_rasterize -a DN -a_srs "EPSG:28992" -tr 5 5 -a_nodata 0 -l test test.shp test.shp</font></div><div><br></div><div>My goal is to convert a shapefile to a tiff-file. The above command does what I want.</div><div>I need to call it from within my C# application.</div><div>I'm already successfully using wrapper_GDALTranslate and wrapper_GDALWarpDestName but I'm struggling with wrapper_GDALRasterizeDestName.</div><div><br></div><div>I have this code:</div><div><div><font face="monospace, monospace">            using (var ds = Ogr.Open(shapefile, 0)) // 0 means read-only. 1 means writeable.</font></div><div><font face="monospace, monospace">            {</font></div><div><font face="monospace, monospace">                if (ds == null)</font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                    throw new Exception("Can't open OGR dataset: " + shapefile);</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace">                var gdalOptions = new GDALRasterizeOptions(options);</font></div><div><font face="monospace, monospace">                using (var newDs = Gdal.wrapper_GDALRasterizeDestName(output, ds, gdalOptions, null, null))</font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                    if (newDs == null)</font></div><div><font face="monospace, monospace">                    {</font></div><div><font face="monospace, monospace">                        throw new Exception("GdalRasterize failed: " + Gdal.GetLastErrorMsg());</font></div><div><font face="monospace, monospace">                    }</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace">                return true;</font></div><div><font face="monospace, monospace">            }</font></div></div><div><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr">
The problem is with ds, the second parameter of <span style="font-family:monospace,monospace">wrapper_GDALRasterizeDestName</span>. Because it is a shapefile I open it with Ogr, but a Gdal dataset is expected.</div><div>When I open my shapefile with Gdal.Open() I get an error saying my shapefile is not recognized as a supported file format.</div><div><br></div><div>What do I need to do to get this working in my C# application?</div><div><br></div><div>Thanks,</div><div dir="ltr"><br></div><div dir="ltr">
Paul<br><br>
</div></div></div></div></div></div>
</div></div>