From a1fc8a03ef5d4d60ffc170b13513656da868c7c0 Mon Sep 17 00:00:00 2001 From: filip Date: Wed, 27 May 2015 10:37:29 +0200 Subject: [PATCH] labels for mappings --- README.textile | 6 ++--- data/3colors | 3 +++ data/3colors2 | 3 +++ src/exceptions/MissingAttributeException.java | 25 +++++++++++++++++++ src/renderers/KmlRenderer.java | 21 ++++++++++------ src/settings/KmlRendererSettings.java | 8 +++--- 6 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 data/3colors create mode 100644 data/3colors2 create mode 100644 src/exceptions/MissingAttributeException.java diff --git a/README.textile b/README.textile index 902773b..9ea82fc 100644 --- a/README.textile +++ b/README.textile @@ -61,8 +61,6 @@ h4. LINES # map line colors to duration attribute values, use supplied color sheet (RGB or RGBA values). Duration attribute applies to a whole branch and colors are not interpolated to reflect that: -render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping duration -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -output test.kml --render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping host -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -output test.kml - # specify alpha channel for lines, this option overwrites all previous settings, including those in color sheet: -render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping host -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -linealpha 150 -output test.kml @@ -79,10 +77,10 @@ h4. LINES -render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping host -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -linealphamapping host -linewidthmapping duration -output test.kml # override default line altitude settings: --render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping host -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -linealphamapping host -linewidth 2 -linealtitude 5000 -output test.kml +-render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping host -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -linealphamapping host -linewidth 2 -linealtitude 50000 -output test.kml # map lines altitude to distance attribute values. Altitude can only be mapped to attributes which apply to a whole branch. --render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping host -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -linealphamapping host -linewidth 2 -linealtitudemapping distance -output test.kml +-render -json /home/filip/Dropbox/JavaProjects/Spread2/test_host.json -polygoncolormapping host -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors2 -polygonalphamapping modality -linecolormapping host -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/3colors -linealphamapping host -linewidthmapping duration -linealtitudemapping distance -output test.kml h3. DISCRETE TREE diff --git a/data/3colors b/data/3colors new file mode 100644 index 0000000..e29594b --- /dev/null +++ b/data/3colors @@ -0,0 +1,3 @@ +Gal 255 0 0 +Ans 255 128 0 +Neo 255 255 0 diff --git a/data/3colors2 b/data/3colors2 new file mode 100644 index 0000000..0302ee9 --- /dev/null +++ b/data/3colors2 @@ -0,0 +1,3 @@ +Gal 0 255 100 100 +Ans 0 128 255 100 +Neo 0 0 255 100 diff --git a/src/exceptions/MissingAttributeException.java b/src/exceptions/MissingAttributeException.java new file mode 100644 index 0000000..a133514 --- /dev/null +++ b/src/exceptions/MissingAttributeException.java @@ -0,0 +1,25 @@ +package exceptions; + +@SuppressWarnings("serial") +public class MissingAttributeException extends Exception { + + public static final String LINE = "line"; + public static final String POLYGON = "polygon"; + + private String attributeName; + private String name; + + public MissingAttributeException(String attributeName, String name) { + + this.attributeName = attributeName; + this.name = name; + + }//END: Constructor + + @Override + public String getMessage() { + String message = "Attribute " + attributeName + " missing from " + name +" attributes"; + return message; + } + +}//END: class diff --git a/src/renderers/KmlRenderer.java b/src/renderers/KmlRenderer.java index 09ba485..3e769ee 100644 --- a/src/renderers/KmlRenderer.java +++ b/src/renderers/KmlRenderer.java @@ -243,7 +243,6 @@ private Feature generateLine( } Object startKey = startTrait.isNumber() ? startTrait.getValue()[0] : (String) startTrait.getId(); - if (lineColorMap.containsKey(startKey)) { // read the supplied color map, or re-use already mapped values @@ -283,7 +282,6 @@ private Feature generateLine( } Object endKey = endTrait.isNumber() ? endTrait.getValue()[0] : (String) endTrait.getId(); - if (lineColorMap.containsKey(endKey)) { endColor = lineColorMap.get(endKey); @@ -304,7 +302,7 @@ private Feature generateLine( }// END: endkey check - label += (", "+settings.lineColorMapping + "="+startKey.toString().concat(" to ").concat(endKey.toString())); + label += ( "color[" + settings.lineColorMapping + "=" + startKey.toString() + " to " + endKey.toString() +"]" ); } else { // use defaults or user defined color @@ -336,7 +334,6 @@ private Feature generateLine( } Object startKey = startTrait.isNumber() ? startTrait.getValue()[0] : (String) startTrait.getId(); - if (lineAlphaMap.containsKey(startKey)) { startAlpha = lineAlphaMap.get(startKey); @@ -361,7 +358,6 @@ private Feature generateLine( } Object endKey = endTrait.isNumber() ? endTrait.getValue()[0] : (String) endTrait.getId(); - if (lineAlphaMap.containsKey(endKey)) { endAlpha = lineAlphaMap.get(endKey); @@ -375,7 +371,12 @@ private Feature generateLine( }// END: endkey check - label += (", "+settings.lineAlphaMapping + "="+startKey.toString().concat(" to ").concat(endKey.toString())); + label += (", alpha[" + settings.lineAlphaMapping + "=" + startKey.toString() + " to " + endKey.toString() + "]"); + + } else { // use defaults + + startAlpha = (int) settings.lineAlpha; + endAlpha = startAlpha; } // END: settings check @@ -416,6 +417,8 @@ private Feature generateLine( }// END: key check + label += (", altitude[" + settings.lineAltitudeMapping + "=" + key.toString() +"]"); + } else { // use defaults or user defined color altitude = settings.lineAltitude; @@ -450,6 +453,8 @@ private Feature generateLine( }// END: key check + label += (", width[" + settings.lineWidthMapping + "=" + key.toString() +"]"); + } else { // use defaults or user defined color width = settings.lineWidth; @@ -631,7 +636,7 @@ private Feature generatePolygons(List polygons) throws IOException, Mis }// END: key check - label = settings.polygonColorMapping + "=" + key.toString(); + label = "color[" + settings.polygonColorMapping + "=" + key.toString() +"]"; } else {// use defaults or user defined color @@ -665,7 +670,7 @@ private Feature generatePolygons(List polygons) throws IOException, Mis }// END: key check - label += (", "+settings.polygonAlphaMapping + "="+key.toString()); + label += (", alpha[" + settings.polygonAlphaMapping + "="+key.toString()+"]"); } // END: settings check diff --git a/src/settings/KmlRendererSettings.java b/src/settings/KmlRendererSettings.java index 171e7b6..820d75e 100644 --- a/src/settings/KmlRendererSettings.java +++ b/src/settings/KmlRendererSettings.java @@ -35,10 +35,10 @@ public class KmlRendererSettings { // For continuous attributes public String lineAlphaMapping; - public Double minLineAlpha = 50.0; public Double maxLineAlpha = 100.0; + public Double minLineAlpha = 100.0; public Double maxLineAlpha = 150.0; // Fixed - public double lineAlpha = 100; + public double lineAlpha = 255; public boolean lineAlphaChanged = false; @@ -47,7 +47,7 @@ public class KmlRendererSettings { // For continuous attributes public String lineAltitudeMapping = null; - public Double minLineAltitude = 500.0; public Double maxLineAltitude = 500000.0; + public Double minLineAltitude = 50000.0; public Double maxLineAltitude = 500000.0; // Fixed public Double lineAltitude = 500000.0; @@ -56,7 +56,7 @@ public class KmlRendererSettings { // For continuous attributes public String lineWidthMapping = null; - public Double minLineWidth = 1.0; public Double maxLineWidth = 10.0; + public Double minLineWidth = 2.0; public Double maxLineWidth = 10.0; // Fixed public Double lineWidth = 2.0;