Mercurial > mxd2map
changeset 106:609c234e8e23
merged with reimunds changes
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Tue, 07 Jun 2011 15:50:43 +0200 |
parents | db18c1b33936 (current diff) 4696d0769f9c (diff) |
children | 196abb30c0d2 |
files | properties.xml |
diffstat | 14 files changed, 416 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/properties.xml Tue Jun 07 13:53:48 2011 +0200 +++ b/properties.xml Tue Jun 07 15:50:43 2011 +0200 @@ -19,7 +19,7 @@ <property name="root.dir" location="${basedir}"/> <basename property="sample.dir" file="${basedir}" /> <property name="src.dir" location="src"/> -<property name="build.dir" location="c:\tmp\build"/> +<property name="build.dir" location="c:\tmp\build_sh"/> <property name="class.dir" location="${build.dir}/classes"/> <property name="dist.dir" location="${build.dir}/dist"/> <property name="libs.dir" location="lib"/>
--- a/src/java/de/intevation/mxd/Converter.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/Converter.java Tue Jun 07 15:50:43 2011 +0200 @@ -1,6 +1,5 @@ package de.intevation.mxd; -import java.io.IOException; import java.io.File; import java.io.FileInputStream; import java.io.BufferedInputStream;
--- a/src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java Tue Jun 07 15:50:43 2011 +0200 @@ -68,7 +68,8 @@ Element symbolElement = util.addSymbol(parent); symbolElement.setAttribute("name", symbol.getNameString()); - symbolElement.setAttribute("style", "line"); + symbolElement.setAttribute("type", "line"); + symbolElement.setAttribute("style", "carto"); if(symbol.getColor() instanceof IRgbColor) { IRgbColor color = (IRgbColor)symbol.getColor(); Color c = new Color (
--- a/src/java/de/intevation/mxd/reader/CharacterMarkerSymbolReader.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/CharacterMarkerSymbolReader.java Tue Jun 07 15:50:43 2011 +0200 @@ -5,10 +5,13 @@ import com.esri.arcgis.display.ISymbol; import com.esri.arcgis.display.IMarkerSymbol; import com.esri.arcgis.display.CharacterMarkerSymbol; -import com.esri.arcgis.display.IColor; import com.esri.arcgis.support.ms.stdole.Font; +import com.esri.arcgis.display.IRgbColor; +import com.esri.arcgis.display.RgbColor; + import org.w3c.dom.Element; +import java.awt.Color; /** * Reads character marker symbol information. @@ -61,7 +64,6 @@ logger.debug("read()"); Element symbolElement = util.addSymbol(parent); - IColor c = symbol.getColor(); symbolElement.setAttribute( "angle", String.valueOf(symbol.getAngle())); @@ -75,18 +77,34 @@ "y_offset", String.valueOf(symbol.getYOffset())); symbolElement.setAttribute( - "color", - String.valueOf(c.getRGB())); - symbolElement.setAttribute( - "tranparency", - String.valueOf(c.getTransparency())); - symbolElement.setAttribute( "name", symbol.getNameString()); symbolElement.setAttribute( "char", String.valueOf(symbol.getCharacterIndex())); + if(symbol.getColor() instanceof IRgbColor) { + IRgbColor color = (IRgbColor)symbol.getColor(); + Color c = new Color ( + color.getRed(), + color.getGreen(), + color.getBlue()); + symbolElement.setAttribute("color", String.valueOf(c.getRGB())); + symbolElement.setAttribute("transparency", + String.valueOf(color.getTransparency())); + } + else { + RgbColor col = new RgbColor(); + col.setRGB(symbol.getColor().getRGB()); + Color c = new Color ( + col.getRed(), + col.getGreen(), + col.getBlue()); + symbolElement.setAttribute("color", String.valueOf(c.getRGB())); + symbolElement.setAttribute("transparency", + String.valueOf(col.getTransparency())); + } + Font f = symbol.getFont(); symbolElement.setAttribute("font", f.getName()); symbolElement.setAttribute("char_set", String.valueOf(f.getCharset()));
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java Tue Jun 07 15:50:43 2011 +0200 @@ -79,6 +79,7 @@ case 0: layerElement.setAttribute("type", "none"); break; case 1: layerElement.setAttribute("type", "point"); break; case 3: layerElement.setAttribute("type", "line"); break; + case 4: layerElement.setAttribute("type", "polygon"); break; } layerElement.setAttribute("definition_query",
--- a/src/java/de/intevation/mxd/reader/HashLineSymbolReader.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/HashLineSymbolReader.java Tue Jun 07 15:50:43 2011 +0200 @@ -67,7 +67,8 @@ Element symbolElement = util.addSymbol(parent); symbolElement.setAttribute("name", symbol.getNameString()); - symbolElement.setAttribute("style", "line"); + symbolElement.setAttribute("type", "line"); + symbolElement.setAttribute("style", "hash"); if(symbol.getColor() instanceof IRgbColor) { IRgbColor color = (IRgbColor)symbol.getColor(); Color c = new Color (
--- a/src/java/de/intevation/mxd/reader/LineFillSymbolReader.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/LineFillSymbolReader.java Tue Jun 07 15:50:43 2011 +0200 @@ -74,6 +74,7 @@ symbolElement.setAttribute( "separation", String.valueOf(symbol.getSeparation())); + symbolElement.setAttribute("angle", String.valueOf(symbol.getAngle())); if(symbol.getColor() instanceof IRgbColor) { IRgbColor color = (IRgbColor)symbol.getColor(); @@ -112,6 +113,7 @@ ILineSymbol ls = symbol.getLineSymbol(); LineSymbolReader lsr = new LineSymbolReader(); if(lsr.canRead(ls)) { + symbolElement.setAttribute("hatch", "1"); lsr.setSymbol(ls); lsr.setUtil(util); lsr.setParent(symbolElement);
--- a/src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java Tue Jun 07 15:50:43 2011 +0200 @@ -68,6 +68,7 @@ Element symbolElement = util.addSymbol(parent); symbolElement.setAttribute("name", symbol.getNameString()); + symbolElement.setAttribute("type", "line"); symbolElement.setAttribute("style", "picture"); if(symbol.getColor() instanceof IRgbColor) { IRgbColor color = (IRgbColor)symbol.getColor();
--- a/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java Tue Jun 07 15:50:43 2011 +0200 @@ -65,8 +65,8 @@ Element symbolElement = util.addSymbol(parent); symbolElement.setAttribute("name", symbol.getNameString()); - symbolElement.setAttribute("style", "line"); - symbolElement.setAttribute("type", "simple"); + symbolElement.setAttribute("type", "line"); + symbolElement.setAttribute("style", "simple"); if(symbol.getColor() instanceof IRgbColor) { IRgbColor color = (IRgbColor)symbol.getColor(); Color c = new Color (
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/intevation/mxd/writer/FillStyleWriter.java Tue Jun 07 15:50:43 2011 +0200 @@ -0,0 +1,225 @@ +package de.intevation.mxd.writer; + +import java.io.IOException; +import java.awt.Color; +import org.apache.log4j.Logger; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import edu.umn.gis.mapscript.mapObj; +import edu.umn.gis.mapscript.layerObj; +import edu.umn.gis.mapscript.classObj; +import edu.umn.gis.mapscript.styleObj; +import edu.umn.gis.mapscript.colorObj; +import edu.umn.gis.mapscript.symbolObj; +import edu.umn.gis.mapscript.symbolSetObj; +import edu.umn.gis.mapscript.lineObj; +import edu.umn.gis.mapscript.pointObj; + + +/** + * The interface to the mapfile writer. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FillStyleWriter { + + /** + * The Logger. + */ + private static final Logger logger = + Logger.getLogger(FillStyleWriter.class); + + private mapObj map; + private classObj cl; + private styleObj style; + + public FillStyleWriter (mapObj map, classObj cl) { + logger.debug("contructor(mapObj, classObj)"); + this.map = map; + this.cl = cl; + this.style = new styleObj(cl); + } + + /** + * Write the content. + */ + public boolean write(Element symbolElement) + throws Exception { + symbolSetObj symbolSet = map.getSymbolset(); + + if(symbolElement.hasChildNodes()) { + NodeList symbols = symbolElement.getChildNodes(); + for (int i = 0; i < symbols.getLength(); i++) { + Element nextSym = (Element)symbols.item(i); + String type = nextSym.getAttribute("type"); + + if(((symbols.getLength() > 1 && i == 0) || + (symbols.getLength() == 1 && + !symbolElement.hasAttribute("hatch"))) && + type.equals("line")) { + writeOutline(nextSym); + if (symbols.getLength() == 1) { + writeSimple(symbolElement); + } + } + else if(nextSym.getTagName().equals("symbol") && + !symbolElement.hasAttribute("hatch") || + (i == 1 && type.equals("marker"))) { + double gap = 0; + if(symbolElement.hasAttribute("xseparation")) { + gap = Double.parseDouble( + symbolElement.getAttribute("xseparation")); + } + writeMarker(nextSym, gap); + } + else if (nextSym.getTagName().equals("symbol") && + symbolElement.hasAttribute("hatch")) { + if(symbolElement.hasAttribute("angle")) { + nextSym.setAttribute( + "angle", + symbolElement.getAttribute("angle")); + } + if(symbolElement.hasAttribute("separation")) { + nextSym.setAttribute( + "size", + symbolElement.getAttribute("separation")); + } + writeMarker(nextSym, -1); + } + else { + writeSimple(symbolElement); + } + } + } + else { + writeSimple(symbolElement); + if(symbolElement.hasAttribute("outline_color")) { + Color oCol = Color.decode( + symbolElement.getAttribute("outline_color")); + colorObj outlineColor = new colorObj( + oCol.getRed(), + oCol.getGreen(), + oCol.getBlue(), + -4); + style.setOutlinecolor(outlineColor); + style.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("outline_size"))); + } + + } + + return true; + } + + /** + * Write the outline for a polygon. + */ + private void writeOutline(Element symbolElement) + throws Exception { + logger.debug("writeOutline()"); + //write transparent outline + colorObj color = new colorObj(-1, -1, -1, -4); + + //write new style for the outline + //TODO write further attribute like pattern etc. + Color oCol = Color.decode( + symbolElement.getAttribute("color")); + + styleObj outline = new styleObj (cl); + + colorObj outlinecolor = new colorObj( + oCol.getRed(), + oCol.getGreen(), + oCol.getBlue(), + -4); + outline.setOutlinecolor(outlinecolor); + outline.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("width"))); + } + + /** + * Write marker attributes and a symbol for the polygon fill. + */ + private void writeMarker(Element symbolElement, double gap) + throws Exception { + logger.debug("writeMarker()"); + String name = symbolElement.getAttribute("name"); + String type = symbolElement.getAttribute("type"); + if (symbolElement.hasAttribute("angle")) { + style.setAngle( + Double.parseDouble(symbolElement.getAttribute("angle"))); + } + if(symbolElement.hasAttribute("color")) { + String c = symbolElement.getAttribute("color"); + Color col = Color.decode(c); + colorObj color = new colorObj( + col.getRed(), + col.getGreen(), + col.getBlue(), + -4); + style.setColor(color); + } + if (symbolElement.hasAttribute ("size")) { + double size = Double.parseDouble( + symbolElement.getAttribute("size")); + style.setSize(size); + //In arcgis the separation goes from center to center, so the gap is + //the separation - size + if (gap > 0) { + style.setGap(gap - size); + } + } + if(symbolElement.hasAttribute("outline_color")) { + Color oCol = Color.decode( + symbolElement.getAttribute("outline_color")); + colorObj outlineColor = new colorObj( + oCol.getRed(), + oCol.getGreen(), + oCol.getBlue(), + -4); + style.setOutlinecolor(outlineColor); + style.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("outline_size"))); + } + + if(type.equals("marker")) { + style.setSymbolByName(map, name); + SymbolWriter sw = new SymbolWriter(this.map, this.cl); + sw.write(symbolElement); + } + else if(type.equals("line")) { + style.setSymbolByName(map, "hatch"); + SymbolWriter sw = new SymbolWriter(this.map, this.cl); + symbolElement.setAttribute("name", "hatch"); + sw.write(symbolElement); + } + } + + /** + * Write simple fill attributes. + */ + private void writeSimple(Element symbolElement) { + logger.debug("writeSimple(Element)"); + if(symbolElement.hasAttribute("transparency")) { + double value = Double.parseDouble( + symbolElement.getAttribute("transparency")); + int opacity = (int)(value/255) * 100; + if(value >= 0) { + style.setOpacity(opacity); + } + } + if(symbolElement.hasAttribute("color")) { + String c = symbolElement.getAttribute("color"); + Color col = Color.decode(c); + colorObj color = new colorObj( + col.getRed(), + col.getGreen(), + col.getBlue(), + -4); + style.setColor(color); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/writer/IWriter.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/IWriter.java Tue Jun 07 15:50:43 2011 +0200 @@ -1,7 +1,5 @@ package de.intevation.mxd.writer; -import java.io.IOException; - import org.w3c.dom.Document; /**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/intevation/mxd/writer/LineStyleWriter.java Tue Jun 07 15:50:43 2011 +0200 @@ -0,0 +1,109 @@ +package de.intevation.mxd.writer; + +import java.awt.Color; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Element; + +import edu.umn.gis.mapscript.mapObj; +import edu.umn.gis.mapscript.classObj; +import edu.umn.gis.mapscript.styleObj; +import edu.umn.gis.mapscript.colorObj; +import edu.umn.gis.mapscript.symbolObj; +import edu.umn.gis.mapscript.symbolSetObj; + + +/** + * The interface to the mapfile writer. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class LineStyleWriter { + + /** + * The Logger. + */ + private static final Logger logger = Logger.getLogger(LineStyleWriter.class); + + private mapObj map; + private classObj cl; + private styleObj style; + + public LineStyleWriter (mapObj map, classObj cl) { + this.map = map; + this.cl = cl; + this.style = new styleObj(cl); + } + + /** + * Write the content. + */ + public boolean write(Element symbolElement) + throws Exception { + logger.debug("write(Element)"); + symbolSetObj symbolSet = map.getSymbolset(); + if(symbolElement.hasAttribute("angle")) { + style.setAngle( + Double.parseDouble(symbolElement.getAttribute("angle"))); + } + if(symbolElement.hasAttribute("color")) { + String c = symbolElement.getAttribute("color"); + Color col = Color.decode(c); + colorObj color = new colorObj( + col.getRed(), + col.getGreen(), + col.getBlue(), + -4); + style.setColor(color); + } + if(symbolElement.hasAttribute("width")) { + style.setWidth((int)Double.parseDouble( + symbolElement.getAttribute("width"))); + } + if(symbolElement.hasAttribute("size")) { + style.setSize((int)Double.parseDouble( + symbolElement.getAttribute("size"))); + } + String name = symbolElement.getAttribute("name"); + symbolObj sym = symbolSet.getSymbolByName(name); + + //The following lines are for dashed and/or dotted lines. + //These lines throw an "incorrect array size" error. + //TODO Find out how to set the pattern correctly.(Remove the "&& false" + //to use this block). + if(symbolElement.hasAttribute("linestyle") && false) { + String ls = symbolElement.getAttribute("linestyle"); + double[] vals; + if(ls.equals("dash")) { + style.setPatternlength(2); + vals = new double[] {2.0, 2.0}; + style.setPattern(vals); + } + else if(ls.equals("dot")) { + style.setPatternlength(2); + vals = new double[] {1.0, 2.0}; + style.setPattern(vals); + } + else if(ls.equals("dashdot")) { + style.setPatternlength(4); + vals = new double[] {2.0, 2.0, 1.0, 2.0}; + style.setPattern(vals); + } + else if (ls.equals("dashdotdot")) { + style.setPatternlength(6); + vals = new double[] {2.0, 2.0, 1.0, 2.0, 1.0, 2.0}; + style.setPattern(vals); + } + } + String type = symbolElement.getAttribute("type"); + + if(type.equals("marker")) { + style.setSymbolByName(map, name); + SymbolWriter sw = new SymbolWriter(this.map, this.cl); + sw.write(symbolElement); + } + return false; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java Tue Jun 07 15:50:43 2011 +0200 @@ -6,22 +6,16 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import java.io.File; + import javax.xml.xpath.XPathConstants; -import java.awt.Color; import edu.umn.gis.mapscript.mapObj; import edu.umn.gis.mapscript.layerObj; import edu.umn.gis.mapscript.classObj; -import edu.umn.gis.mapscript.styleObj; -import edu.umn.gis.mapscript.colorObj; -import edu.umn.gis.mapscript.symbolObj; -import edu.umn.gis.mapscript.symbolSetObj; -import edu.umn.gis.mapscript.lineObj; -import edu.umn.gis.mapscript.pointObj; import edu.umn.gis.mapscript.MS_UNITS; import edu.umn.gis.mapscript.MS_LAYER_TYPE; -import edu.umn.gis.mapscript.MS_SYMBOL_TYPE; import de.intevation.mxd.utils.XMLUtils; @@ -179,9 +173,18 @@ else if (type.equals("line")) { layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE); } + else if (type.equals("polygon")) { + layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON); + } //The layer datasource. - layer.setData(layerElement.getAttribute("data_source")); + String datasource = ""; + if(layerElement.hasAttribute("workspace")) { + datasource = layerElement.getAttribute("workspace"); + datasource += File.separator; + } + datasource += layerElement.getAttribute("data_source"); + layer.setData(datasource); //Write classes. writeClass(layer, layerElement); @@ -220,20 +223,22 @@ co.setExpression(exp); } //Write symbols and styles. - NodeList slist = classElement.getElementsByTagName("symbol"); - String type = layerElement.getAttribute("type"); - if(type.equals("point")) { - for(int j = 0; j < slist.getLength(); j++){ - Element symbolElement = (Element) slist.item(j); + NodeList l = classElement.getChildNodes(); + for (int j = 0; j < l.getLength(); j++) { + Element elem = (Element)l.item(j); + + String type = layerElement.getAttribute("type"); + if(type.equals("point") && elem.getTagName().equals("symbol")) { MarkerStyleWriter swriter = new MarkerStyleWriter (this.map, co); - swriter.write (symbolElement); + swriter.write (elem); } - } - else if(type.equals("line")) { - for(int j = 0; j < slist.getLength(); j++){ - Element symbolElement = (Element) slist.item(j); -// LineStyleWriter swriter = new LineStyleWriter (this.map, co); -// swriter.write (symbolElement); + else if(type.equals("line") && elem.getTagName().equals("symbol")) { + LineStyleWriter swriter = new LineStyleWriter (this.map, co); + swriter.write (elem); + } + else if(type.equals("polygon") && elem.getTagName().equals("symbol")) { + FillStyleWriter swriter = new FillStyleWriter (this.map, co); + swriter.write (elem); } } }
--- a/src/java/de/intevation/mxd/writer/SymbolWriter.java Tue Jun 07 13:53:48 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/SymbolWriter.java Tue Jun 07 15:50:43 2011 +0200 @@ -1,10 +1,6 @@ package de.intevation.mxd.writer; import org.apache.log4j.Logger; -import java.io.File; -import java.io.FileInputStream; -import java.io.BufferedInputStream; -import java.util.Properties; import org.w3c.dom.Element; @@ -50,8 +46,8 @@ String name = symbolElement.getAttribute("name"); symbolObj sym = symbolSet.getSymbolByName(name); - String symType = symbolElement.getAttribute("style"); + String type = symbolElement.getAttribute("type"); if(symType.equals("point")) { writeSimple(sym); } @@ -62,6 +58,9 @@ //TODO Does not work at all... waiting for fix. writeCharacter(sym, symbolElement); } + else if (type.equals("line")) { + writeHatch(sym); + } else { return false; } @@ -99,16 +98,25 @@ private void writeCharacter(symbolObj symbol, Element symbolElement) { logger.debug("writeCharacter(symbolObj, Element)"); //TODO Write the symbol correctly. See Issue 3885 on trac.osgeo.org - symbol.setFont(symbolElement.getAttribute("font")); + String font = symbolElement.getAttribute("font"); + //Remove all blank character to match the mapserver fonts.txt. + font = font.replaceAll(" ", ""); + symbol.setFont(font); symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue()); symbol.setAntialias(1); - symbol.setCharacter("#&" + symbolElement.getAttribute("char") + ";"); + symbol.setCharacter("&#" + symbolElement.getAttribute("char") + ";"); + } + + private void writeHatch(symbolObj symbol) { + logger.debug("writeHatch(symbolObj)"); + symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue()); } public boolean canWrite(String type) { if (type.equals("point") || type.equals("arrow") || - type.equals("char")) { + type.equals("char") || + type.equals("line")) { return true; } else { @@ -118,12 +126,12 @@ private void saveSymbolSet(symbolSetObj symbols) throws Exception { - String path = "";// TODO Get the correct path. Mapfile path or symbolset path + String path = this.map.getMappath(); if(path.equals("")) { return; } - else if(path.endsWith(".map")) { - path.replace(".map", ".sym"); + else { + path += "symbols.sym"; } symbols.save(path); }