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.