<div dir="ltr"><div><div><span class=""><span>Hi Everyone!<br><br></span></span></div><span class=""><span>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!<br>
<br> if fileType == "TAB":<br> driver = ogr.GetDriverByName('MapInfo File')<br><br> if fileType == "SHP":<br> driver = ogr.GetDriverByName('ESRI Shapefile') <br>
<br> featureDataSource = driver.CreateDataSource(fileName)<br> <br> layerName = "FeatureList"<br> featureSpatialRef = osr.SpatialReference()<br> featureSpatialRef.ImportFromEPSG(4326)<br>
featureLayer = featureDataSource.CreateLayer(layerName, srs = featureSpatialRef, geom_type=ogr.wkbPoint)<br> <br> standardFieldsList = []<br> <br> standardField = ""<br> <br>
for attrib in attribList: <br> <br> if attrib["FLD_KEY"] == "ATTRIB_NAME":<br> standardField = attrib["FLD_VAL"]<br><br> if attrib["FLD_KEY"] == "DATA_TYPE":<br>
standardField = standardField + "." + attrib["FLD_VAL"]<br> <br> if attrib["FLD_KEY"] == "DATA_LEN":<br> standardField = standardField + "." + str(attrib["FLD_VAL"])<br>
<br> if attrib["FLD_KEY"] == "DEF_VAL":<br> standardFieldsList.append(standardField)<br> standardField = "" <br> <br> standardFieldsFileCreator = FileCreator()<br>
standardFieldsFileCreator.createStandardFields(standardFieldsList, featureLayer)<br><br> featureObj = ogr.Feature(featureLayer.GetLayerDefn())<br> featurePoint = ogr.Geometry(ogr.wkbPoint)<br> <br>
for feature in featureList:<br> for fieldName in feature.keys():<br> fieldValue = feature[fieldName]<br> featureObj.SetField(str(fieldName), str(fieldValue))<br> <br>
coords = str(feature["COORDS"])<br> coords = coords.strip()[1:-1]<br> coords = coords.split(", ")<br> <br> featurePoint.AddPoint(float(coords[0]),float(coords[1])) <br>
featureObj.SetGeometry(featurePoint)<br> <br> featureLayer.CreateFeature(featureObj)<br><br> featureDataSource.Destroy()<br><br></span></span></div><span class=""><span>av<br></span></span></div>