Mercurial > dive4elements > river
changeset 2616:27cc95e65f18
Defined a style for WSPLGEN layers which are now modifiable.
flys-artifacts/trunk@4200 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 05 Apr 2012 07:21:58 +0000 |
parents | b0597a63fe70 |
children | 71086a3a1c5f |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java |
diffstat | 6 files changed, 126 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Apr 05 07:21:58 2012 +0000 @@ -1,3 +1,19 @@ +2012-04-05 Ingo Weinzierl <ingo@intevation.de> + + * doc/conf/themes.xml: Defined a theme for WSPLGEN layers. + + * src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java: + Made style creation more robust against nullpointers and added an + Expression class. + + * src/main/java/de/intevation/flys/utils/ThemeUtil.java: Added a static + method createWSPLGENStyle() and some helpers to create a WSPLGEN style. + + * src/main/java/de/intevation/flys/exports/MapGenerator.java, + src/main/java/de/intevation/flys/utils/MapfileGenerator.java: Methods + for creating the WSPLGEN layer now take a style document. + + 2012-04-04 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java:
--- a/flys-artifacts/doc/conf/themes.xml Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/doc/conf/themes.xml Thu Apr 05 07:21:58 2012 +0000 @@ -840,6 +840,16 @@ <!-- MAP relevant themes --> + <theme name="WSPLGEN"> + <fields> + <field name="wsplgen_cat1" type="Color" display="Hintergrund" default="178, 201, 215"/> + <field name="wsplgen_cat2" type="Color" display="Hintergrund" default="111, 147, 170"/> + <field name="wsplgen_cat3" type="Color" display="Hintergrund" default="66, 111, 139"/> + <field name="wsplgen_cat4" type="Color" display="Hintergrund" default="33, 79, 108"/> + <field name="wsplgen_cat5" type="Color" display="Hintergrund" default="2, 27, 42"/> + </fields> + </theme> + <theme name="RiverAxis"> <fields> <field name="linecolor" type="Color" display="Linienfarbe" default="0, 0, 205"/> @@ -1002,6 +1012,7 @@ <mapping from="mainvalues.w" to="ComputedDischargeCurveW"/> <mapping from="longitudinal_section.annotations" to="Annotations"/> <mapping from="w_differences" to="Differences"/> + <mapping from="floodmap.wsplgen" to="WSPLGEN"/> <mapping from="floodmap.riveraxis" to="RiverAxis"/> <mapping from="floodmap.kms" to="Kms"/> <mapping from="floodmap.qps" to="Qps"/>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java Thu Apr 05 07:21:58 2012 +0000 @@ -31,7 +31,7 @@ item.toString(sb); } - sb.append("END"); + sb.append("END\n"); return sb.toString(); } @@ -68,7 +68,10 @@ public void toString(StringBuilder sb) { sb.append("STYLE\n"); sb.append("WIDTH " + String.valueOf(size) + "\n"); - sb.append("OUTLINECOLOR " + outlinecolor + "\n"); + + if (outlinecolor != null) { + sb.append("OUTLINECOLOR " + outlinecolor + "\n"); + } if (color != null) { sb.append("COLOR " + color + "\n"); @@ -108,6 +111,20 @@ } } + public static class Expression implements ClazzItem { + protected String value; + + public Expression(String value) { + this.value = value; + } + + @Override + public void toString(StringBuilder sb) { + sb.append("EXPRESSION " + value); + sb.append("\n"); + } + } + protected List<Clazz> classes;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Thu Apr 05 07:21:58 2012 +0000 @@ -104,7 +104,7 @@ if (FLOODMAP_WSPLGEN.equals(name)) { setInitialExtent(extent); - createWSPLGENLayer(flys, wms); + createWSPLGENLayer(flys, wms, attr); } else if (FLOODMAP_BARRIERS.equals(name)) { createBarriersLayer(flys, wms); @@ -119,10 +119,17 @@ } - protected void createWSPLGENLayer(FLYSArtifact flys, WMSLayerFacet wms) { + protected void createWSPLGENLayer( + FLYSArtifact flys, + WMSLayerFacet wms, + Document attr + ) { try { MapfileGenerator mfg = MapfileGenerator.getInstance(); - mfg.createUeskLayer(flys, wms); + mfg.createUeskLayer( + flys, + wms, + ThemeUtil.createWSPLGENStyle(attr)); } catch (IOException ioe) { logger.error(ioe, ioe);
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Thu Apr 05 07:21:58 2012 +0000 @@ -364,8 +364,11 @@ * @param flys The FLYSArtifact that owns <i>wms</i>. * @param wms The WMSLayerFacet that contains information for the layer. */ - public void createUeskLayer(FLYSArtifact flys, WMSLayerFacet wms) - throws FileNotFoundException, IOException + public void createUeskLayer( + FLYSArtifact flys, + WMSLayerFacet wms, + String style + ) throws FileNotFoundException, IOException { logger.debug("createUeskLayer"); @@ -375,6 +378,7 @@ layerinfo.setDirectory(flys.identifier()); layerinfo.setData(WSPLGEN_RESULT_SHAPE); layerinfo.setTitle("I18N_WSPLGEN_RESULT"); + layerinfo.setStyle(style); String name = MS_LAYER_PREFIX + wms.getName();
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed Apr 04 18:30:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Thu Apr 05 07:21:58 2012 +0000 @@ -5,12 +5,17 @@ import java.awt.Color; import java.awt.Font; +import javax.xml.xpath.XPathConstants; + import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.model.MapserverStyle; import de.intevation.flys.artifacts.model.MapserverStyle.Clazz; +import de.intevation.flys.artifacts.model.MapserverStyle.Expression; import de.intevation.flys.artifacts.model.MapserverStyle.Style; import de.intevation.flys.artifacts.model.MapserverStyle.Label; @@ -80,6 +85,9 @@ public final static String XPATH_SHOW_MAXIMUM = "/theme/field[@name='showmaximum']/@default"; + public final static String XPATH_WSPLGEN_FIELDS = + "/theme[@name='WSPLGEN']/field"; + /** Parse string to be boolean with default if empty or unrecognized. */ public static boolean parseBoolean(String value, boolean defaultsTo) { @@ -404,6 +412,62 @@ } + public static String createWSPLGENStyle(Document theme) { + NodeList categories = (NodeList) XMLUtils.xpath( + theme, + XPATH_WSPLGEN_FIELDS, + XPathConstants.NODESET); + + return createWSPLGENStyle(categories).toString(); + } + + protected static MapserverStyle createWSPLGENStyle(NodeList categories) { + MapserverStyle ms = new MapserverStyle(); + + for (int i = 0, n = categories.getLength(); i < n; i++) { + Element cat = (Element) categories.item(i); + String color = cat.getAttribute("default"); + String name = cat.getAttribute("name"); + + String expr; + + try { + int length = name.length(); + int idx = Integer.valueOf(name.substring(length-1, length)); + + expr = createWSPLGENExpression(idx); + } + catch (NumberFormatException nfe) { + logger.warn("Error while parsing WSPLGEN category.", nfe); + continue; + } + + Clazz c = new Clazz(expr); + Style s = new Style(); + s.setColor(color.replace(",", "")); + s.setSize(5); + + c.addItem(new Expression("(" + expr + ")")); + c.addItem(s); + + ms.addClazz(c); + } + + return ms; + } + + + protected static String createWSPLGENExpression(int idx) { + if (idx < 5) { + int lower = idx - 1; + return "[DIFF] >= " + lower + " AND [DIFF] < " + idx; + } + else { + return "[DIFF] >= 4"; + } + } + + public static String createMapserverStyle(Document theme) { String symbol = getSymbol(theme); String backcolor = getBackgroundColorString(theme);