view src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java @ 287:584bc79cf4ad

changed copyright to Intevation as stated in all src-files
author Stephan Holl <stephan.holl@intevation.de>
date Mon, 28 Nov 2011 14:31:51 +0100
parents eae3fe89e669
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.ILayer;
import com.esri.arcgis.carto.GdbRasterCatalogLayer;
import com.esri.arcgis.system.IPropertySet;
import com.esri.arcgis.geodatabase.IWorkspace;

import org.w3c.dom.Element;
import java.io.IOException;
import de.intevation.mxd.utils.MapToXMLUtils;

/**
 * Reads Layer information.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class GdbRasterCatalogLayerReader
implements ILayerReader {

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

    /**
     * Privte member.
     */
    private GdbRasterCatalogLayer  layer;
    private MapToXMLUtils util;

    /**
     * Constructor with layer.
     *
     * @param layer The ArcGIS layer object.
     */
    public GdbRasterCatalogLayerReader(ILayer layer)
    throws Exception {
        if(layer instanceof GdbRasterCatalogLayer) {
            this.layer = (GdbRasterCatalogLayer)layer;
        }
        else {
            throw new Exception("Not an instance of GdbRastaCatalogLayer: " +
                layer.getClass().toString());
        }
    }

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

    /**
     * Reads the Layer content.
     *
     * @return The layer XML element.
     */
    public Element read()
    throws IOException {
        logger.debug("read()");

        Element layerElement;
        try {
            layerElement = util.addLayer();
        }
        catch(Exception e) {
            logger.error(
                "Could not create DOM element for layer." +
                "Stopped reading layer.");
            throw new IOException(
                this.getClass().toString() +
                "Error creating dom element");
        }

        try {
            layerElement.setAttribute("name", layer.getName());
        }
        catch(IOException ioe) {
            logger.warn("Could not read layer name. Stopped reading layer.");
            throw new IOException("Error reading layer name.");
        }

        try {
            layerElement.setAttribute("min_scale",
                String.valueOf(layer.getMinimumScale()));
        }
        catch(IOException ioe) {
            logger.warn("Could not read minimum layer scale.");
        }

        try {
            layerElement.setAttribute("max_scale",
                String.valueOf(layer.getMaximumScale()));
        }
        catch(IOException ioe) {
            logger.warn("Could not read maximum layer scale.");
        }

        try {
            if(layer.isVisible()) {
                layerElement.setAttribute("status", "on");
            }
            else {
                layerElement.setAttribute("status", "off");
            }
        }
        catch(IOException ioe) {
            logger.warn(
                "Could not read layer status." +
                " Setting layer status to \"on\"");
            layerElement.setAttribute("status", "on");
        }

        try {
            layerElement.setAttribute("definition_query",
                layer.getDefinitionExpression());
        }
        catch(IOException ioe) {
            logger.warn(
                "Could not read layer definition query.");
        }

        try {
            layerElement.setAttribute("type", "raster");
            IWorkspace rw = layer.getWorkspace();
            layerElement.setAttribute(
                "dataset",
                rw.getDatasetNames(16).next().getName());
            IPropertySet set = rw.getConnectionProperties();
            Object names[] = new Object[set.getCount()];
            Object prop[] = new Object[set.getCount()];
            set.getAllProperties(names, prop);
            layerElement.setAttribute("connection_type", "SDE");
            for(int i = 0; i < names.length; i++) {
                if(names[i] != null) {
                    String[] prop_names = (String[])names[i];
                    for(int j = 0; j < prop_names.length; j++) {
                        layerElement.setAttribute(
                            prop_names[j].toLowerCase(),
                             set.getProperty(prop_names[j]).toString());
                    }
                }
            }
        }
        catch(Exception e) {
            e.printStackTrace();
            logger.error(
                "Could not read layer datasource." +
                " Stopped reading layer " + layer.getName() + ".");
            util.removeLayer(layerElement);
            return null;
        }

        return layerElement;
    }
}
// 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)