Error in Tab File creation from FeatureDatatble

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Feb 4, 2015 at 2:46 PM
Edited Feb 4, 2015 at 2:48 PM
Hi Team,
As you respond on my last question creating Tab file from FeatureDataTable i have created the tab file by using functionality insisted by you.
but at the end it gives me a wrong Tab File .
you can download the files from link :- Files

Download Folder Contains:-
Class :- CreateTab.cs (Having a function to write TabFile).
SHP Files:- Having SHP file which i need to convert to Tab
Tab Files:- Having all the Tab Files which i converted from this SHP using CreateTab.cs Class
Image of Tab File open using QGIS-

Image

Note:- I had also try few days back Ogr2Ogr.exe for Converting SHP to Tab Files but it gives me the same result.
Please Assist me in this as i stuck in this from very long.
Coordinator
Feb 5, 2015 at 2:34 PM
The problem is that you need to assign a spatial reference to the mapinfo layer.
Using OGR2OGR you need to add -a_srs:EPSG:4326 to the command line
Using the function described in the previous discussion, you need to (assign and) pass the datasource's srid value.
In the function itself you need to assign a spatial reference based on that value:
//...

// Create the data source
var ds = dr.CreateDataSource(connection, driverOptions);
//if (!ds.TestCapability("ODsCCreateLayer"))
//    throw new Exception(string.Format("Driver '{0}' cannot create a layer!", driver));

// Create the spatial reference
var sr = new OSGeo.OSR.SpatialReference(string.Empty);
sr.ImportFromEPSG(srid);

// Create the layer
var lyr = ds.CreateLayer(table.TableName, sr, (OgrGeometryType)geometryType, layerOptions);
sr.Dispose();

//lyr.GetSpatialRef();
foreach (System.Data.DataColumn dc in table.Columns)
{
    using (var fldDef = GetFieldDefinition(dc))
        lyr.CreateField(fldDef, 0);
}

//...
Marked as answer by sgoyal on 2/6/2015 at 9:55 AM
Feb 6, 2015 at 5:55 PM
thanks it works....
Nov 2, 2015 at 10:58 AM
hi Team,
In this discussion the process to create TabFile is fine,
but when i create tab file using this process the size of tab file increases .
I have just export 3MB tab file and in result it results me to 18MB tab file.

Following code has been called in loop for each _DataRow.:-
if (_Datarow != null && lyr != null && _fdt != null && _fdt.Columns.Count > 0)
                {
                    using (var ld = lyr.GetLayerDefn())
                    using (var feature = new Feature(lyr.GetLayerDefn()))
                    {
                        Geometry Gm = null;
                        if (_Datarow.Geometry.GeometryType.ToLower() == "linestring")
                            Gm = new Geometry(wkbGeometryType.wkbLineString);
                        else if (_Datarow.Geometry.GeometryType.ToLower() == "polygon" 
                            || _Datarow.Geometry.GeometryType.ToLower() == "linearring")
                            Gm = new Geometry(wkbGeometryType.wkbLinearRing);
                        else if (_Datarow.Geometry.GeometryType.ToLower() == "point")
                            Gm = new Geometry(wkbGeometryType.wkbPoint);

                        foreach (var crd in _Datarow.Geometry.Coordinates)
                        {
                            Gm.AddPoint(crd.X, crd.Y, crd.Z);
                        }
                        feature.SetGeometry(Gm);
                        var idx = -1;
                        foreach (DataColumn dc in _fdt.Columns)
                        {

                            idx++;
                            var fd = ld.GetFieldDefn(idx);
                            DateTime dt;
                            switch (fd.GetFieldType())
                            {
                                case FieldType.OFTBinary:
                                    //Nothing
                                    break;
                                case FieldType.OFTDate:
                                    dt = ((DateTime)_Datarow[dc]).Date;
                                    feature.SetField(idx, dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, 0);
                                    break;
                                case FieldType.OFTDateTime:
                                    dt = (DateTime)_Datarow[dc];
                                    feature.SetField(idx, dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, 0);
                                    break;
                                case FieldType.OFTTime:
                                    var tod = ((DateTime)_Datarow[dc]).TimeOfDay;
                                    feature.SetField(idx, 0, 0, 0, tod.Hours, tod.Minutes, tod.Seconds, 0);
                                    break;
                                case FieldType.OFTInteger:
                                    feature.SetField(idx, Convert.ToInt32(_Datarow[dc]));
                                    break;
                                case FieldType.OFTIntegerList:
                                    var il = GetIntegerList(_Datarow[dc], dc.DataType);
                                    feature.SetFieldIntegerList(idx, il.Length, il);
                                    break;
                                case FieldType.OFTReal:
                                    feature.SetField(idx, Convert.ToDouble(_Datarow[dc]));
                                    break;
                                case FieldType.OFTRealList:
                                    var dl = GetDoubleList(_Datarow[dc], dc.DataType);
                                    feature.SetFieldDoubleList(idx, dl.Length, dl);
                                    break;
                                case FieldType.OFTString:
                                    feature.SetField(idx, Convert.ToString(_Datarow[dc]));
                                    break;
                                case FieldType.OFTStringList:
                                    var sl = (string[])_Datarow[dc];
                                    feature.SetFieldStringList(idx, sl);
                                    break;

                            }
                            fd.Dispose();
                        }

                        lyr.CreateFeature(feature);
                        feature.Dispose();
                    }

                }
Please help in this.:)
Coordinator
Nov 3, 2015 at 10:01 AM
I suppose that you have columns with string type and the column width is not explicitly set and therefor 255 chars used by default.
This is causing your attribute file to explode.

You might be able to change that when you change character handling in ReadColumnDefinition function like this
    break;
case OgrFieldType.OFTWideString:
case OgrFieldType.OFTString:
    var c = fdt.Columns.Add(ogrFldDef.GetName(), typeof(String));
    c.MaxLength = ogrFldDef.GetWidth();
    break;
case OgrFieldType.OFTStringList: