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 HeuristicLab.Persistence.Core;
|
---|
24 | using HeuristicLab.Persistence.Interfaces;
|
---|
25 | using NetTopologySuite.IO;
|
---|
26 | using System;
|
---|
27 | using System.Collections.Generic;
|
---|
28 | using System.Linq;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.BioBoost.Persistence {
|
---|
31 |
|
---|
32 | public class GeometrySerializer : ICompositeSerializer {
|
---|
33 |
|
---|
34 | #region ICompositeSerializer Members
|
---|
35 |
|
---|
36 | public int Priority {
|
---|
37 | get { return 300; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public bool CanSerialize(Type type) {
|
---|
41 | return type.GetInterfaces().Contains(typeof (IGeometry));
|
---|
42 | }
|
---|
43 |
|
---|
44 | public string JustifyRejection(Type type) {
|
---|
45 | return "type does not implement interface IGeometry";
|
---|
46 | }
|
---|
47 |
|
---|
48 | public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
|
---|
49 | return new WKBReader().Read((byte[]) metaInfo.First().Value);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public IEnumerable<Tag> CreateMetaInfo(object obj) {
|
---|
53 | var g = obj as IGeometry;
|
---|
54 | return new[] {new Tag("WKB", new WKBWriter().Write(g))};
|
---|
55 | }
|
---|
56 |
|
---|
57 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
58 | // object was fully decomposed in CreateMetaInfo
|
---|
59 | return new Tag[0];
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | public void Populate(object instance, IEnumerable<Tag> tags, Type type) {
|
---|
64 | // object was fully populated in CreateInstance
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | #endregion
|
---|
69 | }
|
---|
70 | }
|
---|