[gdal-dev] Using OpenEx() in C# with CSV file

Paul Meems bontepaarden at gmail.com
Mon Oct 23 03:16:24 PDT 2017


Hi List,

I'm trying to read all fields in a CSV file.
Using this command it is working:
ogrinfo -ro -al -so test.csv -oo X_POSSIBLE_NAMES=Lon* -oo
Y_POSSIBLE_NAMES=Lat* -oo KEEP_GEOM_COLUMNS=NO

Now I need to do this in my C# application.
Because I need to send -00 (open options) I cannot use Ogr.Open(), but I
should use Gdal.OpenEx(), right?
OpenEx returns a Dataset, which I somehow need to convert to an
ogr datasource so I can use GetLayerByIndex(), GetFieldCount()
and GetFieldDefn() but I can't get it to work.

Looking at numerous Python example it seems in Python no conversion is
needed.
This is my C# code:
var openOptions = new[]
{
    "X_POSSIBLE_NAMES", "Lon*",
    "Y_POSSIBLE_NAMES", "Lat*",
    "KEEP_GEOM_COLUMNS", "NO"
};
using (var ds = Gdal.OpenEx(input, 4, null, openOptions, null))
{
    if (ds == null)
    {
        throw new Exception("Can't open OGR dataset: " + input);
    }
    // var layer = ds.GetLayerByIndex(0); <----- COMPILE ERROR
}

Any help is much appreciated.

Thanks,

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


More information about the gdal-dev mailing list