view src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java @ 341:10a0bf9a47ab

Added OUTPUTFORMAT jpeg.
author Bjoern Schilberg <bjoern@intevation.de>
date Wed, 14 Nov 2012 13:07:40 +0100
parents ee77a3ae0201
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 org.apache.log4j.Logger;

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

import org.w3c.dom.Element;
import java.io.IOException;

import de.intevation.mxd.utils.MapToXMLUtils;

/**
 * Reads unique vaule renderer information.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class UniqueValueRendererReader
implements IRendererReader {

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

    /**
     * Private Member.
     */
    private UniqueValueRenderer renderer;
    private Element layer;
    private MapToXMLUtils util;

    /**
     * Constructor with renderer.
     *
     * @param renderer ArcGIS renderer.
     */
    public UniqueValueRendererReader(IFeatureRenderer renderer)
    throws Exception {
        logger.debug("constructor()");
        if (renderer instanceof UniqueValueRenderer) {
            this.renderer = (UniqueValueRenderer)renderer;
        }
        else {
            throw new Exception ("Not an instance of UniqueValueRenderer.");
        }
    }

    /**
     * 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 parent XML node.
     */
    public Element read() {
        int count = 0;
        try {
            count = renderer.getClassCount();
            logger.debug("Renderer with " + count + " classes.");
        }
        catch(IOException ioe) {
            logger.error(
                "Could not read class count."+
                " Stopped reading renderer.");
            return layer;
        }
        for(int i = 0; i < count; i++) {
            Element rendererElement = util.addRenderer(layer);
            ISymbol sym;
            try {
                if (!renderer.isUseDefaultSymbol() || i != count - 1) {
                    // When a default symbol exists the last class is the default class
                    String value = renderer.getValue(i);
                    String fieldSep = renderer.getFieldDelimiter();
                    if(value.indexOf(fieldSep) > 0) {
                        int j = 0;
                        while(value.indexOf(fieldSep) > 0) {
                            String v = value.substring(0, value.indexOf(fieldSep));
                            rendererElement.setAttribute("value_" + j, v);
                            value = value.substring(
                                    value.indexOf(fieldSep) + fieldSep.length(),
                                    value.length());
                            j++;
                        }
                        rendererElement.setAttribute("value_" + j, value);
                    }
                    else {
                        rendererElement.setAttribute("value", value);
                    }

                    value = renderer.getValue(i);
                    rendererElement.setAttribute("name", renderer.esri_getClass(i));
                    rendererElement.setAttribute("description",
                            renderer.getDescription(value));

                    rendererElement.setAttribute("label", renderer.getLabel(value));
                    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("expression_operator", "=");
                    sym = renderer.getSymbol(value);
                } else {
                    sym = renderer.getDefaultSymbol();
                }
                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 unique value data." +
                    e.toString());
                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)