annotate src/java/de/intevation/mxd/reader/RasterLayerReader.java @ 307:f9e53dcc7424

Add Read/Write Support for Projections on a per Layer basis
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 06 Sep 2012 18:58:41 +0200
parents ea3fde77ea48
children 5e3a40a84539
rev   line source
303
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 /*
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 * This file is part of MXD2map.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 * This program is free software under the LGPL (>=v2.1)
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 * Read the file LICENCE.txt coming with the software for details
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 * or visit http://www.gnu.org/licenses/ if it does not exist.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 * MXD2map has been developed on behalf of the
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 * by Intevation GmbH.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 * Authors:
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 * Raimund Renkert <raimund.renkert@intevation.de>
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 * Stephan Holl <stephan.holl@intevation.de>
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 */
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 package de.intevation.mxd.reader;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 import org.apache.log4j.Logger;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 import com.esri.arcgis.carto.ILayer;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 import com.esri.arcgis.carto.RasterLayer;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 import com.esri.arcgis.carto.IAnnotateLayerProperties;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 import com.esri.arcgis.carto.LabelEngineLayerProperties;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 import com.esri.arcgis.geodatabase.RasterDatasetName;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 import com.esri.arcgis.system.IName;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 import com.esri.arcgis.system.IPropertySet;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 import com.esri.arcgis.geometry.Envelope;
307
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
33 import com.esri.arcgis.geometry.ISpatialReference;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
34 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
35 import com.esri.arcgis.geometry.GeographicCoordinateSystem;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
36 import com.esri.arcgis.geometry.UnknownCoordinateSystem;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
37 import com.esri.arcgis.geometry.Projection;
303
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 import org.w3c.dom.Element;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 import de.intevation.mxd.utils.MapToXMLUtils;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 import java.io.IOException;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 import com.esri.arcgis.interop.AutomationException;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 /**
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 * Reads Layer information.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a>
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 */
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 public class RasterLayerReader
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 implements ILayerReader {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 /**
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 * The logger.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 */
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 private static final Logger logger =
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 Logger.getLogger(RasterLayerReader.class);
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 /**
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 * Privte member.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 */
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 private RasterLayer layer;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 private MapToXMLUtils util;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 /**
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 * Constructor with layer.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 * @param layer The ArcGIS layer object.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 */
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 public RasterLayerReader(ILayer layer)
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 throws Exception {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 if(layer instanceof RasterLayer) {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72 this.layer = (RasterLayer)layer;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 else {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 throw new Exception("Not an instance of RasterLayer: " +
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 layer.getClass().toString());
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 /**
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 * Setter for XML document helper.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 * @param util The helper for storing map information.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 */
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 public void setUtil(MapToXMLUtils util) {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 this.util = util;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 /**
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 * Reads the Layer content.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
91 *
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 * @return The layer XML element.
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 */
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 public Element read()
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95 throws IOException{
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96 logger.debug("read()");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
97 Element layerElement;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
98 try {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
99 layerElement = util.addLayer();
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
100 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
101 catch(Exception e) {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
102 logger.error("Failed to create DOM-Element for Layer.");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
103 return null;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
104 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
105
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
106 try {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
107 layerElement.setAttribute("name", layer.getName());
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
108 }
306
ea3fde77ea48 Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents: 303
diff changeset
109 catch(Exception e) {
303
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
110 logger.warn(
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
111 "Could not read layer name." +
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
112 " Stopped reading layer.");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113 throw new IOException("Error reading layer name.");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
114 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
115
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
116 try {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
117 layerElement.setAttribute("min_scale",
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
118 String.valueOf(layer.getMinimumScale()));
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
119 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
120 catch(IOException ioe) {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
121 logger.warn("Could not read minimum scale.");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
122 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
123
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
124 try {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
125 layerElement.setAttribute("max_scale",
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
126 String.valueOf(layer.getMaximumScale()));
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
127 }
306
ea3fde77ea48 Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents: 303
diff changeset
128 catch(Exception e) {
303
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
129 logger.warn(
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
130 "Could not read maximum scale.");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
131 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
132
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
133 try {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
134 if(layer.isVisible()) {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
135 layerElement.setAttribute("status", "on");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
136 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
137 else {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
138 layerElement.setAttribute("status", "off");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
139 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
140 }
306
ea3fde77ea48 Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents: 303
diff changeset
141 catch(Exception e) {
303
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
142 logger.warn(
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
143 "Could not read layer status." +
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
144 " Setting layer status to \"on\".");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
145 layerElement.setAttribute("status", "on");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
146 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
147 try {
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
148 layerElement.setAttribute("data_source", layer.getFilePath());
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
149 }
306
ea3fde77ea48 Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents: 303
diff changeset
150 catch(Exception e) {
303
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
151 logger.warn(
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
152 "Could not read datasource." +
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
153 " Stopped reading layer " + layer.getName() + ".");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
154 util.removeLayer(layerElement);
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
155 return null;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
156 }
307
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
157 try {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
158 Envelope rect = (Envelope)layer.getExtent();
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
159 layerElement.setAttribute(
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
160 "extent_min_x",
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
161 String.valueOf(rect.getXMin ()));
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
162 layerElement.setAttribute(
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
163 "extent_max_x",
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
164 String.valueOf(rect.getXMax()));
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
165 layerElement.setAttribute(
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
166 "extent_min_y",
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
167 String.valueOf(rect.getYMin()));
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
168 layerElement.setAttribute(
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
169 "extent_max_y",
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
170 String.valueOf(rect.getYMax()));
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
171 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
172 catch(Exception e) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
173 logger.warn(
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
174 "Could not read extent from layer "
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
175 + layer.getName() + ".");
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
176 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
177 //Read the projection.
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
178 try {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
179 ISpatialReference sr = layer.getSpatialReference();
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
180 int projection = 0;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
181 if(sr instanceof ProjectedCoordinateSystem) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
182 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
183 projection = pcs.getFactoryCode();
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
184 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
185 else if(sr instanceof GeographicCoordinateSystem) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
186 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
187 projection = gcs.getFactoryCode();
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
188 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
189 else if(sr instanceof UnknownCoordinateSystem) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
190 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
191 projection = 0;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
192 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
193 else{
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
194 logger.debug(
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
195 "Unknown SpatialReference: " +
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
196 sr.getClass().toString());
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
197 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
198
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
199 if(projection == 0) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
200 logger.warn(
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
201 "Unknown projection for Layer:" + layer.getName() +
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
202 " Please edit projection in resulting mapfile.");
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
203 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
204 layerElement.setAttribute("projection", String.valueOf(projection));
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
205 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
206 catch(Exception e) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
207 logger.warn("Could not read layer projection.");
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
208 }
303
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
209
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
210 // Static Attributes for Raster:
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
211 layerElement.setAttribute("type", "raster");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
212 layerElement.setAttribute("connection_type", "local");
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
213
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
214 return layerElement;
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
215 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
216 }
a9684178cb29 Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
217 // 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)