Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Persistence/ShapeFileLoader.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 8 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 1.0 KB
RevLine 
[13069]1using SharpMap.Data;
2using SharpMap.Data.Providers;
3using System.Data;
4using System.IO;
5using System.Linq;
6
7namespace HeuristicLab.BioBoost.Persistence {
8
9  public static class ShapeFileLoader {
10    public static GeometryFeatureProvider LoadShapeFile(string filename) {
11      var shapefile = new ShapeFile(filename, true, true);
12      shapefile.Open();
13      var table = new FeatureDataTable {TableName = Path.GetFileNameWithoutExtension(shapefile.Filename)};
14      bool addColumns = true;
15      foreach (var row in shapefile.GetObjectIDsInView(shapefile.GetExtents()).Select(shapefile.GetFeature)) {
16        if (addColumns && row.Table != null) {
17          foreach (DataColumn col in row.Table.Columns)
18            table.Columns.Add(col.ColumnName, col.DataType);
19          addColumns = false;
20        }
21        var newRow = (FeatureDataRow) table.LoadDataRow(row.ItemArray, LoadOption.OverwriteChanges);
22        newRow.Geometry = row.Geometry;
23      }
24      return new GeometryFeatureProvider(table);
25    }
26  }
27}
Note: See TracBrowser for help on using the repository browser.