view src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java @ 340:dbfcb0b69a63

* contrib/installer/example/example/template.map: Switch to latin1 encoding * contrib/installer/example/example/mapfile_header.include: Remove shapepath, data is now referenced relative to the mapfile
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 09 Nov 2012 16:54:16 +0100
parents a46adb3697fa
children
line wrap: on
line source
/*
 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
 *
 * This file is part of MXD2map.
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LICENCE.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 *
 * MXD2map has been developed on behalf of the
 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
 * by Intevation GmbH.
 *
 * Authors:
 * Raimund Renkert <raimund.renkert@intevation.de>
 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
 * Stephan Holl <stephan.holl@intevation.de>
 */

package de.intevation.mxd.reader;

import java.lang.Exception;

import org.apache.log4j.Logger;

import com.esri.arcgis.carto.IFeatureRenderer;
import com.esri.arcgis.carto.ClassBreaksRenderer;
import com.esri.arcgis.display.ISymbol;

import org.w3c.dom.Element;

import de.intevation.mxd.utils.MapToXMLUtils;
import java.io.IOException;

/**
 * Reads the ClassBreaksRender Object Attributes.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class ClassBreakRendererReader
implements IRendererReader {

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

    /**
     * Private member.
     */
    private ClassBreaksRenderer renderer;
    private Element layer;
    private MapToXMLUtils util;

    /**
     * Constructor with renderer.
     *
     * @param renderer The ArcGIS renderer.
     */
    public ClassBreakRendererReader(IFeatureRenderer renderer)
    throws Exception {
        logger.debug("constructor()");
        if(renderer instanceof ClassBreaksRenderer)
            this.renderer = (ClassBreaksRenderer)renderer;
        else
            throw new Exception("Not a ClassBreaksRenderer!");
    }

    /**
     * Setter for the parent XML element.
     *
     * @param parent The XML parent node.
     */
    public void setParent(Element parent) {
        this.layer = parent;
    }

    /**
     * Setter for XML document helper.
     *
     * @param util The helper class for storing map information.
     */
    public void setUtil(MapToXMLUtils util) {
        this.util = util;
    }

    /**
     * Reads the Renderer attributes.
     *
     * @return The XML node.
     */
    public Element read() {
        logger.debug("read()");

        int count = 0;
        try {
            count = renderer.getBreakCount();
        }
        catch(IOException ioe) {
            logger.warn(
                "No break symbols found in renderer." +
                " Stopped reading this renderer.");
            return layer;
        }

        for(int i = 0; i < count; i++){
            Element rendererElement = util.addRenderer(layer);
            try {
                rendererElement.setAttribute("value",
                    String.valueOf(renderer.getBreak(i)));
                rendererElement.setAttribute("label", renderer.getLabel(i));
                rendererElement.setAttribute(
                    "field_count",
                    String.valueOf(renderer.getFieldCount()));
                for(int j = 0; j < renderer.getFieldCount(); j++) {
                    rendererElement.setAttribute(
                        "expression_field_" + j,
                        renderer.getField(j));

                }
                rendererElement.setAttribute(
                    "min_value",
                    String.valueOf(renderer.getLowBreak(i)));
                rendererElement.setAttribute("expression_operator", "<=");

                ISymbol sym = renderer.getSymbol(i);
                MarkerSymbolReader markerReader = new MarkerSymbolReader();
                LineSymbolReader lineReader = new LineSymbolReader();
                FillSymbolReader fillReader = new FillSymbolReader();
                if(markerReader.canRead(sym)) {
                    markerReader.setSymbol(sym);
                    markerReader.setUtil(util);
                    markerReader.setParent(rendererElement);
                    markerReader.read();
                }
                else if(lineReader.canRead(sym)) {
                    lineReader.setSymbol(sym);
                    lineReader.setUtil(util);
                    lineReader.setParent(rendererElement);
                    lineReader.read();
                }
                else if(fillReader.canRead(sym)) {
                    fillReader.setSymbol(sym);
                    fillReader.setUtil(util);
                    fillReader.setParent(rendererElement);
                    fillReader.read();
                }
                else {
                    logger.debug("Not a known symbol type: " +
                                 sym.getClass().toString());
                }
            }
            catch(Exception e) {
                logger.error(
                    "Could not read data for " + i +
                    ". break of renderer. Stopped reading this renderer.");
                return layer;
            }
        }
        return layer;
    }
}
// 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)