[gdal-dev] Gdal Mapinfo driver write access

HappyFrasse fdr at cartesia.se
Sat Feb 22 04:51:43 PST 2014


Hi

I am trying to use the latest ogr/gdal library in my dotnet projekt. I do
ref. to ogr_csharp, gdal_csharp.
My problem is that I can read my Mapinfo tab-file but I can’t write (append)
features to it and I don’t understand why?

If I open the mapinfo file with Ogr.Open(_FileName, 0) I got write access
error when using “CreateFeature”.
If I change the second parameter to 1 (in open) then I won’t get any
datasource. Why? Does ogr/gdal not support write /append to some existing
mapinfo file?

My code goes like:

*****Code start ***
Ogr.RegisterAll()

'Open data source.
Dim dsTab As DataSource = Ogr.Open(_FileName, 0)
'Dim dsTab As DataSource = Ogr.Open(_FileName, 1)
If dsTab Is Nothing Then
    System.Diagnostics.Debug.WriteLine("Can't open " + _FileName)
End If

'Get driver 
 Dim drvTab As Driver = dsTab.GetDriver()
If drvTab Is Nothing Then
     System.Diagnostics.Debug.WriteLine("Can't get driver.")
End If
System.Diagnostics.Debug.WriteLine("Using driver " + drvTab.name)

Dim layerTab As Layer = Nothing
Dim i As Integer = 0
Dim iLayers As Integer = dsTab.GetLayerCount

layerTab = dsTab.GetLayerByIndex(0)
Dim layerName As String = layerTab.GetName
System.Diagnostics.Debug.WriteLine("Layername " + layerName)

Dim feature As Feature = New Feature(layerTab.GetLayerDefn())
feature.SetFID(Ogr.OGRNullFID)

feature.SetField("TraktId", "Mytest_TraktId")

Dim geom As Geometry = Geometry.CreateFromWkt("POINT(47.0 19.2)")
If feature.SetGeometry(geom) <> 0 Then
     System.Diagnostics.Debug.WriteLine("Failed add geometry to the
feature.")
End If

If layerTab.CreateFeature(feature) <> 0 Then
     System.Diagnostics.Debug.WriteLine("Failed to create feature in file.")
End If
*** code end ***

Is my code wrong or do I missunderstood something?

Regards/Frasse




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Gdal-Mapinfo-driver-write-access-tp5105252.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list