25 |
* |
* |
26 |
* Contributors: |
* Contributors: |
27 |
* Martin O. J. Schmitz - initial API and implementation |
* Martin O. J. Schmitz - initial API and implementation |
28 |
* Stefan A. Krüger - additional utility classes |
* Stefan A. Tzeggai - additional utility classes |
29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.geotools; |
package skrueger.geotools; |
31 |
|
|
35 |
|
|
36 |
import org.geotools.coverage.grid.GridCoverage2D; |
import org.geotools.coverage.grid.GridCoverage2D; |
37 |
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader; |
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader; |
38 |
|
import org.geotools.geometry.jts.ReferencedEnvelope; |
39 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
40 |
|
|
41 |
import schmitzm.geotools.JTSUtil; |
import schmitzm.geotools.JTSUtil; |
45 |
|
|
46 |
/** |
/** |
47 |
* This class provides a simple implementation of {@link StyledLayerInterface} |
* This class provides a simple implementation of {@link StyledLayerInterface} |
48 |
* for {@link AbstractGridCoverage2DReader}. The uncache functionality is not supported, |
* for {@link AbstractGridCoverage2DReader}. The uncache functionality is not |
49 |
* because if the coverage is read once this class bases on an existing {@link GridCoverage2D} |
* supported, because if the coverage is read once this class bases on an |
50 |
* object in memory. |
* existing {@link GridCoverage2D} object in memory. |
51 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany) |
* |
52 |
|
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
53 |
|
* (University of Bonn/Germany) |
54 |
* @version 1.0 |
* @version 1.0 |
55 |
*/ |
*/ |
56 |
public class StyledGridCoverageReader extends AbstractStyledLayer<AbstractGridCoverage2DReader> implements StyledGridCoverageReaderInterface { |
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 |
/** Holds the meta data for displaying a legend. */ |
/** |
266 |
protected RasterLegendData legendData = null; |
* Returns the meta data needed for displaying a legend. |
267 |
|
*/ |
268 |
|
public RasterLegendData getLegendMetaData() { |
269 |
|
return legendData; |
270 |
|
} |
271 |
|
|
272 |
/** |
/** |
273 |
* Creates a styled grid with language-specific informations. |
* Sets the meta data needed for displaying a legend. If {@code legendData} |
274 |
* @param gcr the grid reader |
* is {@code null} an empty {@link RasterLegendData} (without gaps) is set, |
275 |
* @param id a unique ID for the object |
* so {@link #getLegendMetaData()} never returns {@code null}. |
276 |
* @param title a (language-specific) short description |
* |
277 |
* @param desc a (language-specific) long description |
* @param legendData |
278 |
* @param keywords (language-specific) keywords for the geo objects |
* legend meta data |
279 |
* @param style a display style (if {@code null}, a default style is created) |
*/ |
280 |
* @param legendData meta data for displaying a legend |
public void setLegendMetaData(RasterLegendData legendData) { |
281 |
* @param icon an icon for the object (can be {@code null}) |
this.legendData = (legendData != null) ? legendData |
282 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
: new RasterLegendData(false); |
283 |
*/ |
} |
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) { |
|
|
super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style, icon); |
|
|
setLegendMetaData(legendData); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Creates a styled grid with language-specific informations. |
|
|
* @param gcr the grid reader |
|
|
* @param id a unique ID for the object |
|
|
* @param title a (language-specific) short description |
|
|
* @param desc a (language-specific) long description |
|
|
* @param keywords (language-specific) keywords for the geo objects |
|
|
* @param style a display style with legend information |
|
|
* @param icon an icon for the object (can be {@code null}) |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
|
|
*/ |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) { |
|
|
super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon); |
|
|
setLegendMetaData( style != null ? style.getMetaData() : null ); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Creates a styled grid with a language-specific title, no long description, no |
|
|
* keywords and no icon. |
|
|
* @param gcr the grid reader |
|
|
* @param id a unique ID for the object |
|
|
* @param title a short description |
|
|
* @param style a display style (if {@code null}, a default style is created) |
|
|
* @param legendData meta data for displaying a legend |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
|
|
*/ |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Style style, RasterLegendData legendData) { |
|
|
this(gcr, id, title, null, null, style, legendData, null); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Creates a styled grid with non-translated informations. |
|
|
* @param gcr the grid reader |
|
|
* @param id a unique ID for the object |
|
|
* @param title a short description |
|
|
* @param desc a long description |
|
|
* @param keywords keywords for the geo objects |
|
|
* @param style a display style (if {@code null}, a default style is created) |
|
|
* @param legendData meta data for displaying a legend |
|
|
* @param icon an icon for the object (can be {@code null}) |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
|
|
*/ |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, Style style, RasterLegendData legendData, ImageIcon icon) { |
|
|
this(gcr, id, (Translation)null, null, null, style, legendData, icon); |
|
|
setTitle(title); |
|
|
setDesc(desc); |
|
|
setKeywords(keywords); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Creates a styled grid with non-translated informations. |
|
|
* @param gcr the grid reader |
|
|
* @param id a unique ID for the object |
|
|
* @param title a short description |
|
|
* @param desc a long description |
|
|
* @param keywords keywords for the geo objects |
|
|
* @param style a display style with legend information |
|
|
* @param icon an icon for the object (can be {@code null}) |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
|
|
*/ |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) { |
|
|
this(gcr, |
|
|
id, |
|
|
title, |
|
|
desc, |
|
|
keywords, |
|
|
style != null ? style.getGeoObjectStyle() : null, |
|
|
style != null ? style.getMetaData() : null, |
|
|
icon |
|
|
); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Creates a styled grid with a non-translated title, no long description, no |
|
|
* keywords and no icon. |
|
|
* @param gcr the grid reader |
|
|
* @param id a unique ID for the object |
|
|
* @param title a short description |
|
|
* @param style a display style (if {@code null}, a default style is created) |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
|
|
*/ |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, Style style, RasterLegendData legendData) { |
|
|
this(gcr, id, title, null, null, style, legendData, null); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Creates a styled grid with a non-translated title, no long description, no |
|
|
* keywords and no icon. |
|
|
* @param gcr the grid reader |
|
|
* @param id a unique ID for the object |
|
|
* @param title a short description |
|
|
* @param style a display style with legend information |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
|
|
*/ |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, StyledLayerStyle<RasterLegendData> style) { |
|
|
this(gcr, |
|
|
id, |
|
|
title, |
|
|
null, |
|
|
null, |
|
|
style != null ? style.getGeoObjectStyle() : null, |
|
|
style != null ? style.getMetaData() : null, |
|
|
null |
|
|
); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Creates a default style for a {@link GridCoverage2D}. |
|
|
* @see GridUtil#createDefaultStyle() |
|
|
*/ |
|
|
protected Style createDefaultStyle() { |
|
|
return GridUtil.createDefaultStyle(); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Returns the meta data needed for displaying a legend. |
|
|
*/ |
|
|
public RasterLegendData getLegendMetaData() { |
|
|
return legendData; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Sets the meta data needed for displaying a legend. |
|
|
* If {@code legendData} is {@code null} an empty {@link RasterLegendData} |
|
|
* (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}. |
|
|
* @param legendData legend meta data |
|
|
*/ |
|
|
public void setLegendMetaData(RasterLegendData legendData) { |
|
|
this.legendData = (legendData != null) ? legendData : new RasterLegendData(false); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and |
|
|
* {@link #legendData} to {@code null}. |
|
|
*/ |
|
|
public void dispose() { |
|
|
this.geoObject = null; |
|
|
this.envelope = null; |
|
|
this.crs = null; |
|
|
this.legendData = null; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Tests whether the geo object is disposed. |
|
|
* @return boolean |
|
|
*/ |
|
|
public boolean isDisposed() { |
|
|
return geoObject == null; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Does nothing, because the {@link AbstractStyledLayer} bases on existing |
|
|
* objects (in memory) which can not be uncached and reloaded. |
|
|
*/ |
|
|
public void uncache() { |
|
|
LOGGER.warn("Uncache functionality is not supported. Object remains in memory."); |
|
|
} |
|
|
|
|
|
/* |
|
|
* (non-Javadoc) |
|
|
* @see skrueger.geotools.StyledLayerInterface#getInfoURL() |
|
|
*/ |
|
|
public URL getInfoURL() { |
|
|
return null; |
|
|
} |
|
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 |
* If true, this layer will not be shown in the legend. Default = false |
324 |
*/ |
*/ |
325 |
/** |
/** |
331 |
* nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher |
* nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher |
332 |
* die Funktion genutzt. |
* die Funktion genutzt. |
333 |
* |
* |
334 |
public boolean isHideInLegend() { |
* public boolean isHideInLegend() { return false; } |
|
return false; |
|
|
} |
|
335 |
*/ |
*/ |
336 |
|
|
337 |
} |
} |