[gdal-dev] How to convert shapefile to geojson, using c# binding?

Paul Meems bontepaarden at gmail.com
Thu Jan 10 01:15:19 PST 2019


I use it like this:
var options = new[]
{
    "-f", "GeoJSON",
    "-lco", "RFC7946=YES"
};
VectorTranslate(shapefileLocation, output, options);

public void VectorTranslate(string input, string output, string[] options)
{
    if (!input.StartsWith("PG:") && !File.Exists(input))
    {
        throw new FileNotFoundException("Can't find the input file",
            new Exception("Working with " + input));
    }

    using (var ds = Gdal.OpenEx(input, 4, null, null, null))
    {
        if (ds == null)  throw new Exception("Can't open GDAL dataset: " +
input);

        var gdalOptions = new GDALVectorTranslateOptions(options);
        using (var newDs = Gdal.wrapper_GDALVectorTranslateDestName(output,
ds, gdalOptions, null, null))
        {
            if (newDs == null)  throw new Exception("VectorTranslate
failed: " + Gdal.GetLastErrorMsg());
        }
    }
}


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 a new forum
<https://mapwindow.discourse.group>!*


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>



Op wo 9 jan. 2019 om 16:49 schreef Gigas002 <gigas002 at yandex.ru>:

> Hello. Does anybody know, if there's a way to convert shapefile to geojson
> using c# bindings? I know about ogr2ogr.exe, but I'd still prefer bindings
> if it's possible.
>
>
>
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190110/4c338171/attachment.html>


More information about the gdal-dev mailing list