Mercurial > mxd2map
diff src/java/de/intevation/mxd/writer/SymbolWriter.java @ 87:7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 31 May 2011 17:54:43 +0200 |
parents | |
children | 82a1f39214fd |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/intevation/mxd/writer/SymbolWriter.java Tue May 31 17:54:43 2011 +0200 @@ -0,0 +1,112 @@ +package de.intevation.mxd.writer; + +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.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_SYMBOL_TYPE; + + +/** + * The interface to the mapfile writer. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class SymbolWriter { + + /** + * The Logger. + */ + private static final Logger logger = Logger.getLogger(SymbolWriter.class); + + private mapObj map; + private classObj cl; + private styleObj style; + + public SymbolWriter (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(); + + String name = symbolElement.getAttribute("name"); + symbolObj sym = symbolSet.getSymbolByName(name); + + String symType = symbolElement.getAttribute("style"); + if(symType.equals("point")) { + writeSimple(sym); + } + else if (symType.equals("arrow")) { + writeArrow(sym, symbolElement); + } + else if (symType.equals("char")) { + //TODO Does not work at all... waiting for fix. + writeCharacter(sym, symbolElement); + } + else { + return false; + } + return true; + } + + private void writeSimple(symbolObj symbol) { + logger.debug("writeSimple(symbolObj)"); + lineObj points = new lineObj(); + points.add(new pointObj(1,1,0)); + symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue()); + symbol.setPoints(points); + symbol.setFilled(1); + } + + 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 ratio = len/width; + lineObj points = new lineObj(); + + points.add(new pointObj(0, 0, 0)); + points.add(new pointObj((1*ratio), 0.5, 0)); + points.add(new pointObj(0, 1, 0)); + points.add(new pointObj(0, 0, 0)); + symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue()); + symbol.setPoints(points); + symbol.setFilled(1); + } + + 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")); + symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue()); + symbol.setAntialias(1); + symbol.setCharacter("#&" + symbolElement.getAttribute("char") + ";"); + } + + public boolean canWrite(String type) { + if (type.equals("point") || + type.equals("arrow") || + type.equals("char")) { + return true; + } + else { + return false; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :