Index: Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -0,0 +1,188 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Globalization;
+using System.Linq;
+using Core.Common.Base.Geometry;
+using Core.Components.Gis.Data;
+using Core.Components.Gis.Features;
+using DotSpatial.Controls;
+using DotSpatial.Data;
+using DotSpatial.Symbology;
+using DotSpatial.Topology;
+
+namespace Core.Components.DotSpatial.Converter
+{
+ ///
+ /// Abstract base class for transforming into .
+ ///
+ /// The type of map data to convert.
+ /// The type of map feature layer to set the converted data to.
+ public abstract class FeatureBasedMapDataConverter : IFeatureBasedMapDataConverter
+ where TMapData : MapData
+ where TMapFeatureLayer : IMapFeatureLayer
+ {
+ ///
+ /// Needed because DotSpatial can't handle special characters.
+ /// Therefore we create an id as column name for the data table in the featureSet.
+ /// We need this lookup to match the selected attribute from the MapData with the created id.
+ ///
+ private readonly Dictionary columnLookup;
+
+ ///
+ /// Creates a new instance of
+ ///
+ protected FeatureBasedMapDataConverter()
+ {
+ columnLookup = new Dictionary();
+ }
+
+ public bool CanConvertMapData(MapData data)
+ {
+ return data is TMapData;
+ }
+
+ public IMapFeatureLayer Convert(MapData data)
+ {
+ ValidateParameters(data);
+
+ return Convert((TMapData) data);
+ }
+
+ public void ConvertLayerFeatures(MapData data, IMapFeatureLayer layer)
+ {
+ ValidateParameters(data);
+
+ ConvertLayerFeatures((TMapData) data, (TMapFeatureLayer) layer);
+ }
+
+ public void ConvertLayerProperties(MapData data, IMapFeatureLayer layer)
+ {
+ ValidateParameters(data);
+
+ ConvertLayerProperties((TMapData) data, (TMapFeatureLayer) layer);
+ }
+
+ ///
+ /// Creates a based on the that was given.
+ ///
+ /// The data to transform into a .
+ /// A new .
+ protected abstract IMapFeatureLayer Convert(TMapData data);
+
+ ///
+ /// Converts all feature related data from to .
+ /// Any features already part of are cleared.
+ ///
+ /// The data to convert the feature related data from.
+ /// The layer to convert the feature related data to.
+ protected abstract void ConvertLayerFeatures(TMapData data, TMapFeatureLayer layer);
+
+ ///
+ /// Converts all general properties (like and )
+ /// from to .
+ ///
+ /// The data to convert the general properties from.
+ /// The layer to convert the general properties to.
+ protected abstract void ConvertLayerProperties(TMapData data, TMapFeatureLayer layer);
+
+ ///
+ /// Converts an of to an
+ /// of .
+ ///
+ /// The of to convert.
+ /// The converted of .
+ protected static IEnumerable ConvertPoint2DElementsToCoordinates(IEnumerable points)
+ {
+ return points.Select(point => new Coordinate(point.X, point.Y));
+ }
+
+ ///
+ /// Adds as attributes to the given and to the .
+ ///
+ /// The to get the meta data from.
+ /// The to add the attributes to.
+ /// The to add the attributes to.
+ protected void AddMetaDataAsAttributes(MapFeature ringtoetsMapFeature, IFeatureSet featureSet, Feature feature)
+ {
+ var columnKey = 1;
+ foreach (var attribute in ringtoetsMapFeature.MetaData)
+ {
+ string attributeName = attribute.Key;
+
+ var columnName = columnKey.ToString();
+ if (!columnLookup.ContainsKey(attributeName))
+ {
+ columnLookup.Add(attributeName, columnName);
+
+ if (!featureSet.DataTable.Columns.Contains(columnName))
+ {
+ featureSet.DataTable.Columns.Add(columnName, typeof(string));
+ }
+ }
+
+ feature.DataRow[columnName] = attribute.Value;
+ columnKey++;
+ }
+ }
+
+ ///
+ /// Gets a new .
+ ///
+ /// The to add the to.
+ /// Indicator whether to show the labels or not.
+ /// The key of the attribute to show the labels for.
+ /// A new .
+ protected MapLabelLayer GetLabelLayer(IFeatureSet featureSet, bool showLabels, string labelToShow)
+ {
+ var labelLayer = new MapLabelLayer();
+
+ if (featureSet.DataTable.Columns.Count > 0 && showLabels)
+ {
+ labelLayer.Symbology.Categories[0].Symbolizer = new LabelSymbolizer
+ {
+ Orientation = ContentAlignment.MiddleRight,
+ OffsetX = 5
+ };
+ labelLayer.Symbology.Categories[0].Expression = string.Format(CultureInfo.CurrentCulture, "[{0}]", columnLookup[labelToShow]);
+ }
+
+ return labelLayer;
+ }
+
+ private void ValidateParameters(MapData data)
+ {
+ if (data == null)
+ {
+ throw new ArgumentNullException("data", @"Null data cannot be converted into a feature layer.");
+ }
+
+ if (!CanConvertMapData(data))
+ {
+ var message = string.Format("The data of type {0} cannot be converted by this converter.", data.GetType());
+ throw new ArgumentException(message);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/src/Core.Components.DotSpatial/Converter/IFeatureBasedMapDataConverter.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/Converter/IFeatureBasedMapDataConverter.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/IFeatureBasedMapDataConverter.cs (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -0,0 +1,65 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using Core.Components.Gis.Data;
+using DotSpatial.Controls;
+
+namespace Core.Components.DotSpatial.Converter
+{
+ ///
+ /// The interface for a converter which converts into .
+ ///
+ public interface IFeatureBasedMapDataConverter
+ {
+ ///
+ /// Checks whether the can convert the .
+ ///
+ /// The to check for.
+ /// true if the can be converted by the
+ /// , false otherwise.
+ bool CanConvertMapData(MapData data);
+
+ ///
+ /// Creates a based on the that was given.
+ ///
+ /// The data to transform into a .
+ /// A new .
+ /// Thrown when returns false.
+ /// Thrown when is null.
+ IMapFeatureLayer Convert(MapData data);
+
+ ///
+ /// Converts all feature related data from to .
+ ///
+ /// The data to convert the feature related data from.
+ /// The layer to convert the feature related data to.
+ void ConvertLayerFeatures(MapData data, IMapFeatureLayer layer);
+
+ ///
+ /// Converts all general properties (like and )
+ /// from to .
+ ///
+ /// The data to convert the general properties from.
+ /// The layer to convert the general properties to.
+ void ConvertLayerProperties(MapData data, IMapFeatureLayer layer);
+ }
+}
\ No newline at end of file
Fisheye: Tag d72d28f9d51c5bc4c7bb0f49509e3656465cc22c refers to a dead (removed) revision in file `Core/Components/src/Core.Components.DotSpatial/Converter/IMapDataConverter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag d72d28f9d51c5bc4c7bb0f49509e3656465cc22c refers to a dead (removed) revision in file `Core/Components/src/Core.Components.DotSpatial/Converter/MapDataConverter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapFeatureLayerFactory.cs
===================================================================
diff -u -r0f65a6bd78c76390d84a1fe459a1de44bf7fb27c -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapFeatureLayerFactory.cs (.../MapFeatureLayerFactory.cs) (revision 0f65a6bd78c76390d84a1fe459a1de44bf7fb27c)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapFeatureLayerFactory.cs (.../MapFeatureLayerFactory.cs) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -40,14 +40,14 @@
/// Thrown when the given type is not supported.
public static IMapFeatureLayer Create(MapData data)
{
- var converters = new Collection
+ var converters = new Collection
{
new MapPointDataConverter(),
new MapLineDataConverter(),
new MapPolygonDataConverter()
};
- foreach (IMapDataConverter converter in converters.Where(c => c.CanConvertMapData(data)))
+ foreach (IFeatureBasedMapDataConverter converter in converters.Where(c => c.CanConvertMapData(data)))
{
return converter.Convert(data);
}
@@ -63,7 +63,7 @@
/// Thrown when the given type is not supported.
public static void ConvertLayerFeatures(MapData data, IMapFeatureLayer layer)
{
- var converter = GetMapDataConverter(data);
+ var converter = GetFeatureBasedMapDataConverter(data);
if (converter != null)
{
converter.ConvertLayerFeatures(data, layer);
@@ -82,7 +82,7 @@
/// The layer to convert the general properties to.
public static void ConvertLayerProperties(MapData data, IMapFeatureLayer layer)
{
- var converter = GetMapDataConverter(data);
+ var converter = GetFeatureBasedMapDataConverter(data);
if (converter != null)
{
converter.ConvertLayerProperties(data, layer);
@@ -93,9 +93,9 @@
}
}
- private static IMapDataConverter GetMapDataConverter(MapData data)
+ private static IFeatureBasedMapDataConverter GetFeatureBasedMapDataConverter(MapData data)
{
- return new Collection
+ return new Collection
{
new MapPointDataConverter(),
new MapLineDataConverter(),
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapLineDataConverter.cs
===================================================================
diff -u -rd2eecf88d4da2c824ccfa6eb81cf0a75733eccde -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapLineDataConverter.cs (.../MapLineDataConverter.cs) (revision d2eecf88d4da2c824ccfa6eb81cf0a75733eccde)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapLineDataConverter.cs (.../MapLineDataConverter.cs) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -35,7 +35,7 @@
///
/// The converter that converts into a .
///
- public class MapLineDataConverter : MapDataConverter
+ public class MapLineDataConverter : FeatureBasedMapDataConverter
{
protected override IMapFeatureLayer Convert(MapLineData data)
{
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs
===================================================================
diff -u -rd2eecf88d4da2c824ccfa6eb81cf0a75733eccde -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs (.../MapPointDataConverter.cs) (revision d2eecf88d4da2c824ccfa6eb81cf0a75733eccde)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs (.../MapPointDataConverter.cs) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -33,7 +33,7 @@
///
/// The converter that converts into a .
///
- public class MapPointDataConverter : MapDataConverter
+ public class MapPointDataConverter : FeatureBasedMapDataConverter
{
protected override IMapFeatureLayer Convert(MapPointData data)
{
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapPolygonDataConverter.cs
===================================================================
diff -u -rd2eecf88d4da2c824ccfa6eb81cf0a75733eccde -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapPolygonDataConverter.cs (.../MapPolygonDataConverter.cs) (revision d2eecf88d4da2c824ccfa6eb81cf0a75733eccde)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapPolygonDataConverter.cs (.../MapPolygonDataConverter.cs) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -33,7 +33,7 @@
///
/// The converter that converts into a .
///
- public class MapPolygonDataConverter : MapDataConverter
+ public class MapPolygonDataConverter : FeatureBasedMapDataConverter
{
protected override IMapFeatureLayer Convert(MapPolygonData data)
{
Index: Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj
===================================================================
diff -u -r675771641656abfb56ef89be86bad7bd21684016 -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision 675771641656abfb56ef89be86bad7bd21684016)
+++ Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -63,8 +63,8 @@
Properties\GlobalAssembly.cs
-
-
+
+
Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/FeatureBasedMapDataConverterTest.cs
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Test/Converter/FeatureBasedMapDataConverterTest.cs (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/FeatureBasedMapDataConverterTest.cs (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -0,0 +1,130 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using Core.Common.TestUtil;
+using Core.Components.DotSpatial.Converter;
+using Core.Components.DotSpatial.TestUtil;
+using Core.Components.Gis.Data;
+using DotSpatial.Controls;
+using NUnit.Framework;
+
+namespace Core.Components.DotSpatial.Test.Converter
+{
+ [TestFixture]
+ public class FeatureBasedMapDataConverterTest
+ {
+ [Test]
+ public void CanConvertMapData_DifferentInheritingTypes_OnlySupportsExactType()
+ {
+ // Setup
+ var testConverter = new TestFeatureBasedMapDataConverter();
+
+ // Call
+ var mapDataResult = testConverter.CanConvertMapData(new TestMapData("test data"));
+ var classResult = testConverter.CanConvertMapData(new Class("test data"));
+ var childResult = testConverter.CanConvertMapData(new Child("test data"));
+
+ // Assert
+ Assert.IsFalse(mapDataResult);
+ Assert.IsTrue(classResult);
+ Assert.IsTrue(childResult);
+ }
+
+ [Test]
+ public void Convert_DataNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var testConverter = new TestFeatureBasedMapDataConverter();
+
+ // Call
+ TestDelegate test = () => testConverter.Convert(null);
+
+ // Assert
+ const string expectedMessage = "Null data cannot be converted into a feature layer.";
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage);
+ }
+
+ [Test]
+ public void Convert_DataCannotBeConverted_ThrowsArgumentException()
+ {
+ // Setup
+ var testConverter = new TestFeatureBasedMapDataConverter();
+ var testMapData = new TestMapData("test data");
+
+ // Precondition
+ Assert.IsFalse(testConverter.CanConvertMapData(testMapData));
+
+ // Call
+ TestDelegate test = () => testConverter.Convert(testMapData);
+
+ // Assert
+ var expectedMessage = string.Format("The data of type {0} cannot be converted by this converter.", testMapData.GetType());
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage);
+ }
+
+ [Test]
+ public void Convert_DataCanBeConverted_ReturnsResult()
+ {
+ // Setup
+ var testConverter = new TestFeatureBasedMapDataConverter();
+ var testMapData = new TestMapData("test data");
+
+ // Precondition
+ Assert.IsTrue(testConverter.CanConvertMapData(testMapData));
+
+ // Call
+ var result = testConverter.Convert(testMapData);
+
+ // Assert
+ Assert.IsNotNull(result);
+ }
+
+ private class Class : MapData
+ {
+ public Class(string name) : base(name) {}
+ }
+
+ private class Child : Class
+ {
+ public Child(string name) : base(name) {}
+ }
+
+ private class TestFeatureBasedMapDataConverter : FeatureBasedMapDataConverter
+ where TMapData : MapData
+ {
+ protected override void ConvertLayerFeatures(TMapData data, MapPointLayer layer)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override void ConvertLayerProperties(TMapData data, MapPointLayer layer)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override IMapFeatureLayer Convert(TMapData data)
+ {
+ return new MapPointLayer();
+ }
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag d72d28f9d51c5bc4c7bb0f49509e3656465cc22c refers to a dead (removed) revision in file `Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapDataConverterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs
===================================================================
diff -u -ra47c2cb4b8278ff844e007477b0510a4d1a4956a -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs (.../MapLineDataConverterTest.cs) (revision a47c2cb4b8278ff844e007477b0510a4d1a4956a)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs (.../MapLineDataConverterTest.cs) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -52,7 +52,7 @@
var converter = new MapLineDataConverter();
// Assert
- Assert.IsInstanceOf>(converter);
+ Assert.IsInstanceOf>(converter);
}
[Test]
Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPointDataConverterTest.cs
===================================================================
diff -u -ra47c2cb4b8278ff844e007477b0510a4d1a4956a -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPointDataConverterTest.cs (.../MapPointDataConverterTest.cs) (revision a47c2cb4b8278ff844e007477b0510a4d1a4956a)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPointDataConverterTest.cs (.../MapPointDataConverterTest.cs) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -51,7 +51,7 @@
var converter = new MapPointDataConverter();
// Assert
- Assert.IsInstanceOf>(converter);
+ Assert.IsInstanceOf>(converter);
}
[Test]
Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPolygonDataConverterTest.cs
===================================================================
diff -u -ra47c2cb4b8278ff844e007477b0510a4d1a4956a -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPolygonDataConverterTest.cs (.../MapPolygonDataConverterTest.cs) (revision a47c2cb4b8278ff844e007477b0510a4d1a4956a)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPolygonDataConverterTest.cs (.../MapPolygonDataConverterTest.cs) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -51,7 +51,7 @@
var converter = new MapPolygonDataConverter();
// Assert
- Assert.IsInstanceOf>(converter);
+ Assert.IsInstanceOf>(converter);
}
[Test]
Index: Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj
===================================================================
diff -u -r675771641656abfb56ef89be86bad7bd21684016 -rd72d28f9d51c5bc4c7bb0f49509e3656465cc22c
--- Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision 675771641656abfb56ef89be86bad7bd21684016)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision d72d28f9d51c5bc4c7bb0f49509e3656465cc22c)
@@ -81,7 +81,7 @@
-
+