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 |
|
---|
22 | using GeoAPI.Geometries;
|
---|
23 | using HEAL.Attic;
|
---|
24 | using HeuristicLab.Persistence.Core;
|
---|
25 | using HeuristicLab.Persistence.Interfaces;
|
---|
26 | using SharpMap.Data;
|
---|
27 | using SharpMap.Data.Providers;
|
---|
28 | using System;
|
---|
29 | using System.Collections.Generic;
|
---|
30 | using System.Data;
|
---|
31 | using System.Diagnostics;
|
---|
32 | using System.Drawing.Design;
|
---|
33 | using System.Linq;
|
---|
34 |
|
---|
35 | namespace 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 | }
|
---|