comparison src/java/de/intevation/mxd/reader/GraphicsSubLayerReader.java @ 321:b6c0fbae16dc

Expand Graphics Layer Support
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 20 Sep 2012 17:58:29 +0200
parents
children
comparison
equal deleted inserted replaced
320:9289b7c1b4ce 321:b6c0fbae16dc
1 /*
2 * Copyright (c) 2012 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 * Andre Heinecke <aheinecke@intevation.de>
19 */
20
21 package de.intevation.mxd.reader;
22
23 import org.apache.log4j.Logger;
24
25 import com.esri.arcgis.carto.IGraphicsLayer;
26 import com.esri.arcgis.carto.ILayer;
27 import com.esri.arcgis.carto.GraphicsSubLayer;
28 import com.esri.arcgis.globecore.GlobeGraphicsLayer;
29 import com.esri.arcgis.analyst3d.GraphicsLayer3D;
30 import com.esri.arcgis.carto.GraphicsSubLayer;
31 import com.esri.arcgis.carto.FDOGraphicsLayer;
32
33 import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection;
34 import com.esri.arcgis.carto.IAnnotateLayerProperties;
35 import com.esri.arcgis.carto.LabelEngineLayerProperties;
36 import com.esri.arcgis.carto.IElement;
37 import com.esri.arcgis.carto.TextElement;
38 import com.esri.arcgis.system.IName;
39 import com.esri.arcgis.system.IPropertySet;
40 import com.esri.arcgis.geometry.Envelope;
41 import com.esri.arcgis.geometry.ISpatialReference;
42 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
43 import com.esri.arcgis.geometry.GeographicCoordinateSystem;
44 import com.esri.arcgis.geometry.UnknownCoordinateSystem;
45 import com.esri.arcgis.geometry.Projection;
46 import com.esri.arcgis.geometry.IPoint;
47
48 import com.esri.arcgis.display.ITextSymbol;
49 import com.esri.arcgis.display.TextSymbol;
50
51 import org.w3c.dom.Element;
52
53 import de.intevation.mxd.utils.MapToXMLUtils;
54 import java.io.IOException;
55 import com.esri.arcgis.interop.AutomationException;
56 /**
57 * Reads Layer information.
58 *
59 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a>
60 */
61 public class GraphicsSubLayerReader
62 implements ILayerReader {
63
64 /**
65 * The logger.
66 */
67 private static final Logger logger =
68 Logger.getLogger(GraphicsSubLayerReader.class);
69
70 /**
71 * Privte member.
72 */
73 private GraphicsSubLayer layer;
74 private MapToXMLUtils util;
75
76 /**
77 * Constructor with layer.
78 *
79 * @param layer The ArcGIS layer object.
80 */
81 public GraphicsSubLayerReader(GraphicsSubLayer layer) {
82 this.layer = layer;
83 }
84
85 /**
86 * Setter for XML document helper.
87 *
88 * @param util The helper for storing map information.
89 */
90 public void setUtil(MapToXMLUtils util) {
91 this.util = util;
92 }
93
94 /**
95 * Reads the Layer content.
96 *
97 * @return The layer XML element.
98 */
99 public Element read()
100 throws IOException{
101 logger.debug("read()");
102 Element layerElement = null;
103 try {
104 layerElement = util.addLayer();
105 }
106 catch(Exception e) {
107 logger.error("Failed to create DOM-Element for Layer.");
108 return null;
109 }
110
111 // Name
112 try {
113 layerElement.setAttribute("name", layer.getName());
114
115 }
116 catch(Exception e) {
117 logger.warn(
118 "Could not read layer name." +
119 " Stopped reading layer.");
120 throw new IOException("Error reading layer name.");
121 }
122
123 // Scale
124 try {
125 layerElement.setAttribute("min_scale",
126 String.valueOf(layer.getMinimumScale()));
127 }
128 catch(IOException ioe) {
129 logger.warn("Could not read minimum scale.");
130 }
131
132 try {
133 layerElement.setAttribute("max_scale",
134 String.valueOf(layer.getMaximumScale()));
135 }
136 catch(Exception e) {
137 logger.warn(
138 "Could not read maximum scale.");
139 }
140
141 // Status
142 try {
143 if(layer.isVisible()) {
144 layerElement.setAttribute("status", "on");
145 }
146 else {
147 layerElement.setAttribute("status", "off");
148 }
149 }
150 catch(Exception e) {
151 logger.warn(
152 "Could not read layer status." +
153 " Setting layer status to \"on\".");
154 layerElement.setAttribute("status", "on");
155 }
156
157 // Read the elements
158 try {
159 int count = 0;
160 IElement actElement = null;
161 IElement prevElement = null;
162 layer.reset(); // Reset the element container
163 actElement = layer.next();
164 while (actElement != prevElement) {
165 prevElement = actElement;
166 if (actElement instanceof TextElement) {
167 TextElement te = (TextElement)actElement;
168 Element xmlTextElement = util.addFeature(layerElement);
169 xmlTextElement.setAttribute("text", te.getText());
170
171 IPoint poi = te.getGeometry().getEnvelope().getLowerLeft();
172 xmlTextElement.setAttribute("X", String.valueOf(poi.getX()));
173 xmlTextElement.setAttribute("Y", String.valueOf(poi.getY()));
174 xmlTextElement.setAttribute("classId", String.valueOf(count));
175
176 try {
177 ITextSymbol sym = te.getSymbol();
178 if(sym instanceof TextSymbol) {
179 TextSymbolReader tsr = new TextSymbolReader(sym);
180 tsr.setParent(xmlTextElement);
181 tsr.setUtil(util);
182 tsr.read();
183 } else {
184 logger.warn("Unknwon Symbol of class: " +
185 sym.getClass().toString());
186 }
187 }
188 catch(Exception e) {
189 logger.warn("Could not read element text symbol.");
190 }
191 } else {
192 logger.warn("Unhandled Element of class: " +
193 actElement.getClass().toString() +
194 " in conversion of layer: " +
195 layer.getName());
196 }
197 count++;
198 actElement = layer.next();
199 }
200 }
201 catch(Exception e) {
202 logger.warn("Could not read layer elements.");
203 logger.debug(e);
204 }
205
206 // Static values for this layer
207 layerElement.setAttribute("type", "annotation");
208
209 return layerElement;
210 }
211 }
212 // 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)