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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Gigas002
This post was updated on .
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@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to convert shapefile to geojson, using c# binding?

Paul Meems
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!


Download the latest MapWinGIS mapping engine.

Download the latest MapWindow 5 open source desktop application.



Op wo 9 jan. 2019 om 16:49 schreef Gigas002 <[hidden email]>:
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
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev