view src/java/de/intevation/mxd/reader/MapReader.java @ 52:cd541e73d523

* mapserver/rundir/Readme.txt: New. This is a folder containing the MXD-files for conversion. The resulting MAP-file can be run from here; all Paths are relative from here so request will find its symbols, fonts, logfiles etc. * mapserver/mapfile/mapfile_header.include: Added SHAPEPATH for the Visualization of the frida-shapefiles.
author Stephan Holl <stephan.holl@intevation.de>
date Wed, 11 May 2011 10:08:25 +0200
parents ef7ca23c4233
children 8da6555f1c12
line wrap: on
line source
package de.intevation.mxd.reader;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.esri.arcgis.carto.IMap;
import com.esri.arcgis.carto.Map;
import com.esri.arcgis.geometry.ISpatialReference;
import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
import com.esri.arcgis.geometry.GeographicCoordinateSystem;
import com.esri.arcgis.geometry.UnknownCoordinateSystem;
import com.esri.arcgis.geometry.Projection;
import com.esri.arcgis.geometry.IEnvelope;

import org.w3c.dom.Element;

import de.intevation.mxd.utils.MapToXMLUtils;

/**
 * Reads map information.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class MapReader {
    /**
     * The Logger.
     */
    private static final Logger logger = Logger.getLogger(MapReader.class);

    /**
     * Private member.
     */
    private Map map;
    private MapToXMLUtils util;


    public MapReader(IMap map)
    throws Exception {
        logger.debug("constructor()");
        if(map instanceof Map) {
            this.map = (Map)map;
        }
        else {
            throw new Exception("Not an instance of \"Map\"!");
        }
    }

    /**
     * Reads the Map attributes.
     */
    public void read()
    throws IOException {
        logger.debug("read()");
        if(util == null) {
            throw new IOException("Can not write to document.");
        }

        //Create XML Element for map.
        Element mapElement;
        try{
            mapElement = util.createMap();
        }
        catch(Exception e){
            e.printStackTrace();
            return;
        }

        //Read map name.
        mapElement.setAttribute("name", map.getName());

        //Read map extent.
        IEnvelope ext = map.getExtent();
        mapElement.setAttribute(
            "extent_max_x",
            String.valueOf(ext.getXMax()));
        mapElement.setAttribute(
            "extent_max_y",
            String.valueOf(ext.getYMax()));
        mapElement.setAttribute(
            "extent_min_x",
            String.valueOf(ext.getXMin()));
        mapElement.setAttribute(
            "extent_min_y",
            String.valueOf(ext.getYMin()));

        //Read map units.
        int units = map.getMapUnits();
        String s_units;
        switch(units) {
            case   3: s_units = "feet"; break;
            case   1: s_units = "inches"; break;
            case  10: s_units = "kilometers"; break;
            case   9: s_units = "meters"; break;
            case   5: s_units = "miles"; break;
            case   6: s_units = "nauticalmiles"; break;
            case   2: s_units = "points"; break;
            default : s_units = "not supported"; break;
        }
        mapElement.setAttribute("units", s_units);

        //TODO: Find out whats the correct scale value.
        mapElement.setAttribute(
            "scale",
            String.valueOf(map.getMaxScale()));

        //Read the projection.
        ISpatialReference sr = map.getSpatialReference();
        if(sr instanceof ProjectedCoordinateSystem) {
            ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
            Projection p = (Projection)pcs.getProjection();
            mapElement.setAttribute("projection", p.getName());
        }
        else if(sr instanceof GeographicCoordinateSystem) {
            GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
            mapElement.setAttribute("projection", gcs.getName());
        }
        else if(sr instanceof UnknownCoordinateSystem) {
            UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
            mapElement.setAttribute("projection", sr.getName());
        }
        else{
            throw new IOException("Unknown SpatialReference: " +
                                  sr.getClass().toString());
        }
    }

    /**
     * Set the utilities.
     */
    public void setUtil(MapToXMLUtils util) {
        this.util = util;
    }
}
// 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)