Sample Python add-in script for creating and inserting a feature into a MapInfo Table using GDAL with MapInfo Pro extensibilty

products affected: MapInfo Pro™
The attached example Python add-in script, gdal_create_table.py, can be used as part of MapInfo Pro extensibility to create and insert a feature into a MapInfo Table using GDAL.

from osgeo import ogr

# more example for creating a geomtry and gdal usage here.
# https://pcjericks.github.io/py-gdalogr-cookbook/geometry.html

def createNativeTab(filename):
    ds = ogr.GetDriverByName('MapInfo EFAL').CreateDataSource(filename, options=['FORMAT=NATIVE'])
    lyr = ds.CreateLayer('newNative')
    lyr.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger))
    feat = ogr.Feature(lyr.GetLayerDefn())
    feat.SetField('ID', 1)
    geojson = '{"type":"MultiPolygon","coordinates":[[[[-96.16112799999999,31.72572],[-96.16165199999999,31.725734],[-96.16165,31.726202999999998],[-96.16113299999999,31.726212999999998],[-96.16113,31.726056999999997],[-96.161127,31.725747],[-96.16112799999999,31.72572]]]]}'
    feat.SetGeometryDirectly(ogr.CreateGeometryFromJson(geojson))
    lyr.CreateFeature(feat)
    ds = None

def createNativeXTab(filename):
    ds = ogr.GetDriverByName('MapInfo EFAL').CreateDataSource(filename, options=['FORMAT=NATIVEX'])
    lyr = ds.CreateLayer('newNativeX')
    lyr.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger))
    feat = ogr.Feature(lyr.GetLayerDefn())
    feat.SetField('ID', 1)
    geojson = '{"type":"MultiPolygon","coordinates":[[[[-96.16112799999999,31.72572],[-96.16165199999999,31.725734],[-96.16165,31.726202999999998],[-96.16113299999999,31.726212999999998],[-96.16113,31.726056999999997],[-96.161127,31.725747],[-96.16112799999999,31.72572]]]]}'
    feat.SetGeometryDirectly(ogr.CreateGeometryFromJson(geojson))
    lyr.CreateFeature(feat)
    ds = None


createNativeTab("C:\\Delete\\qt\\newNative.tab")
createNativeXTab("C:\\Delete\\qt\\newNativeX.tab")


 
UPDATED:  June 17, 2020