/[schmitzm]/trunk/src/skrueger/geotools/StyledGridCoverageReader.java
ViewVC logotype

Contents of /trunk/src/skrueger/geotools/StyledGridCoverageReader.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1212 - (show annotations)
Wed Nov 3 10:49:38 2010 UTC (14 years, 3 months ago) by alfonx
File size: 11225 byte(s)
* Moved testing resources (shp, raster) from gpcore, ascore etc to schmitzm
* added a special directory for the testresources.. 

1 /*******************************************************************************
2 * Copyright (c) 2009 Martin O. J. Schmitz.
3 *
4 * This file is part of the SCHMITZM library - a collection of utility
5 * classes based on Java 1.6, focusing (not only) on Java Swing
6 * and the Geotools library.
7 *
8 * The SCHMITZM project is hosted at:
9 * http://wald.intevation.org/projects/schmitzm/
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License (license.txt)
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * or try this link: http://www.gnu.org/licenses/lgpl.html
25 *
26 * Contributors:
27 * Martin O. J. Schmitz - initial API and implementation
28 * Stefan A. Tzeggai - additional utility classes
29 ******************************************************************************/
30 package skrueger.geotools;
31
32 import java.net.URL;
33
34 import javax.swing.ImageIcon;
35
36 import org.geotools.coverage.grid.GridCoverage2D;
37 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
38 import org.geotools.geometry.jts.ReferencedEnvelope;
39 import org.geotools.styling.Style;
40
41 import schmitzm.geotools.JTSUtil;
42 import schmitzm.geotools.grid.GridUtil;
43 import skrueger.RasterLegendData;
44 import skrueger.i8n.Translation;
45
46 /**
47 * This class provides a simple implementation of {@link StyledLayerInterface}
48 * for {@link AbstractGridCoverage2DReader}. The uncache functionality is not
49 * supported, because if the coverage is read once this class bases on an
50 * existing {@link GridCoverage2D} object in memory.
51 *
52 * @author <a href="mailto:[email protected]">Martin Schmitz</a>
53 * (University of Bonn/Germany)
54 * @version 1.0
55 */
56 public class StyledGridCoverageReader extends
57 AbstractStyledLayer<AbstractGridCoverage2DReader> implements
58 StyledGridCoverageReaderInterface {
59 @Override
60 public ReferencedEnvelope getReferencedEnvelope() {
61 return new ReferencedEnvelope(getEnvelope(), getCrs());
62 }
63
64 /** Holds the meta data for displaying a legend. */
65 protected RasterLegendData legendData = null;
66
67 /**
68 * Creates a styled grid with language-specific informations.
69 *
70 * @param gcr
71 * the grid reader
72 * @param id
73 * a unique ID for the object
74 * @param title
75 * a (language-specific) short description
76 * @param desc
77 * a (language-specific) long description
78 * @param keywords
79 * (language-specific) keywords for the geo objects
80 * @param style
81 * a display style (if {@code null}, a default style is created)
82 * @param legendData
83 * meta data for displaying a legend
84 * @param icon
85 * an icon for the object (can be {@code null})
86 * @exception IllegalArgumentException
87 * if {@code null} is given as ID or geo object
88 */
89 public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
90 String id, Translation title, Translation desc,
91 Translation keywords, Style style, RasterLegendData legendData,
92 ImageIcon icon) {
93 super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
94 .getCrs(), id, title, desc, keywords, style, icon);
95 setLegendMetaData(legendData);
96 }
97
98 /**
99 * Creates a styled grid with language-specific informations.
100 *
101 * @param gcr
102 * the grid reader
103 * @param id
104 * a unique ID for the object
105 * @param title
106 * a (language-specific) short description
107 * @param desc
108 * a (language-specific) long description
109 * @param keywords
110 * (language-specific) keywords for the geo objects
111 * @param style
112 * a display style with legend information
113 * @param icon
114 * an icon for the object (can be {@code null})
115 * @exception IllegalArgumentException
116 * if {@code null} is given as ID or geo object
117 */
118 public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
119 String id, Translation title, Translation desc,
120 Translation keywords, StyledLayerStyle<RasterLegendData> style,
121 ImageIcon icon) {
122 super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
123 .getCrs(), id, title, desc, keywords, style != null ? style
124 .getGeoObjectStyle() : null, icon);
125 setLegendMetaData(style != null ? style.getMetaData() : null);
126 }
127
128 /**
129 * Creates a styled grid with a language-specific title, no long
130 * description, no keywords and no icon.
131 *
132 * @param gcr
133 * the grid reader
134 * @param id
135 * a unique ID for the object
136 * @param title
137 * a short description
138 * @param style
139 * a display style (if {@code null}, a default style is created)
140 * @param legendData
141 * meta data for displaying a legend
142 * @exception IllegalArgumentException
143 * if {@code null} is given as ID or geo object
144 */
145 public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
146 String id, Translation title, Style style,
147 RasterLegendData legendData) {
148 this(gcr, id, title, null, null, style, legendData, null);
149 }
150
151 /**
152 * Creates a styled grid with non-translated informations.
153 *
154 * @param gcr
155 * the grid reader
156 * @param id
157 * a unique ID for the object
158 * @param title
159 * a short description
160 * @param desc
161 * a long description
162 * @param keywords
163 * keywords for the geo objects
164 * @param style
165 * a display style (if {@code null}, a default style is created)
166 * @param legendData
167 * meta data for displaying a legend
168 * @param icon
169 * an icon for the object (can be {@code null})
170 * @exception IllegalArgumentException
171 * if {@code null} is given as ID or geo object
172 */
173 public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
174 String id, String title, String desc, String keywords, Style style,
175 RasterLegendData legendData, ImageIcon icon) {
176 this(gcr, id, (Translation) null, null, null, style, legendData, icon);
177 setTitle(title);
178 setDesc(desc);
179 setKeywords(keywords);
180 }
181
182 /**
183 * Creates a styled grid with non-translated informations.
184 *
185 * @param gcr
186 * the grid reader
187 * @param id
188 * a unique ID for the object
189 * @param title
190 * a short description
191 * @param desc
192 * a long description
193 * @param keywords
194 * keywords for the geo objects
195 * @param style
196 * a display style with legend information
197 * @param icon
198 * an icon for the object (can be {@code null})
199 * @exception IllegalArgumentException
200 * if {@code null} is given as ID or geo object
201 */
202 public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
203 String id, String title, String desc, String keywords,
204 StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
205 this(gcr, id, title, desc, keywords, style != null ? style
206 .getGeoObjectStyle() : null, style != null ? style
207 .getMetaData() : null, icon);
208 }
209
210 /**
211 * Creates a styled grid with a non-translated title, no long description,
212 * no keywords and no icon.
213 *
214 * @param gcr
215 * the grid reader
216 * @param id
217 * a unique ID for the object
218 * @param title
219 * a short description
220 * @param style
221 * a display style (if {@code null}, a default style is created)
222 * @exception IllegalArgumentException
223 * if {@code null} is given as ID or geo object
224 */
225 public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
226 String id, String title, Style style, RasterLegendData legendData) {
227 this(gcr, id, title, null, null, style, legendData, null);
228 }
229
230 /**
231 * Creates a styled grid with a non-translated title, no long description,
232 * no keywords and no icon.
233 *
234 * @param gcr
235 * the grid reader
236 * @param id
237 * a unique ID for the object
238 * @param title
239 * a short description
240 * @param style
241 * a display style with legend information
242 * @exception IllegalArgumentException
243 * if {@code null} is given as ID or geo object
244 */
245 public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
246 String id, String title, StyledLayerStyle<RasterLegendData> style) {
247 this(gcr, id, title, null, null, style != null ? style
248 .getGeoObjectStyle() : null, style != null ? style
249 .getMetaData() : null, null);
250 }
251
252 public StyledGridCoverageReader(AbstractGridCoverage2DReader reader) {
253 this(reader, "", "", null, null);
254 }
255
256 /**
257 * Creates a default style for a {@link GridCoverage2D}.
258 *
259 * @see GridUtil#createDefaultStyle()
260 */
261 protected Style createDefaultStyle() {
262 return GridUtil.createDefaultStyle();
263 }
264
265 /**
266 * Returns the meta data needed for displaying a legend.
267 */
268 public RasterLegendData getLegendMetaData() {
269 return legendData;
270 }
271
272 /**
273 * Sets the meta data needed for displaying a legend. If {@code legendData}
274 * is {@code null} an empty {@link RasterLegendData} (without gaps) is set,
275 * so {@link #getLegendMetaData()} never returns {@code null}.
276 *
277 * @param legendData
278 * legend meta data
279 */
280 public void setLegendMetaData(RasterLegendData legendData) {
281 this.legendData = (legendData != null) ? legendData
282 : new RasterLegendData(false);
283 }
284
285 /**
286 * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
287 * {@link #legendData} to {@code null}.
288 */
289 public void dispose() {
290 this.geoObject = null;
291 this.envelope = null;
292 this.crs = null;
293 this.legendData = null;
294 }
295
296 /**
297 * Tests whether the geo object is disposed.
298 *
299 * @return boolean
300 */
301 public boolean isDisposed() {
302 return geoObject == null;
303 }
304
305 /**
306 * Does nothing, because the {@link AbstractStyledLayer} bases on existing
307 * objects (in memory) which can not be uncached and reloaded.
308 */
309 public void uncache() {
310 LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
311 }
312
313 /*
314 * (non-Javadoc)
315 *
316 * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
317 */
318 public URL getInfoURL() {
319 return null;
320 }
321
322 /**
323 * If true, this layer will not be shown in the legend. Default = false
324 */
325 /**
326 *
327 * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
328 * verstecken/nicht verstecken gestellt werden können. Das sind
329 * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
330 * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
331 * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
332 * die Funktion genutzt.
333 *
334 * public boolean isHideInLegend() { return false; }
335 */
336
337 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26