view src/java/de/intevation/mxd/writer/MarkerStyleWriter.java @ 190:c640fb351f66

Do not write layer with empty CLASS objects.
author raimund renkert <raimund.renkert@intevation.de>
date Wed, 20 Jul 2011 16:00:22 +0200
parents 0bde090506f9
children 17b4aaa159ec
line wrap: on
line source
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.symbolSetObj;


/**
 * The interface to the mapfile writer.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class MarkerStyleWriter {

    /**
     * The Logger.
     */
    private static final Logger logger = Logger.getLogger(MarkerStyleWriter.class);

    /**
     * Private member.
     */
    private mapObj map;
    private classObj cl;
    private styleObj style;

    /**
     * Contructor with map object and class object.
     *
     * @param map The map object.
     * @param cl  The class object containing the style.
     */
    public MarkerStyleWriter (mapObj map, classObj cl) {
        this.map = map;
        this.cl = cl;
        this.style = new styleObj(cl);
    }

    /**
     * Write the content.
     *
     * @param symbolElement DOM element containing style attributes.
     */
    public boolean write(Element symbolElement) {
        logger.debug("write(Element)");
        symbolSetObj symbolSet = map.getSymbolset();

        if (symbolElement.hasAttribute("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");
            Color col = Color.decode(c);
            colorObj color = new colorObj(
                col.getRed(),
                col.getGreen(),
                col.getBlue(),
                -4);
            style.setColor(color);
        }
        if (symbolElement.hasAttribute ("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(
                symbolElement.getAttribute("outline_color"));
            colorObj outlineColor = new colorObj(
                oCol.getRed(),
                oCol.getGreen(),
                oCol.getBlue(),
                -4);
            style.setOutlinecolor(outlineColor);
            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") ||
           symType.equals("arrow") ||
           symType.equals("char")) {
           SymbolWriter sw = new SymbolWriter(this.map, this.cl);
           sw.write(symbolElement);
        }
        else {
            return false;
        }
        String name = symbolElement.getAttribute("name");
        style.setSymbolByName(map, name);

        return true;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)