comparison src/java/de/intevation/mxd/reader/RasterLayerReader.java @ 303:a9684178cb29

Add RasterLayer Reader
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 05 Sep 2012 17:16:41 +0200
parents
children ea3fde77ea48
comparison
equal deleted inserted replaced
302:f5ac467e2863 303:a9684178cb29
1 /*
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
3 *
4 * This file is part of MXD2map.
5 *
6 * This program is free software under the LGPL (>=v2.1)
7 * Read the file LICENCE.txt coming with the software for details
8 * or visit http://www.gnu.org/licenses/ if it does not exist.
9 *
10 * MXD2map has been developed on behalf of the
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
12 * by Intevation GmbH.
13 *
14 * Authors:
15 * Raimund Renkert <raimund.renkert@intevation.de>
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
17 * Stephan Holl <stephan.holl@intevation.de>
18 */
19
20 package de.intevation.mxd.reader;
21
22 import org.apache.log4j.Logger;
23
24 import com.esri.arcgis.carto.ILayer;
25 import com.esri.arcgis.carto.RasterLayer;
26 import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection;
27 import com.esri.arcgis.carto.IAnnotateLayerProperties;
28 import com.esri.arcgis.carto.LabelEngineLayerProperties;
29 import com.esri.arcgis.geodatabase.RasterDatasetName;
30 import com.esri.arcgis.system.IName;
31 import com.esri.arcgis.system.IPropertySet;
32 import com.esri.arcgis.geometry.Envelope;
33
34 import org.w3c.dom.Element;
35
36 import de.intevation.mxd.utils.MapToXMLUtils;
37 import java.io.IOException;
38 import com.esri.arcgis.interop.AutomationException;
39 /**
40 * Reads Layer information.
41 *
42 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a>
43 */
44 public class RasterLayerReader
45 implements ILayerReader {
46
47 /**
48 * The logger.
49 */
50 private static final Logger logger =
51 Logger.getLogger(RasterLayerReader.class);
52
53 /**
54 * Privte member.
55 */
56 private RasterLayer layer;
57 private MapToXMLUtils util;
58
59 /**
60 * Constructor with layer.
61 *
62 * @param layer The ArcGIS layer object.
63 */
64 public RasterLayerReader(ILayer layer)
65 throws Exception {
66 if(layer instanceof RasterLayer) {
67 this.layer = (RasterLayer)layer;
68 }
69 else {
70 throw new Exception("Not an instance of RasterLayer: " +
71 layer.getClass().toString());
72 }
73 }
74
75 /**
76 * Setter for XML document helper.
77 *
78 * @param util The helper for storing map information.
79 */
80 public void setUtil(MapToXMLUtils util) {
81 this.util = util;
82 }
83
84 /**
85 * Reads the Layer content.
86 *
87 * @return The layer XML element.
88 */
89 public Element read()
90 throws IOException{
91 logger.debug("read()");
92 Element layerElement;
93 try {
94 layerElement = util.addLayer();
95 }
96 catch(Exception e) {
97 logger.error("Failed to create DOM-Element for Layer.");
98 return null;
99 }
100
101 try {
102 layerElement.setAttribute("name", layer.getName());
103 }
104 catch(IOException ioe) {
105 logger.warn(
106 "Could not read layer name." +
107 " Stopped reading layer.");
108 throw new IOException("Error reading layer name.");
109 }
110
111 try {
112 layerElement.setAttribute("min_scale",
113 String.valueOf(layer.getMinimumScale()));
114 }
115 catch(IOException ioe) {
116 logger.warn("Could not read minimum scale.");
117 }
118
119 try {
120 layerElement.setAttribute("max_scale",
121 String.valueOf(layer.getMaximumScale()));
122 }
123 catch(IOException ioe) {
124 logger.warn(
125 "Could not read maximum scale.");
126 }
127
128 try {
129 if(layer.isVisible()) {
130 layerElement.setAttribute("status", "on");
131 }
132 else {
133 layerElement.setAttribute("status", "off");
134 }
135 }
136 catch(IOException ioe) {
137 logger.warn(
138 "Could not read layer status." +
139 " Setting layer status to \"on\".");
140 layerElement.setAttribute("status", "on");
141 }
142 try {
143 layerElement.setAttribute("data_source", layer.getFilePath());
144 }
145 catch(IOException ioe) {
146 logger.warn(
147 "Could not read datasource." +
148 " Stopped reading layer " + layer.getName() + ".");
149 util.removeLayer(layerElement);
150 return null;
151 }
152
153 // Static Attributes for Raster:
154 layerElement.setAttribute("type", "raster");
155 layerElement.setAttribute("connection_type", "local");
156
157 return layerElement;
158 }
159 }
160 // 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)