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

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

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

File size: 2.0 KB
Line 
1using GeoAPI.Geometries;
2using HeuristicLab.Persistence.Core;
3using HeuristicLab.Persistence.Interfaces;
4using SharpMap.Data;
5using SharpMap.Data.Providers;
6using System;
7using System.Collections.Generic;
8using System.Data;
9using System.Linq;
10
11namespace HeuristicLab.BioBoost.Persistence {
12
13  public class GeometryFeatureProviderSerializer : ICompositeSerializer {
14
15    #region ICompositeSerializer Members
16
17    public int Priority { get { return 200; } }
18
19    public bool CanSerialize(Type type) {
20      return type == typeof (GeometryFeatureProvider);
21    }
22
23    public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
24      var table = new FeatureDataTable();
25      foreach (var tag in metaInfo)
26        table.Columns.Add(tag.Name, (Type)tag.Value);
27      return new GeometryFeatureProvider(table);
28    }
29
30    public IEnumerable<Tag> CreateMetaInfo(object obj) {
31      var gfp = obj as GeometryFeatureProvider;
32      return from DataColumn col in gfp.Features.Columns select new Tag(col.ColumnName, col.DataType);
33    }
34
35    public IEnumerable<Tag> Decompose(object obj) {
36      var gfp = obj as GeometryFeatureProvider;
37      foreach (FeatureDataRow row in gfp.Features.Rows) {
38        yield return new Tag(row.ItemArray);
39        yield return new Tag(row.Geometry);
40      }
41    }
42
43    public string JustifyRejection(Type type) {
44      return "Not a GeometryFeatureProvider";
45    }
46
47    public void Populate(object instance, IEnumerable<Tag> tags, Type type) {
48      var gfp = instance as GeometryFeatureProvider;
49      var it = tags.GetEnumerator();
50      while (it.MoveNext()) {
51        var row = (FeatureDataRow) gfp.Features.LoadDataRow((object[]) it.Current.Value, LoadOption.OverwriteChanges);
52        if (it.MoveNext())
53          row.Geometry = (IGeometry) it.Current.Value;
54        else
55          throw new PersistenceException("invalid data format for GeometryDataProvider: interleaved pairs of features and geometries expected");
56      }
57    }
58
59    #endregion
60  }
61}
Note: See TracBrowser for help on using the repository browser.