[gdal-dev] Unable to create MApInfo .tab File

Avenger Maslog amamaslog at gmail.com
Wed Dec 25 18:43:52 PST 2013


Hi Everyone!

I'm having an issue with creating MapInfo .tab files. I'm trying to
automate the process of creating either .tab or .shp files using the same
set of codes. It works fine when the output specified are shapefiles but
fails with a message: "Failed writing geometry for feature id #" for each
.tab point feature that I was trying to create.The input is dictionary
information and the output comes out as either .shp or .tab depending on
which one was specified. I really hope somebody could point out the reason
why it works with shapefiles but not with tab files. Thanks in advance!

        if fileType == "TAB":
            driver = ogr.GetDriverByName('MapInfo File')

        if fileType == "SHP":
            driver = ogr.GetDriverByName('ESRI Shapefile')

        featureDataSource = driver.CreateDataSource(fileName)

        layerName = "FeatureList"
        featureSpatialRef = osr.SpatialReference()
        featureSpatialRef.ImportFromEPSG(4326)
        featureLayer = featureDataSource.CreateLayer(layerName, srs =
featureSpatialRef, geom_type=ogr.wkbPoint)

        standardFieldsList = []

        standardField = ""

        for attrib in attribList:

            if attrib["FLD_KEY"] == "ATTRIB_NAME":
                standardField = attrib["FLD_VAL"]

            if attrib["FLD_KEY"] == "DATA_TYPE":
                standardField = standardField + "." + attrib["FLD_VAL"]

            if attrib["FLD_KEY"] == "DATA_LEN":
                standardField = standardField + "." + str(attrib["FLD_VAL"])

            if attrib["FLD_KEY"] == "DEF_VAL":
                standardFieldsList.append(standardField)
                standardField = ""

        standardFieldsFileCreator = FileCreator()
        standardFieldsFileCreator.createStandardFields(standardFieldsList,
featureLayer)

        featureObj = ogr.Feature(featureLayer.GetLayerDefn())
        featurePoint = ogr.Geometry(ogr.wkbPoint)

        for feature in featureList:
            for fieldName in feature.keys():
                fieldValue = feature[fieldName]
                featureObj.SetField(str(fieldName), str(fieldValue))

            coords = str(feature["COORDS"])
            coords = coords.strip()[1:-1]
            coords = coords.split(", ")

            featurePoint.AddPoint(float(coords[0]),float(coords[1]))
            featureObj.SetGeometry(featurePoint)

            featureLayer.CreateFeature(featureObj)

        featureDataSource.Destroy()

av
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20131226/da334668/attachment.html>


More information about the gdal-dev mailing list