Mercurial > mxd2map
changeset 145:b2c5a66022f1
Exception handling for number conversions in writer modules.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 27 Jun 2011 18:22:21 +0200 |
parents | ad3f540fd1c3 |
children | e4a8c39985d7 03daf386f19a |
files | ChangeLog src/java/de/intevation/mxd/writer/FillStyleWriter.java src/java/de/intevation/mxd/writer/LineStyleWriter.java src/java/de/intevation/mxd/writer/MapScriptWriter.java src/java/de/intevation/mxd/writer/MarkerStyleWriter.java src/java/de/intevation/mxd/writer/SymbolWriter.java |
diffstat | 6 files changed, 146 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Jun 27 17:22:52 2011 +0200 +++ b/ChangeLog Mon Jun 27 18:22:21 2011 +0200 @@ -1,3 +1,12 @@ +2011-06-27 Raimund Renkert <raimund.renkert@intevation.de> + + * src/java/de/intevation/mxd/writer/FillStyleWriter.java, + src/java/de/intevation/mxd/writer/LineStyleWriter.java, + src/java/de/intevation/mxd/writer/MapScriptWriter.java, + src/java/de/intevation/mxd/writer/MarkerStyleWriter.java, + src/java/de/intevation/mxd/writer/SymbolWriter.java: + Exception handling for number conversions in writer modules. + 2011-06-27 Raimund Renkert <raimund.renkert@intevation.de> * src/java/de/intevation/mxd/writer/CartoLineSymbolReader.java:
--- a/src/java/de/intevation/mxd/writer/FillStyleWriter.java Mon Jun 27 17:22:52 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/FillStyleWriter.java Mon Jun 27 18:22:21 2011 +0200 @@ -69,8 +69,13 @@ (i == 1 && type.equals("marker"))) { double gap = 0; if(symbolElement.hasAttribute("xseparation")) { - gap = Double.parseDouble( - symbolElement.getAttribute("xseparation")); + try { + gap = Double.parseDouble( + symbolElement.getAttribute("xseparation")); + } + catch(NumberFormatException nfe) { + gap = 0; + } } writeMarker(nextSym, gap); } @@ -104,8 +109,14 @@ oCol.getBlue(), -4); style.setOutlinecolor(outlineColor); - style.setOutlinewidth(Double.parseDouble( - symbolElement.getAttribute("outline_size"))); + try { + style.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("outline_size"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting outline width."); + style.setOutlinewidth(0.0); + } } } @@ -121,7 +132,14 @@ //write transparent outline colorObj color = new colorObj(-1, -1, -1, -4); if(symbolElement.hasAttribute("width")) { - double w = Double.parseDouble(symbolElement.getAttribute("width")); + double w = 0; + try { + w = Double.parseDouble(symbolElement.getAttribute("width")); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting outline width."); + w = 0; + } if (w < 1.0) { return; } @@ -139,8 +157,14 @@ oCol.getBlue(), -4); outline.setOutlinecolor(outlinecolor); - outline.setOutlinewidth(Double.parseDouble( - symbolElement.getAttribute("width"))); + try { + outline.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("width"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting outline width."); + outline.setOutlinewidth(0.0); + } if(symbolElement.hasAttribute("linestyle")) { String ls = symbolElement.getAttribute("linestyle"); double[] vals; @@ -177,8 +201,14 @@ String name = symbolElement.getAttribute("name"); String type = symbolElement.getAttribute("type"); if (symbolElement.hasAttribute("angle")) { - style.setAngle( - Double.parseDouble(symbolElement.getAttribute("angle"))); + try { + style.setAngle( + Double.parseDouble(symbolElement.getAttribute("angle"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting angle."); + style.setAngle(0.0); + } } if(symbolElement.hasAttribute("color")) { String c = symbolElement.getAttribute("color"); @@ -191,8 +221,13 @@ style.setColor(color); } if (symbolElement.hasAttribute ("size")) { - double size = Double.parseDouble( - symbolElement.getAttribute("size")); + double size = 1; + try { + size = Double.parseDouble(symbolElement.getAttribute("size")); + } + catch(NumberFormatException nfe) { + size = 1.0; + } style.setSize(size); //In arcgis the separation goes from center to center, so the gap is //the separation - size @@ -209,8 +244,14 @@ oCol.getBlue(), -4); style.setOutlinecolor(outlineColor); - style.setOutlinewidth(Double.parseDouble( - symbolElement.getAttribute("outline_size"))); + try { + style.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("outline_size"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting angle."); + style.setOutlinewidth(0.0); + } } if(type.equals("marker")) { style.setSymbolByName(map, name); @@ -255,8 +296,14 @@ private void writeSimple(Element symbolElement) { logger.debug("writeSimple(Element)"); if(symbolElement.hasAttribute("transparency")) { - double value = Double.parseDouble( - symbolElement.getAttribute("transparency")); + double value = 0; + try { + value = Double.parseDouble( + symbolElement.getAttribute("transparency")); + } + catch(NumberFormatException nfe) { + value = 0; + } int opacity = (int)(value/255) * 100; if(value >= 0) { style.setOpacity(opacity);
--- a/src/java/de/intevation/mxd/writer/LineStyleWriter.java Mon Jun 27 17:22:52 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/LineStyleWriter.java Mon Jun 27 18:22:21 2011 +0200 @@ -43,16 +43,27 @@ logger.debug("write(Element)"); symbolSetObj symbolSet = map.getSymbolset(); if(symbolElement.hasAttribute("width")) { - double w = Double.parseDouble(symbolElement.getAttribute("width")); + double w = 0; + try { + w = Double.parseDouble(symbolElement.getAttribute("width")); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting width. No line width set."); + w = 0; + } if(w < 1.0) { return false; } - style.setWidth((int)Double.parseDouble( - symbolElement.getAttribute("width"))); + style.setWidth((int)w); } if(symbolElement.hasAttribute("angle")) { - style.setAngle( - Double.parseDouble(symbolElement.getAttribute("angle"))); + try { + style.setAngle( + Double.parseDouble(symbolElement.getAttribute("angle"))); + } + catch(NumberFormatException nfe) { + logger.info("Error setting angle. Could not get value."); + } } if(symbolElement.hasAttribute("color")) { String c = symbolElement.getAttribute("color"); @@ -66,8 +77,14 @@ } if(symbolElement.hasAttribute("size")) { - style.setSize((int)Double.parseDouble( - symbolElement.getAttribute("size"))); + try { + style.setSize((int)Double.parseDouble( + symbolElement.getAttribute("size"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting size. Setting size to 1."); + style.setSize (1); + } } String type = symbolElement.getAttribute("type"); if(type.equals("marker")) {
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java Mon Jun 27 17:22:52 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java Mon Jun 27 18:22:21 2011 +0200 @@ -163,10 +163,19 @@ } //The scale. - double maxScale = - Double.parseDouble(layerElement.getAttribute("max_scale")); - double minScale = - Double.parseDouble(layerElement.getAttribute("min_scale")); + double maxScale = 0; + double minScale = 0; + try { + maxScale = + Double.parseDouble(layerElement.getAttribute("max_scale")); + minScale = + Double.parseDouble(layerElement.getAttribute("min_scale")); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting scale."); + maxScale = 0; + minScale = 0; + } layer.setMaxscaledenom(maxScale); layer.setMinscaledenom(minScale);
--- a/src/java/de/intevation/mxd/writer/MarkerStyleWriter.java Mon Jun 27 17:22:52 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/MarkerStyleWriter.java Mon Jun 27 18:22:21 2011 +0200 @@ -43,8 +43,14 @@ symbolSetObj symbolSet = map.getSymbolset(); if (symbolElement.hasAttribute("angle")) { - style.setAngle( - Double.parseDouble(symbolElement.getAttribute("angle"))); + try { + style.setAngle( + Double.parseDouble(symbolElement.getAttribute("angle"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting angle."); + style.setAngle(0.0); + } } if(symbolElement.hasAttribute("color")) { String c = symbolElement.getAttribute("color"); @@ -57,8 +63,14 @@ style.setColor(color); } if (symbolElement.hasAttribute ("size")) { - style.setSize(Double.parseDouble( - symbolElement.getAttribute("size"))); + try { + style.setSize(Double.parseDouble( + symbolElement.getAttribute("size"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting size. Setting to deafult: 1."); + style.setSize(1); + } } if(symbolElement.hasAttribute("outline_color")) { Color oCol = Color.decode( @@ -69,8 +81,13 @@ oCol.getBlue(), -4); style.setOutlinecolor(outlineColor); - style.setOutlinewidth(Double.parseDouble( - symbolElement.getAttribute("outline_size"))); + try { + style.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("outline_size"))); + } + catch(NumberFormatException nfe) { + logger.warn("Error setting outline width."); + } } String symType = symbolElement.getAttribute("style"); if(symType.equals("point") || @@ -85,7 +102,6 @@ String name = symbolElement.getAttribute("name"); style.setSymbolByName(map, name); - return true; } }
--- a/src/java/de/intevation/mxd/writer/SymbolWriter.java Mon Jun 27 17:22:52 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/SymbolWriter.java Mon Jun 27 18:22:21 2011 +0200 @@ -97,8 +97,18 @@ private void writeArrow(symbolObj symbol, Element symbolElement) { logger.debug("writeArrow(symbolObj, Element)"); - double len = Double.parseDouble(symbolElement.getAttribute("length")); - double width = Double.parseDouble(symbolElement.getAttribute("width")); + double len = 0; + double width = 1; + try { + len = + Double.parseDouble(symbolElement.getAttribute("length")); + width = + Double.parseDouble(symbolElement.getAttribute("width")); + } + catch(NumberFormatException nfe) { + logger.warn ("Error setting arrow symbol."); + return; + } double ratio = len/width; lineObj points = new lineObj(); @@ -161,11 +171,11 @@ String etype = elem.getAttribute("style"); if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue () && etype.equals("point")) { - return i; + return i; } else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue () && etype.equals("arrow")) { - return i; + return i; } else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue () && etype.equals("char")) { @@ -181,9 +191,8 @@ } else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue () && etype.equals("hatch")) { - return i; + return i; } - } return -1; }