[13071] | 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;
|
---|
[16575] | 23 | using HEAL.Attic;
|
---|
[13069] | 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.Linq;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.BioBoost.Persistence {
|
---|
| 34 |
|
---|
| 35 | public class GeometryFeatureProviderSerializer : ICompositeSerializer {
|
---|
| 36 |
|
---|
| 37 | #region ICompositeSerializer Members
|
---|
| 38 |
|
---|
| 39 | public int Priority { get { return 200; } }
|
---|
| 40 |
|
---|
| 41 | public bool CanSerialize(Type type) {
|
---|
| 42 | return type == typeof (GeometryFeatureProvider);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
|
---|
| 46 | var table = new FeatureDataTable();
|
---|
| 47 | foreach (var tag in metaInfo)
|
---|
| 48 | table.Columns.Add(tag.Name, (Type)tag.Value);
|
---|
| 49 | return new GeometryFeatureProvider(table);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public IEnumerable<Tag> CreateMetaInfo(object obj) {
|
---|
| 53 | var gfp = obj as GeometryFeatureProvider;
|
---|
| 54 | return from DataColumn col in gfp.Features.Columns select new Tag(col.ColumnName, col.DataType);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
| 58 | var gfp = obj as GeometryFeatureProvider;
|
---|
| 59 | foreach (FeatureDataRow row in gfp.Features.Rows) {
|
---|
| 60 | yield return new Tag(row.ItemArray);
|
---|
| 61 | yield return new Tag(row.Geometry);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public string JustifyRejection(Type type) {
|
---|
| 66 | return "Not a GeometryFeatureProvider";
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public void Populate(object instance, IEnumerable<Tag> tags, Type type) {
|
---|
| 70 | var gfp = instance as GeometryFeatureProvider;
|
---|
| 71 | var it = tags.GetEnumerator();
|
---|
| 72 | while (it.MoveNext()) {
|
---|
| 73 | var row = (FeatureDataRow) gfp.Features.LoadDataRow((object[]) it.Current.Value, LoadOption.OverwriteChanges);
|
---|
| 74 | if (it.MoveNext())
|
---|
| 75 | row.Geometry = (IGeometry) it.Current.Value;
|
---|
| 76 | else
|
---|
| 77 | throw new PersistenceException("invalid data format for GeometryDataProvider: interleaved pairs of features and geometries expected");
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | #endregion
|
---|
| 82 | }
|
---|
| 83 | }
|
---|