[gdal-dev] How to use wrapper_GDALRasterizeDestName with C# bindings
Paul Meems
bontepaarden at gmail.com
Tue Mar 14 07:57:31 PDT 2017
Thanks Even,
I now have
using (var ds = Gdal.OpenEx(input, 1, null, null, null))
I couldn't find GDAL_OF_VECTOR in the C# bindings. I'm assuming it must be
1 since GDAL_OF_RASTER is 0.
It is now working.
Paul
*Paul Meems *
Release manager, configuration manager
and forum moderator of MapWindow GIS.
www.mapwindow.org
Owner of MapWindow.nl - Support for
Dutch speaking users.
www.mapwindow.nl
*The MapWindow GIS project has moved to GitHub
<https://github.com/MapWindow>!*
Download the latest MapWinGIS mapping engine.
<https://github.com/MapWindow/MapWinGIS/releases>
Download the latest MapWindow 5 open source desktop application.
<https://github.com/MapWindow/MapWindow5/releases>
2017-03-14 15:23 GMT+01:00 Even Rouault <even.rouault at spatialys.com>:
> On mardi 14 mars 2017 15:12:20 CET Paul Meems wrote:
>
> > 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.
>
>
>
> Use Gdal.OpenEx(). This will allow vector drivers to be used and return a
> GDAL dataset.
>
>
>
> >
>
> > What do I need to do to get this working in my C# application?
>
> >
>
> > Thanks,
>
> >
>
> > Paul
>
>
>
>
>
> --
>
> Spatialys - Geospatial professional services
>
> http://www.spatialys.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170314/4b3b9bb2/attachment-0001.html>
More information about the gdal-dev
mailing list