comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 5655:53a2ceeae9a3

Create floodmap colorrange dynamically from artifact parameters. Theme setting for colorrange classes is currently not functioning (wasn't before either).
author Christian Lins <christian.lins@intevation.de>
date Thu, 11 Apr 2013 11:25:41 +0200
parents dc0d37715e16
children
comparison
equal deleted inserted replaced
5654:c5854dc8d6a1 5655:53a2ceeae9a3
658 * This method uses a start- and endcolor to interpolate a 658 * This method uses a start- and endcolor to interpolate a
659 * given number of color classes for the MapserverStyle. 659 * given number of color classes for the MapserverStyle.
660 * @param theme 660 * @param theme
661 * @return String representation of the MapserverStyle 661 * @return String representation of the MapserverStyle
662 */ 662 */
663 public static String createDynamicMapserverStyle(Document theme) { 663 public static String createDynamicMapserverStyle(Document theme,
664 float from, float to, float step)
665 {
664 MapserverStyle ms = new MapserverStyle(); 666 MapserverStyle ms = new MapserverStyle();
665 667
666 String strStartColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null); 668 String strStartColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null);
667 Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215); 669 Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215);
668 String strEndColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_ENDCOLOR, null); 670 String strEndColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_ENDCOLOR, null);
669 Color endColor = strEndColor != null? parseColor(strEndColor) : new Color(2, 27, 42); 671 Color endColor = strEndColor != null? parseColor(strEndColor) : new Color(2, 27, 42);
672 /*
670 String strNumClasses = XMLUtils.xpathString(theme, XPATH_WSPLGEN_NUMCLASSES, null); 673 String strNumClasses = XMLUtils.xpathString(theme, XPATH_WSPLGEN_NUMCLASSES, null);
671 int numClasses = strNumClasses != null ? Integer.parseInt(strNumClasses) : 5; 674 int numClasses;
675 if (strNumClasses != null) {
676 numClasses = Integer.parseInt(strNumClasses);
677 }
678 else {
679 numClasses = 5;
680 logger.warn("createDynamicMapserverStyle(): strNumClasses is null");
681 }
672 682
673 if (numClasses < 5) { 683 if (numClasses < 5) {
674 numClasses = 5; 684 numClasses = 5;
675 } 685 }
676 else if (numClasses > 20) { 686 else if (numClasses > 20) {
677 numClasses = 20; 687 numClasses = 20;
678 } 688 }*/
689
690
691 int numClasses = (int)((to - from) / step);
679 692
680 float rd = (endColor.getRed() - startColor.getRed()) / (float)numClasses; 693 float rd = (endColor.getRed() - startColor.getRed()) / (float)numClasses;
681 float gd = (endColor.getGreen() - startColor.getGreen()) / (float)numClasses; 694 float gd = (endColor.getGreen() - startColor.getGreen()) / (float)numClasses;
682 float bd = (endColor.getBlue() - startColor.getBlue()) / (float)numClasses; 695 float bd = (endColor.getBlue() - startColor.getBlue()) / (float)numClasses;
683 696
687 newColor.append(' '); 700 newColor.append(' ');
688 newColor.append(startColor.getGreen() + Math.round(n * gd)); 701 newColor.append(startColor.getGreen() + Math.round(n * gd));
689 newColor.append(' '); 702 newColor.append(' ');
690 newColor.append(startColor.getBlue() + Math.round(n * bd)); 703 newColor.append(startColor.getBlue() + Math.round(n * bd));
691 704
692 String expr = createWSPLGENExpression(n + 1, numClasses); 705 String expr = createWSPLGENExpression(from + n * step, step, n + 1, numClasses);
693 706
694 Clazz c = new Clazz(expr); 707 Clazz c = new Clazz(expr);
695 Style s = new Style(); 708 Style s = new Style();
696 s.setColor(newColor.toString()); 709 s.setColor(newColor.toString());
697 s.setSize(5); 710 s.setSize(5);
704 717
705 return ms.toString(); 718 return ms.toString();
706 } 719 }
707 720
708 721
709 protected static String createWSPLGENExpression(int idx, int maxIdx) { 722 protected static String createWSPLGENExpression(float val, float step, int idx, int maxIdx) {
710 if (idx < maxIdx) { 723 if (idx < maxIdx) {
711 int lower = idx - 1; 724 return "[DIFF] >= " + val + " AND [DIFF] < " + (val + step);
712 return "[DIFF] >= " + lower + " AND [DIFF] < " + idx;
713 } 725 }
714 else { 726 else {
715 return "[DIFF] >= " + (maxIdx - 1); 727 return "[DIFF] >= " + val;
716 } 728 }
717 } 729 }
718 730
719 731
720 public static String createMapserverStyle(Document theme) { 732 public static String createMapserverStyle(Document theme) {

http://dive4elements.wald.intevation.org