source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Persistence/GeometryFeatureProviderTransformer.cs @ 17777

Last change on this file since 17777 was 17777, checked in by epitzer, 13 months ago

#3086 add transformers for GeometryFeatureProvider and IGeometry

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using GeoAPI.Geometries;
23using HEAL.Attic;
24using HeuristicLab.Persistence.Core;
25using HeuristicLab.Persistence.Interfaces;
26using SharpMap.Data;
27using SharpMap.Data.Providers;
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Diagnostics;
32using System.Drawing.Design;
33using System.Linq;
34
35namespace HeuristicLab.BioBoost.Persistence {
36
37  [Transformer("EDCB7A5F-A05F-4303-9B67-B1C84DF02246", 100)]
38  public class GeometryFeatureProviderTransformer : BoxTransformer<GeometryFeatureProvider> {
39   
40    public override Box CreateBox(object o, Mapper mapper) {
41      var box = base.CreateBox(o, mapper);
42      var value = o as GeometryFeatureProvider;
43      box.Values = new RepeatedValueBox();
44      box.Values.Kvps = new RepeatedKeyValuePairsBox();
45      foreach (DataColumn col in value.Features.Columns) {
46        Debug.Assert(col.ColumnName != null);
47        Debug.Assert(col.DataType != null);
48        box.Values.Kvps.Keys.Add(mapper.GetStringId(col.ColumnName));
49        box.Values.Kvps.Values.Add(mapper.GetTypeId(col.DataType));
50      }
51      return box;
52    }
53
54    public override object ToObject(Box box, Mapper mapper) {
55      var table = new FeatureDataTable();
56      for (int i = 0; i<box.Values.Kvps.Keys.Count; i++) {
57        table.Columns.Add(
58          mapper.GetString(box.Values.Kvps.Keys[i]),
59          mapper.GetType(box.Values.Kvps.Values[i]));
60      }
61      return new GeometryFeatureProvider(table);
62    }
63
64    public override void FillBox(Box box, object o, Mapper mapper) {
65      var value = o as GeometryFeatureProvider;
66      var rows = new List<Tuple<object[], IGeometry>>();
67      foreach (FeatureDataRow row in value.Features.Rows) {
68        rows.Add(Tuple.Create(row.ItemArray, row.Geometry));
69      }
70      box.Values.UInts = new RepeatedUIntBox();
71      box.Values.UInts.Values.Add(mapper.GetBoxId(rows));
72    }
73
74    public override void FillFromBox(object obj, Box box, Mapper mapper) {
75      var gfp = obj as GeometryFeatureProvider;
76      var rows = (List<Tuple<object[], IGeometry>>)mapper.GetObject(box.Values.UInts.Values[0]);
77      foreach (var row in rows) {
78        var dataRow = (FeatureDataRow)gfp.Features.LoadDataRow(row.Item1, LoadOption.OverwriteChanges);
79        dataRow.Geometry = row.Item2;
80      }
81    }
82
83    protected override void Populate(Box box, GeometryFeatureProvider value, Mapper mapper) {
84      throw new NotImplementedException();
85    }
86
87    protected override GeometryFeatureProvider Extract(Box box, Type type, Mapper mapper) {
88      throw new NotImplementedException();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.