0

I'm trying to read all fields in a CSV file using GDAL v2.1.3 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 -oo (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.

Paul Meems
  • 3,002
  • 4
  • 35
  • 66

2 Answers2

0

I am no swig expert at all, but it looks like the vector (OGR) part of the Dataset is specifically NOT defined for C# in the current GDAL code

0

I was facing similar issues with C++, trying to switch from ogr2ogr CLI to GDAL C++. Maybe this will help someone.

I had to format my options array differently to get it to work :

  const char *optionsArray[5] = {
    "X_POSSIBLE_NAMES=lon*",
    "Y_POSSIBLE_NAMES=lat*",
    "Z_POSSIBLE_NAMES=alt*",
    "KEEP_GEOM_COLUMNS=NO",
    NULL
  };

In C++ I have to add the ending NULL as stated by GDALOpenEx documentation.

Francois
  • 143
  • 7