Mercurial > mxd2map
annotate src/java/de/intevation/mxd/reader/RasterLayerReader.java @ 347:02d3c1665a46
Shorten long paths for better pdf representation
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 16 Nov 2012 17:02:33 +0100 |
parents | 5e3a40a84539 |
children |
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.system.IName; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 import com.esri.arcgis.system.IPropertySet; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 import com.esri.arcgis.geometry.Projection; |
303
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 import org.w3c.dom.Element; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 import de.intevation.mxd.utils.MapToXMLUtils; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 import java.io.IOException; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 import com.esri.arcgis.interop.AutomationException; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 /** |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 * Reads Layer information. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 * |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a> |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
47 */ |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
48 public class RasterLayerReader |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
49 implements ILayerReader { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
50 |
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 * The logger. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
53 */ |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
54 private static final Logger logger = |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
55 Logger.getLogger(RasterLayerReader.class); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
56 |
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 * Privte member. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 */ |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
60 private RasterLayer layer; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
61 private MapToXMLUtils util; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
62 |
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 * Constructor with layer. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 * |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 * @param layer The ArcGIS layer object. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 */ |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
68 public RasterLayerReader(ILayer layer) |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 throws Exception { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 if(layer instanceof RasterLayer) { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
71 this.layer = (RasterLayer)layer; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 } |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 else { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
74 throw new Exception("Not an instance of RasterLayer: " + |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
75 layer.getClass().toString()); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
76 } |
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 * Setter for XML document helper. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 * |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 * @param util The helper for storing map information. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 */ |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
84 public void setUtil(MapToXMLUtils util) { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 this.util = util; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
86 } |
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 * Reads the Layer content. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 * |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
91 * @return The layer XML element. |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
92 */ |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
93 public Element read() |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
94 throws IOException{ |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
95 logger.debug("read()"); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
96 Element layerElement; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
97 try { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
98 layerElement = util.addLayer(); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
99 } |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
100 catch(Exception e) { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
101 logger.error("Failed to create DOM-Element for Layer."); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 return null; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 } |
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 try { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 layerElement.setAttribute("name", layer.getName()); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
107 } |
306
ea3fde77ea48
Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents:
303
diff
changeset
|
108 catch(Exception e) { |
303
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
109 logger.warn( |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
110 "Could not read layer name." + |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
111 " Stopped reading layer."); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
112 throw new IOException("Error reading layer name."); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
113 } |
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 try { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
116 layerElement.setAttribute("min_scale", |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
117 String.valueOf(layer.getMinimumScale())); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
118 } |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
119 catch(IOException ioe) { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
120 logger.warn("Could not read minimum scale."); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
121 } |
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 try { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
124 layerElement.setAttribute("max_scale", |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
125 String.valueOf(layer.getMaximumScale())); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
126 } |
306
ea3fde77ea48
Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents:
303
diff
changeset
|
127 catch(Exception e) { |
303
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
128 logger.warn( |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
129 "Could not read maximum scale."); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
130 } |
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 try { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
133 if(layer.isVisible()) { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
134 layerElement.setAttribute("status", "on"); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
135 } |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
136 else { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 layerElement.setAttribute("status", "off"); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
138 } |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
139 } |
306
ea3fde77ea48
Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents:
303
diff
changeset
|
140 catch(Exception e) { |
303
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
141 logger.warn( |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
142 "Could not read layer status." + |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
143 " Setting layer status to \"on\"."); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
144 layerElement.setAttribute("status", "on"); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
145 } |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
146 try { |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
147 layerElement.setAttribute("data_source", layer.getFilePath()); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
148 } |
306
ea3fde77ea48
Catch generic Exceptions to avoid leaking them and creating
Andre Heinecke <aheinecke@intevation.de>
parents:
303
diff
changeset
|
149 catch(Exception e) { |
303
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
150 logger.warn( |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
151 "Could not read datasource." + |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
152 " Stopped reading layer " + layer.getName() + "."); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
153 util.removeLayer(layerElement); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
154 return null; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
155 } |
307
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
156 try { |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
157 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
|
158 layerElement.setAttribute( |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
159 "extent_min_x", |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
160 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
|
161 layerElement.setAttribute( |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
162 "extent_max_x", |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
163 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
|
164 layerElement.setAttribute( |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
165 "extent_min_y", |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
166 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
|
167 layerElement.setAttribute( |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
168 "extent_max_y", |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
169 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
|
170 } |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
171 catch(Exception e) { |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
172 logger.warn( |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
173 "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
|
174 + layer.getName() + "."); |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
175 } |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
176 //Read the projection. |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
177 try { |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
178 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
|
179 int projection = 0; |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
180 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
|
181 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
|
182 projection = pcs.getFactoryCode(); |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
183 } |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
184 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
|
185 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
|
186 projection = gcs.getFactoryCode(); |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
187 } |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
188 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
|
189 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
|
190 projection = 0; |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
191 } |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
192 else{ |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
193 logger.debug( |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
194 "Unknown SpatialReference: " + |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
195 sr.getClass().toString()); |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
196 } |
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 if(projection == 0) { |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
199 logger.warn( |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
200 "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
|
201 " 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
|
202 } |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
203 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
|
204 } |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
205 catch(Exception e) { |
f9e53dcc7424
Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents:
306
diff
changeset
|
206 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
|
207 } |
303
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
208 |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
209 // Static Attributes for Raster: |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
210 layerElement.setAttribute("type", "raster"); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
211 layerElement.setAttribute("connection_type", "local"); |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
212 |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
213 return layerElement; |
a9684178cb29
Add RasterLayer Reader
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
214 } |
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |