private void PrepareTable(DataTable table) { DataColumn shapeColumn = null; foreach (DataColumn column in table.Columns) { if (column.DataType.GetInterfaces().Contains(typeof(IGeometry))) { shapeColumn = column; switch (shapeColumn.DataType.Name) { case "IPoint": _shapeType = 1; break; case "IMultiLineString": _shapeType = 3; break; case "IMultiPolygon": _shapeType = 5; break; } } } if (shapeColumn == null) { throw new ArgumentException("Table does not contain a shape column"); } _table = table; _shapeColumn = shapeColumn; _shapeLength = new int[_table.Rows.Count]; _numParts = new int[_table.Rows.Count]; _numPoints = new int[_table.Rows.Count]; for (int i = 0; i < _table.Rows.Count; ++i) { if (_table.Rows[i].IsNull(_shapeColumn)) { _shapeLength[i] = 2; } else { IGeometry geometry = (IGeometry)_table.Rows[i][_shapeColumn]; switch (_shapeType) { case 1: _shapeLength[i] = 10; break; case 3: IMultiLineString multiLineString = (IMultiLineString)geometry; _numParts[i] = multiLineString.Count; _numPoints[i] = 0; foreach (ILineString lineString in multiLineString.Geometries.Cast<ILineString>()) { _numPoints[i] += lineString.Coordinates.Length; } _shapeLength[i] = 22 + 2 * _numParts[i] + 8 * _numPoints[i]; break; case 5: IMultiPolygon multiPolygon = (IMultiPolygon)geometry; _numParts[i] = multiPolygon.Count; _numPoints[i] = 0; foreach (IPolygon polygon in multiPolygon.Geometries.Cast<IPolygon>()) { _numPoints[i] += polygon.ExteriorRing.Coordinates.Length; } _shapeLength[i] = 22 + 2 * _numParts[i] + 8 * _numPoints[i]; break; } _extent.ExpandToInclude(geometry.EnvelopeInternal); } _fileLength += _shapeLength[i] + 4; } _dbf = new DBaseWriter(_table); }