I am using OGR to open a layer, add a filter and then save the results as a separate MapInfo TAB file. Upon trying to save the layer, I get the following error message:
ERROR 5: CreateFeature() failed: invalid feature id 0
Using the same procedure to create a CSV or ESRI Shp works as expected.
My code is as follows:
result = dataSource.ExecuteSQL("select * from '"+ self.inputname +"' WHERE not ST_IsValid(geometry)", dialect = "SQLITE") if ".shp" in self.outputpath: outdrv = ogr.GetDriverByName("ESRI Shapefile") elif ".csv" in self.outputpath: outdrv = ogr.GetDriverByName("CSV") elif ".tab" in self.outputpath: outdrv = ogr.GetDriverByName("MapInfo File") filtered = outdrv.CreateDataSource (self.outputpath) filter_layer = filtered.CopyLayer(result, 'filtered') QMessageBox.information(self, "Process complete", "Process complete! " + str(resultpolygons) + " error(s) detected.")
Whilst attempting to save a layer from an MSSQL server to MapInfo File, I encountered the same issue. It seems as though the OGR python bindings have issues writing the new MapInfo Files.