#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using GeoAPI.Geometries;
using HEAL.Attic;
using HeuristicLab.Persistence.Core;
using HeuristicLab.Persistence.Interfaces;
using SharpMap.Data;
using SharpMap.Data.Providers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing.Design;
using System.Linq;
namespace HeuristicLab.BioBoost.Persistence {
[Transformer("EDCB7A5F-A05F-4303-9B67-B1C84DF02246", 100)]
public class GeometryFeatureProviderTransformer : BoxTransformer {
public override Box CreateBox(object o, Mapper mapper) {
var box = base.CreateBox(o, mapper);
var value = o as GeometryFeatureProvider;
box.Values = new RepeatedValueBox();
box.Values.Kvps = new RepeatedKeyValuePairsBox();
foreach (DataColumn col in value.Features.Columns) {
Debug.Assert(col.ColumnName != null);
Debug.Assert(col.DataType != null);
box.Values.Kvps.Keys.Add(mapper.GetStringId(col.ColumnName));
box.Values.Kvps.Values.Add(mapper.GetTypeId(col.DataType));
}
return box;
}
public override object ToObject(Box box, Mapper mapper) {
var table = new FeatureDataTable();
for (int i = 0; i>();
foreach (FeatureDataRow row in value.Features.Rows) {
rows.Add(Tuple.Create(row.ItemArray, row.Geometry));
}
box.Values.UInts = new RepeatedUIntBox();
box.Values.UInts.Values.Add(mapper.GetBoxId(rows));
}
public override void FillFromBox(object obj, Box box, Mapper mapper) {
var gfp = obj as GeometryFeatureProvider;
var rows = (List>)mapper.GetObject(box.Values.UInts.Values[0]);
foreach (var row in rows) {
var dataRow = (FeatureDataRow)gfp.Features.LoadDataRow(row.Item1, LoadOption.OverwriteChanges);
dataRow.Geometry = row.Item2;
}
}
protected override void Populate(Box box, GeometryFeatureProvider value, Mapper mapper) {
throw new NotImplementedException();
}
protected override GeometryFeatureProvider Extract(Box box, Type type, Mapper mapper) {
throw new NotImplementedException();
}
}
}