Index: Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs
===================================================================
diff -u -r43485bbd567a6a27eda933073b73086073fe7456 -rcfc35ba7d39c3a60b269f75e3c05a67d659de799
--- Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (.../FeatureBasedMapDataConverter.cs) (revision 43485bbd567a6a27eda933073b73086073fe7456)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (.../FeatureBasedMapDataConverter.cs) (revision cfc35ba7d39c3a60b269f75e3c05a67d659de799)
@@ -41,9 +41,11 @@
///
/// The type of feature based map data to convert.
/// The type of map feature layer to set the converted data to.
- public abstract class FeatureBasedMapDataConverter
- where TFeatureBasedMapData : FeatureBasedMapData
+ /// The type of category theme.
+ public abstract class FeatureBasedMapDataConverter
+ where TFeatureBasedMapData : FeatureBasedMapData
where TMapFeatureLayer : FeatureLayer, IMapFeatureLayer
+ where TCategoryTheme : CategoryTheme
{
///
/// Converts all feature related data from to .
@@ -102,7 +104,7 @@
layer.ShowLabels = data.ShowLabels;
((IMapFeatureLayer) layer).LabelLayer = GetLabelLayer(GetAttributeMapping(data), layer.DataSet, data.SelectedMetaDataAttribute);
- if (HasMapTheme(data))
+ if (data.Theme != null)
{
layer.Symbology = CreateCategoryScheme(data);
}
@@ -149,64 +151,46 @@
}
///
- /// Determines if the has a categorical theming to be applied
- /// on the data it contains
+ /// Creates the based on the type of map data.
///
- /// The map data to determine if it has categorical theming.
- /// true if the has categorical theming, false otherwise.
- protected abstract bool HasMapTheme(TFeatureBasedMapData mapData);
+ /// A configured based on the type of map data.
+ /// null should never be returned as this will break DotSpatial.
+ protected abstract IFeatureScheme CreateScheme();
///
- /// Creates the based on the categorical theming of .
+ /// Creates the based on the type of category theme.
///
- /// The map data to create the categorical theming for.
- /// A configured based on the map data theme.
+ /// The type of category theme to create a for.
+ /// A based on .
/// null should never be returned as this will break DotSpatial.
- /// Thrown when the
- /// could not be successfully converted to a scheme.
- protected abstract IFeatureScheme CreateCategoryScheme(TFeatureBasedMapData mapData);
+ protected abstract IFeatureCategory CreateFeatureCategory(TCategoryTheme categoryTheme);
- ///
- /// Gets the mapping between map data attribute names and DotSpatial attribute names.
- ///
- /// The map data to get the mappings from.
- /// The mapping between map data attribute names and DotSpatial attribute names.
- ///
- /// This method is used for obtaining a mapping between map data attribute names and DotSpatial
- /// attribute names. This mapping is needed because DotSpatial can't handle special characters.
- ///
- protected static Dictionary GetAttributeMapping(TFeatureBasedMapData data)
+ private IFeatureScheme CreateCategoryScheme(TFeatureBasedMapData mapData)
{
- return Enumerable.Range(0, data.MetaData.Count())
- .ToDictionary(md => data.MetaData.ElementAt(md), mdi => mdi + 1);
- }
+ IFeatureScheme scheme = CreateScheme();
+ scheme.ClearCategories();
+ scheme.AddCategory(CreateDefaultCategory(mapData));
- ///
- /// Creates a filter expression based for an attribute and the criteria to apply.
- ///
- /// The index of the attribute in the metadata table.
- /// The criterion to convert to an expression.
- /// The filter expression based on the
- /// and .
- /// Thrown when the
- /// cannot be used to create a filter expression.
- protected static string CreateFilterExpression(int attributeIndex, ValueCriterion criterion)
- {
- ValueCriterionOperator valueOperator = criterion.ValueOperator;
- switch (valueOperator)
+ MapTheme mapTheme = mapData.Theme;
+ Dictionary attributeMapping = GetAttributeMapping(mapData);
+ if (attributeMapping.ContainsKey(mapTheme.AttributeName))
{
- case ValueCriterionOperator.EqualValue:
- return $"[{attributeIndex}] = '{criterion.Value}'";
- case ValueCriterionOperator.UnequalValue:
- return $"NOT [{attributeIndex}] = '{criterion.Value}'";
- default:
- throw new NotSupportedException();
+ int attributeIndex = attributeMapping[mapTheme.AttributeName];
+
+ foreach (TCategoryTheme categoryTheme in mapTheme.CategoryThemes)
+ {
+ IFeatureCategory category = CreateFeatureCategory(categoryTheme);
+ category.FilterExpression = CreateFilterExpression(attributeIndex, categoryTheme.Criterion);
+ scheme.AddCategory(category);
+ }
}
+
+ return scheme;
}
private void ClearFeatureScheme(TFeatureBasedMapData mapData, IScheme scheme)
{
- if (HasMapTheme(mapData))
+ if (mapData.Theme != null)
{
scheme.ClearCategories();
scheme.AddCategory(CreateDefaultCategory(mapData));
@@ -258,6 +242,16 @@
}
}
+ ///
+ /// This method is used for obtaining a mapping between map data attribute names and DotSpatial
+ /// attribute names. This mapping is needed because DotSpatial can't handle special characters.
+ ///
+ private static Dictionary GetAttributeMapping(TFeatureBasedMapData data)
+ {
+ return Enumerable.Range(0, data.MetaData.Count())
+ .ToDictionary(md => data.MetaData.ElementAt(md), mdi => mdi + 1);
+ }
+
private static MapLabelLayer GetLabelLayer(IDictionary attributeMapping, IFeatureSet featureSet, string labelToShow)
{
var labelLayer = new MapLabelLayer();
@@ -276,5 +270,28 @@
return labelLayer;
}
+
+ ///
+ /// Creates a filter expression based for an attribute and the criteria to apply.
+ ///
+ /// The index of the attribute in the metadata table.
+ /// The criterion to convert to an expression.
+ /// The filter expression based on the
+ /// and .
+ /// Thrown when the
+ /// cannot be used to create a filter expression.
+ private static string CreateFilterExpression(int attributeIndex, ValueCriterion criterion)
+ {
+ ValueCriterionOperator valueOperator = criterion.ValueOperator;
+ switch (valueOperator)
+ {
+ case ValueCriterionOperator.EqualValue:
+ return $"[{attributeIndex}] = '{criterion.Value}'";
+ case ValueCriterionOperator.UnequalValue:
+ return $"NOT [{attributeIndex}] = '{criterion.Value}'";
+ default:
+ throw new NotSupportedException();
+ }
+ }
}
}
\ No newline at end of file
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapLineDataConverter.cs
===================================================================
diff -u -r35f8077602c4054df008af5ae79d7b2d33d32011 -rcfc35ba7d39c3a60b269f75e3c05a67d659de799
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapLineDataConverter.cs (.../MapLineDataConverter.cs) (revision 35f8077602c4054df008af5ae79d7b2d33d32011)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapLineDataConverter.cs (.../MapLineDataConverter.cs) (revision cfc35ba7d39c3a60b269f75e3c05a67d659de799)
@@ -37,7 +37,7 @@
///
/// The converter that converts data into data.
///
- public class MapLineDataConverter : FeatureBasedMapDataConverter
+ public class MapLineDataConverter : FeatureBasedMapDataConverter
{
protected override IEnumerable CreateFeatures(MapFeature mapFeature)
{
@@ -53,38 +53,19 @@
LineCap.Round);
}
- protected override IFeatureCategory CreateDefaultCategory(MapLineData mapData)
+ protected override IFeatureScheme CreateScheme()
{
- return CreateCategory(mapData.Style);
+ return new LineScheme();
}
- protected override bool HasMapTheme(MapLineData mapData)
+ protected override IFeatureCategory CreateFeatureCategory(LineCategoryTheme categoryTheme)
{
- return mapData.Theme != null;
+ return CreateCategory(categoryTheme.Style);
}
- protected override IFeatureScheme CreateCategoryScheme(MapLineData mapData)
+ protected override IFeatureCategory CreateDefaultCategory(MapLineData mapData)
{
- var scheme = new LineScheme();
- scheme.ClearCategories();
- scheme.AddCategory(CreateCategory(mapData.Style));
-
- MapTheme mapTheme = mapData.Theme;
- Dictionary attributeMapping = GetAttributeMapping(mapData);
-
- if (attributeMapping.ContainsKey(mapTheme.AttributeName))
- {
- int attributeIndex = attributeMapping[mapTheme.AttributeName];
-
- foreach (LineCategoryTheme categoryTheme in mapTheme.CategoryThemes)
- {
- IFeatureCategory category = CreateCategory(categoryTheme.Style);
- category.FilterExpression = CreateFilterExpression(attributeIndex, categoryTheme.Criterion);
- scheme.AddCategory(category);
- }
- }
-
- return scheme;
+ return CreateCategory(mapData.Style);
}
private static IFeatureCategory CreateCategory(LineStyle style)
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs
===================================================================
diff -u -r35f8077602c4054df008af5ae79d7b2d33d32011 -rcfc35ba7d39c3a60b269f75e3c05a67d659de799
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs (.../MapPointDataConverter.cs) (revision 35f8077602c4054df008af5ae79d7b2d33d32011)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs (.../MapPointDataConverter.cs) (revision cfc35ba7d39c3a60b269f75e3c05a67d659de799)
@@ -35,7 +35,7 @@
///
/// The converter that converts data into data.
///
- public class MapPointDataConverter : FeatureBasedMapDataConverter
+ public class MapPointDataConverter : FeatureBasedMapDataConverter
{
protected override IEnumerable CreateFeatures(MapFeature mapFeature)
{
@@ -52,33 +52,14 @@
return CreateCategory(mapData.Style);
}
- protected override bool HasMapTheme(MapPointData mapData)
+ protected override IFeatureScheme CreateScheme()
{
- return mapData.Theme != null;
+ return new PointScheme();
}
- protected override IFeatureScheme CreateCategoryScheme(MapPointData mapData)
+ protected override IFeatureCategory CreateFeatureCategory(PointCategoryTheme categoryTheme)
{
- var scheme = new PointScheme();
- scheme.ClearCategories();
- scheme.AddCategory(CreateCategory(mapData.Style));
-
- MapTheme mapTheme = mapData.Theme;
- Dictionary attributeMapping = GetAttributeMapping(mapData);
-
- if (attributeMapping.ContainsKey(mapTheme.AttributeName))
- {
- int attributeIndex = attributeMapping[mapTheme.AttributeName];
-
- foreach (PointCategoryTheme categoryTheme in mapTheme.CategoryThemes)
- {
- IFeatureCategory category = CreateCategory(categoryTheme.Style);
- category.FilterExpression = CreateFilterExpression(attributeIndex, categoryTheme.Criterion);
- scheme.AddCategory(category);
- }
- }
-
- return scheme;
+ return CreateCategory(categoryTheme.Style);
}
private static IFeatureCategory CreateCategory(PointStyle pointStyle)
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapPolygonDataConverter.cs
===================================================================
diff -u -r35f8077602c4054df008af5ae79d7b2d33d32011 -rcfc35ba7d39c3a60b269f75e3c05a67d659de799
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapPolygonDataConverter.cs (.../MapPolygonDataConverter.cs) (revision 35f8077602c4054df008af5ae79d7b2d33d32011)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapPolygonDataConverter.cs (.../MapPolygonDataConverter.cs) (revision cfc35ba7d39c3a60b269f75e3c05a67d659de799)
@@ -38,7 +38,7 @@
///
/// The converter that converts data into data.
///
- public class MapPolygonDataConverter : FeatureBasedMapDataConverter
+ public class MapPolygonDataConverter : FeatureBasedMapDataConverter
{
protected override IEnumerable CreateFeatures(MapFeature mapFeature)
{
@@ -67,48 +67,27 @@
protected override IFeatureSymbolizer CreateSymbolizer(MapPolygonData mapData)
{
- return new PolygonSymbolizer(mapData.Style.FillColor, GetStrokeColor(mapData.Style), mapData.Style.StrokeThickness);
+ PolygonStyle polygonStyle = mapData.Style;
+ return new PolygonSymbolizer(polygonStyle.FillColor,
+ GetStrokeColor(polygonStyle),
+ polygonStyle.StrokeThickness);
}
- protected override IFeatureCategory CreateDefaultCategory(MapPolygonData mapData)
+ protected override IFeatureScheme CreateScheme()
{
- return CreateCategory(mapData.Style);
+ return new PolygonScheme();
}
- protected override bool HasMapTheme(MapPolygonData mapData)
+ protected override IFeatureCategory CreateFeatureCategory(PolygonCategoryTheme categoryTheme)
{
- return mapData.Theme != null;
+ return CreateCategory(categoryTheme.Style);
}
- protected override IFeatureScheme CreateCategoryScheme(MapPolygonData mapData)
+ protected override IFeatureCategory CreateDefaultCategory(MapPolygonData mapData)
{
- var scheme = new PolygonScheme();
- scheme.ClearCategories();
- scheme.AddCategory(CreateCategory(mapData.Style));
-
- MapTheme mapTheme = mapData.Theme;
- Dictionary attributeMapping = GetAttributeMapping(mapData);
-
- if (attributeMapping.ContainsKey(mapTheme.AttributeName))
- {
- int attributeIndex = attributeMapping[mapTheme.AttributeName];
-
- foreach (PolygonCategoryTheme categoryTheme in mapTheme.CategoryThemes)
- {
- IFeatureCategory category = CreateCategory(categoryTheme.Style);
- category.FilterExpression = CreateFilterExpression(attributeIndex, categoryTheme.Criterion);
- scheme.AddCategory(category);
- }
- }
-
- return scheme;
+ return CreateCategory(mapData.Style);
}
- private static IFeatureCategory CreateCategory(PolygonStyle style)
- {
- return new PolygonCategory(style.FillColor, GetStrokeColor(style), style.StrokeThickness);
- }
-
private static Color GetStrokeColor(PolygonStyle style)
{
Color strokeColor = style.StrokeColor;
@@ -120,6 +99,11 @@
return strokeColor;
}
+ private IFeatureCategory CreateCategory(PolygonStyle style)
+ {
+ return new PolygonCategory(style.FillColor, GetStrokeColor(style), style.StrokeThickness);
+ }
+
private static IBasicGeometry GetGeometry(List geometryList)
{
IBasicGeometry geometry;