1 |
package skrueger.geotools; |
/******************************************************************************* |
2 |
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
import java.net.URL; |
* |
4 |
import java.util.Map; |
* This file is part of the SCHMITZM library - a collection of utility |
5 |
import java.util.HashMap; |
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
import javax.swing.ImageIcon; |
* and the Geotools library. |
7 |
|
* |
8 |
import org.geotools.styling.Style; |
* The SCHMITZM project is hosted at: |
9 |
import org.geotools.feature.FeatureCollection; |
* http://wald.intevation.org/projects/schmitzm/ |
10 |
import org.geotools.feature.FeatureType; |
* |
11 |
import org.geotools.feature.AttributeType; |
* 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 |
import schmitzm.geotools.feature.FeatureUtil; |
* as published by the Free Software Foundation; either version 3 |
14 |
|
* of the License, or (at your option) any later version. |
15 |
import skrueger.i8n.Translation; |
* |
16 |
import skrueger.AttributeMetaData; |
* 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 |
* This class provides a simple implementation of {@link StyledMapInterface} |
* |
21 |
* for {@link FeatureCollection}. The uncache functionality is not supported, |
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
* because this class bases on an existing {@link FeatureCollection} object in |
* along with this program; if not, write to the Free Software |
23 |
* memory. |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany) |
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
* @version 1.0 |
* |
26 |
*/ |
* Contributors: |
27 |
public class StyledFeatureCollection extends AbstractStyledMap<FeatureCollection> implements StyledFeatureCollectionInterface { |
* Martin O. J. Schmitz - initial API and implementation |
28 |
|
* Stefan A. Krüger - additional utility classes |
29 |
/** Holds the meta data for displaying a legend. */ |
******************************************************************************/ |
30 |
protected Map<Integer,AttributeMetaData> attrMetaData = null; |
package skrueger.geotools; |
31 |
|
|
32 |
/** |
import java.io.IOException; |
33 |
* Creates a styled {@link FeatureCollection} with language-specific informations. |
import java.net.URL; |
34 |
* @param fc the {@link FeatureCollection} |
|
35 |
* @param id a unique ID for the object |
import javax.swing.ImageIcon; |
36 |
* @param title a (language-specific) short description |
|
37 |
* @param desc a (language-specific) long description |
import org.geotools.data.FeatureSource; |
38 |
* @param keywords (language-specific) keywords for the geo objects |
import org.geotools.data.collection.CollectionDataStore; |
39 |
* @param style a display style (if {@code null}, a default style is created) |
import org.geotools.data.store.EmptyFeatureCollection; |
40 |
* @param attrMetaData meta data for displaying a legend |
import org.geotools.feature.FeatureCollection; |
41 |
* @param icon an icon for the object (can be {@code null}) |
import org.geotools.feature.collection.SubFeatureCollection; |
42 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
import org.geotools.styling.Style; |
43 |
*/ |
import org.opengis.feature.simple.SimpleFeature; |
44 |
public StyledFeatureCollection(FeatureCollection fc, String id, Translation title, Translation desc, Translation keywords, Style style, Map<Integer,AttributeMetaData> attrMetaData, ImageIcon icon) { |
import org.opengis.feature.simple.SimpleFeatureType; |
45 |
super(fc, fc.getBounds(), fc.getSchema().getDefaultGeometry().getCoordinateSystem(), id, title, desc, keywords, style, icon); |
import org.opengis.feature.type.AttributeDescriptor; |
46 |
setAttributeMetaData( attrMetaData ); |
import org.opengis.filter.Filter; |
47 |
} |
|
48 |
|
import schmitzm.geotools.feature.FeatureUtil; |
49 |
/** |
import skrueger.AttributeMetadata; |
50 |
* Creates a styled {@link FeatureCollection} with language-specific informations. |
import skrueger.i8n.Translation; |
51 |
* @param fc the {@link FeatureCollection} |
|
52 |
* @param id a unique ID for the object |
/** |
53 |
* @param title a (language-specific) short description |
* This class provides a simple implementation of {@link StyledLayerInterface} |
54 |
* @param desc a (language-specific) long description |
* for {@link FeatureCollection}. The uncache functionality is not supported, |
55 |
* @param keywords (language-specific) keywords for the geo objects |
* because this class bases on an existing {@link FeatureCollection} object in |
56 |
* @param style a display style with attribute meta data information |
* memory. |
57 |
* @param icon an icon for the object (can be {@code null}) |
* |
58 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
59 |
*/ |
* (University of Bonn/Germany) |
60 |
public StyledFeatureCollection(FeatureCollection fc, String id, Translation title, Translation desc, Translation keywords, StyledMapStyle<Map<Integer,AttributeMetaData>> style, ImageIcon icon) { |
* @version 1.0 |
61 |
super(fc, fc.getBounds(), fc.getSchema().getDefaultGeometry().getCoordinateSystem(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon); |
*/ |
62 |
setAttributeMetaData( style != null ? style.getMetaData() : null ); |
public class StyledFeatureCollection |
63 |
} |
extends |
64 |
|
AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature>> |
65 |
/** |
implements StyledFeatureCollectionInterface { |
66 |
* Creates a styled {@link FeatureCollection} with a language-specific title, |
|
67 |
* no long description, no keywords, default attribute meta data and no icon. |
/** Holds the meta data for displaying a legend. */ |
68 |
* @param fc the {@link FeatureCollection} |
protected AttributeMetadataMap attrMetaData = null; |
69 |
* @param id a unique ID for the object |
|
70 |
* @param title a short description |
/** |
71 |
* @param style a display style (if {@code null}, a default style is created) |
* We be filled with a "virtual" {@link FeatureSource} on demand. |
72 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
*/ |
73 |
* @see #createDefaultAttributeMetaDataMap(FeatureCollection) |
private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null; |
74 |
*/ |
|
75 |
public StyledFeatureCollection(FeatureCollection fc, String id, Translation title, Style style) { |
/** |
76 |
this(fc, id, title, null, null, style, null, null); |
* A Filter that will be applied internally applied to this |
77 |
} |
* FeatureCollection |
78 |
|
**/ |
79 |
/** |
private Filter filter = Filter.INCLUDE; |
80 |
* Creates a styled {@link FeatureCollection} with non-translated informations. |
|
81 |
* @param fc the {@link FeatureCollection} |
/** |
82 |
* @param id a unique ID for the object |
* Creates a styled {@link FeatureCollection} with language-specific |
83 |
* @param title a short description |
* informations. |
84 |
* @param desc a long description |
* |
85 |
* @param keywords keywords for the geo objects |
* @param fc |
86 |
* @param style a display style (if {@code null}, a default style is created) |
* the {@link FeatureCollection} |
87 |
* @param attrMetaData meta data for displaying a legend |
* @param id |
88 |
* @param icon an icon for the object (can be {@code null}) |
* a unique ID for the object |
89 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
* @param title |
90 |
*/ |
* a (language-specific) short description |
91 |
public StyledFeatureCollection(FeatureCollection fc, String id, String title, String desc, String keywords, Style style, Map<Integer,AttributeMetaData> attrMetaData, ImageIcon icon) { |
* @param desc |
92 |
this(fc, id, (Translation)null, null, null, style, attrMetaData, icon); |
* a (language-specific) long description |
93 |
setTitle(title); |
* @param keywords |
94 |
setDesc(desc); |
* (language-specific) keywords for the geo objects |
95 |
setKeywords(keywords); |
* @param style |
96 |
} |
* a display style (if {@code null}, a default style is created) |
97 |
|
* @param attrMetaData |
98 |
/** |
* meta data for displaying a legend |
99 |
* Creates a styled {@link FeatureCollection} with non-translated informations. |
* @param icon |
100 |
* @param fc the {@link FeatureCollection} |
* an icon for the object (can be {@code null}) |
101 |
* @param id a unique ID for the object |
* @exception IllegalArgumentException |
102 |
* @param title a short description |
* if {@code null} is given as ID or geo object |
103 |
* @param desc a long description |
*/ |
104 |
* @param keywords keywords for the geo objects |
public StyledFeatureCollection( |
105 |
* @param style a display style with attribute meta data information |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id, |
106 |
* @param icon an icon for the object (can be {@code null}) |
Translation title, Translation desc, Translation keywords, |
107 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
Style style, AttributeMetadataMap attrMetaData, ImageIcon icon) { |
108 |
*/ |
super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor() |
109 |
public StyledFeatureCollection(FeatureCollection fc, String id, String title, String desc, String keywords, StyledMapStyle<Map<Integer,AttributeMetaData>> style, ImageIcon icon) { |
.getCoordinateReferenceSystem(), id, title, desc, keywords, |
110 |
this(fc, |
style, icon); |
111 |
id, |
setAttributeMetaData(attrMetaData); |
112 |
title, |
} |
113 |
desc, |
|
114 |
keywords, |
/** |
115 |
style != null ? style.getGeoObjectStyle() : null, |
* Creates a styled {@link FeatureCollection} with language-specific |
116 |
style != null ? style.getMetaData() : null, |
* informations. |
117 |
icon |
* |
118 |
); |
* @param fc |
119 |
} |
* the {@link FeatureCollection} |
120 |
|
* @param id |
121 |
/** |
* a unique ID for the object |
122 |
* Creates a styled {@link FeatureCollection} with a non-translated title, |
* @param title |
123 |
* no long description, no keywords, default attribute meta data and no icon. |
* a (language-specific) short description |
124 |
* @param fc the {@link FeatureCollection} |
* @param desc |
125 |
* @param id a unique ID for the object |
* a (language-specific) long description |
126 |
* @param title a short description |
* @param keywords |
127 |
* @param style a display style (if {@code null}, a default style is created) |
* (language-specific) keywords for the geo objects |
128 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
* @param style |
129 |
* @see #createDefaultAttributeMetaDataMap(FeatureCollection) |
* a display style with attribute meta data information |
130 |
*/ |
* @param icon |
131 |
public StyledFeatureCollection(FeatureCollection fc, String id, String title, Style style) { |
* an icon for the object (can be {@code null}) |
132 |
this(fc, id, title, null, null, style, null, null); |
* @exception IllegalArgumentException |
133 |
} |
* if {@code null} is given as ID or geo object |
134 |
|
*/ |
135 |
/** |
public StyledFeatureCollection( |
136 |
* Creates a styled {@link FeatureCollection} with a non-translated title, |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id, |
137 |
* no long description, no keywords, default attribute meta data and no icon. |
Translation title, Translation desc, Translation keywords, |
138 |
* @param fc the {@link FeatureCollection} |
StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) { |
139 |
* @param id a unique ID for the object |
super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor() |
140 |
* @param title a short description |
.getCoordinateReferenceSystem(), id, title, desc, keywords, |
141 |
* @param style a display style (if {@code null}, a default style is created) |
style != null ? style.getGeoObjectStyle() : null, icon); |
142 |
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
setAttributeMetaData(style != null ? style.getMetaData() : null); |
143 |
* @see #createDefaultAttributeMetaDataMap(FeatureCollection) |
} |
144 |
*/ |
|
145 |
public StyledFeatureCollection(FeatureCollection fc, String id, String title, StyledMapStyle<Map<Integer,AttributeMetaData>> style) { |
/** |
146 |
this( |
* Creates a styled {@link FeatureCollection} with a language-specific |
147 |
fc, |
* title, no long description, no keywords, default attribute meta data and |
148 |
id, |
* no icon. |
149 |
title, |
* |
150 |
null, |
* @param fc |
151 |
null, |
* the {@link FeatureCollection} |
152 |
style != null ? style.getGeoObjectStyle() : null, |
* @param id |
153 |
style != null ? style.getMetaData() : null, |
* a unique ID for the object |
154 |
null |
* @param title |
155 |
); |
* a short description |
156 |
} |
* @param style |
157 |
|
* a display style (if {@code null}, a default style is created) |
158 |
/** |
* @exception IllegalArgumentException |
159 |
* Creates a default style for the {@link FeatureCollection}. |
* if {@code null} is given as ID or geo object |
160 |
* @see FeatureUtil#createDefaultStyle(FeatureCollection) |
* @see #createDefaultAttributeMetaDataMap(FeatureCollection) |
161 |
*/ |
*/ |
162 |
protected Style createDefaultStyle() { |
public StyledFeatureCollection( |
163 |
return FeatureUtil.createDefaultStyle( geoObject ); |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id, |
164 |
} |
Translation title, Style style) { |
165 |
|
this(fc, id, title, null, null, style, null, null); |
166 |
/** |
} |
167 |
* Returns the meta data needed for displaying a legend. |
|
168 |
*/ |
/** |
169 |
public Map<Integer,AttributeMetaData> getAttributeMetaDataMap() { |
* Creates a styled {@link FeatureCollection} with non-translated |
170 |
return attrMetaData; |
* informations. |
171 |
} |
* |
172 |
|
* @param fc |
173 |
/** |
* the {@link FeatureCollection} |
174 |
* Sets the meta data needed for displaying a legend. |
* @param id |
175 |
* If {@code legendData} is {@code null} an empty map is set, so |
* a unique ID for the object |
176 |
* {@link #getAttributeMetaDataMap()} never returns {@code null}. |
* @param title |
177 |
* @param attrMetaData map of attribute meta data |
* a short description |
178 |
*/ |
* @param desc |
179 |
public void setAttributeMetaData(Map<Integer,AttributeMetaData> attrMetaData) { |
* a long description |
180 |
this.attrMetaData = (attrMetaData != null) ? attrMetaData : createDefaultAttributeMetaDataMap(geoObject); |
* @param keywords |
181 |
} |
* keywords for the geo objects |
182 |
|
* @param style |
183 |
/** |
* a display style (if {@code null}, a default style is created) |
184 |
* Creates non-translated default meta data for a {@link FeatureCollection} |
* @param attrMetaData |
185 |
* with all attributes visible and no unit set. |
* meta data for displaying a legend |
186 |
* @param fc a {@link FeatureCollection} |
* @param icon |
187 |
*/ |
* an icon for the object (can be {@code null}) |
188 |
public static Map<Integer,AttributeMetaData> createDefaultAttributeMetaDataMap(FeatureCollection fc) { |
* @exception IllegalArgumentException |
189 |
HashMap<Integer,AttributeMetaData> metaDataMap = new HashMap<Integer,AttributeMetaData>(); |
* if {@code null} is given as ID or geo object |
190 |
FeatureType ftype = fc.getSchema(); |
*/ |
191 |
for (int i=0; i<ftype.getAttributeCount(); i++) { |
public StyledFeatureCollection( |
192 |
AttributeType aType = ftype.getAttributeType(i); |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id, |
193 |
if ( aType != ftype.getDefaultGeometry() ) |
String title, String desc, String keywords, Style style, |
194 |
metaDataMap.put( |
AttributeMetadataMap attrMetaData, ImageIcon icon) { |
195 |
i, |
this(fc, id, (Translation) null, null, null, style, attrMetaData, icon); |
196 |
new AttributeMetaData( |
setTitle(title); |
197 |
i, // Column no. |
setDesc(desc); |
198 |
true, // visible |
setKeywords(keywords); |
199 |
new Translation( aType.getName() ), // Column name |
} |
200 |
new Translation(), // description |
|
201 |
"" // Unit |
/** |
202 |
) |
* Creates a styled {@link FeatureCollection} with non-translated |
203 |
); |
* informations. |
204 |
} |
* |
205 |
return metaDataMap; |
* @param fc |
206 |
} |
* the {@link FeatureCollection} |
207 |
|
* @param id |
208 |
/** |
* a unique ID for the object |
209 |
* Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and |
* @param title |
210 |
* {@link #attrMetaData} to {@code null}. |
* a short description |
211 |
*/ |
* @param desc |
212 |
public void dispose() { |
* a long description |
213 |
this.geoObject = null; |
* @param keywords |
214 |
this.envelope = null; |
* keywords for the geo objects |
215 |
this.crs = null; |
* @param style |
216 |
this.attrMetaData = null; |
* a display style with attribute meta data information |
217 |
} |
* @param icon |
218 |
|
* an icon for the object (can be {@code null}) |
219 |
/** |
* @exception IllegalArgumentException |
220 |
* Tests whether the geo object is disposed. |
* if {@code null} is given as ID or geo object |
221 |
*/ |
*/ |
222 |
public boolean isDisposed() { |
public StyledFeatureCollection( |
223 |
return geoObject == null; |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id, |
224 |
} |
String title, String desc, String keywords, |
225 |
|
StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) { |
226 |
/** |
this(fc, id, title, desc, keywords, style != null ? style |
227 |
* Does nothing, because the {@link AbstractStyledMap} bases on existing |
.getGeoObjectStyle() : null, style != null ? style |
228 |
* objects (in memory) which can not be uncached and reloaded. |
.getMetaData() : null, icon); |
229 |
*/ |
} |
230 |
public void uncache() { |
|
231 |
LOGGER.warn("Uncache functionality is not supported. Object remains in memory."); |
/** |
232 |
} |
* Creates a styled {@link FeatureCollection} with a non-translated title, |
233 |
|
* no long description, no keywords, default attribute meta data and no |
234 |
|
* icon. |
235 |
/* |
* |
236 |
* (non-Javadoc) |
* @param fc |
237 |
* @see skrueger.geotools.StyledMapInterface#getInfoURL() |
* the {@link FeatureCollection} |
238 |
*/ |
* @param id |
239 |
public URL getInfoURL() { |
* a unique ID for the object |
240 |
return null; |
* @param title |
241 |
} |
* a short description |
242 |
|
* @param style |
243 |
/** |
* a display style (if {@code null}, a default style is created) |
244 |
* If true, this layer will not be shown in the legend. Default = false |
* @exception IllegalArgumentException |
245 |
*/ |
* if {@code null} is given as ID or geo object |
246 |
/** |
* @see #createDefaultAttributeMetaDataMap(FeatureCollection) |
247 |
* |
*/ |
248 |
* Killed by SK: 6. April 09: Ein Layer soll nicht generell auf |
public StyledFeatureCollection( |
249 |
* verstecken/nicht verstecken gestellt werden können. Das sind |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id, |
250 |
* Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer. |
String title, Style style) { |
251 |
* Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer |
this(fc, id, title, null, null, style, null, null); |
252 |
* nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher |
} |
253 |
* die Funktion genutzt. |
|
254 |
* |
/** |
255 |
public boolean isHideInLegend() { |
* Creates a styled {@link FeatureCollection} with a non-translated title, |
256 |
return false; |
* no long description, no keywords, default attribute meta data and no |
257 |
} |
* icon. |
258 |
*/ |
* |
259 |
} |
* @param fc |
260 |
|
* the {@link FeatureCollection} |
261 |
|
* @param id |
262 |
|
* a unique ID for the object |
263 |
|
* @param title |
264 |
|
* a short description |
265 |
|
* @param style |
266 |
|
* a display style (if {@code null}, a default style is created) |
267 |
|
* @exception IllegalArgumentException |
268 |
|
* if {@code null} is given as ID or geo object |
269 |
|
* @see #createDefaultAttributeMetaDataMap(FeatureCollection) |
270 |
|
*/ |
271 |
|
public StyledFeatureCollection( |
272 |
|
FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id, |
273 |
|
String title, StyledLayerStyle<AttributeMetadataMap> style) { |
274 |
|
this(fc, id, title, null, null, style != null ? style |
275 |
|
.getGeoObjectStyle() : null, style != null ? style |
276 |
|
.getMetaData() : null, null); |
277 |
|
} |
278 |
|
|
279 |
|
/** |
280 |
|
* Creates a default style for the {@link FeatureCollection}. |
281 |
|
* |
282 |
|
* @see FeatureUtil#createDefaultStyle(FeatureCollection) |
283 |
|
*/ |
284 |
|
protected Style createDefaultStyle() { |
285 |
|
return FeatureUtil.createDefaultStyle(geoObject); |
286 |
|
} |
287 |
|
|
288 |
|
/** |
289 |
|
* Returns the meta data needed for displaying a legend. |
290 |
|
*/ |
291 |
|
public AttributeMetadataMap getAttributeMetaDataMap() { |
292 |
|
return attrMetaData; |
293 |
|
} |
294 |
|
|
295 |
|
/** |
296 |
|
* Sets the meta data needed for displaying a legend. If {@code legendData} |
297 |
|
* is {@code null} an empty map is set, so |
298 |
|
* {@link #getAttributeMetaDataMap()} never returns {@code null}. |
299 |
|
* |
300 |
|
* @param attrMetaData |
301 |
|
* map of attribute meta data |
302 |
|
*/ |
303 |
|
public void setAttributeMetaData(AttributeMetadataMap attrMetaData) { |
304 |
|
this.attrMetaData = (attrMetaData != null) ? attrMetaData |
305 |
|
: createDefaultAttributeMetaDataMap(geoObject); |
306 |
|
} |
307 |
|
|
308 |
|
/** |
309 |
|
* Creates non-translated default meta data for a {@link FeatureCollection} |
310 |
|
* with all attributes visible and no unit set. |
311 |
|
* |
312 |
|
* @param fc |
313 |
|
* a {@link FeatureCollection} |
314 |
|
*/ |
315 |
|
public static AttributeMetadataMap createDefaultAttributeMetaDataMap( |
316 |
|
FeatureCollection<SimpleFeatureType, SimpleFeature> fc) { |
317 |
|
AttributeMetadataMap metaDataMap = new AttributeMetadataMap(); |
318 |
|
SimpleFeatureType ftype = fc.getSchema(); |
319 |
|
for (int i = 0; i < ftype.getAttributeCount(); i++) { |
320 |
|
AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i); |
321 |
|
if (aDesc != ftype.getGeometryDescriptor()) |
322 |
|
metaDataMap.put(aDesc.getName(), new AttributeMetadata(aDesc.getName(), |
323 |
|
true, // visible |
324 |
|
new Translation(aDesc.getLocalName()), // Column name |
325 |
|
new Translation(aDesc.getLocalName()), // description |
326 |
|
"" // Unit |
327 |
|
)); |
328 |
|
} |
329 |
|
return metaDataMap; |
330 |
|
} |
331 |
|
|
332 |
|
/** |
333 |
|
* Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and |
334 |
|
* {@link #attrMetaData} to {@code null}. |
335 |
|
*/ |
336 |
|
public void dispose() { |
337 |
|
this.geoObject = null; |
338 |
|
this.envelope = null; |
339 |
|
this.crs = null; |
340 |
|
this.attrMetaData = null; |
341 |
|
} |
342 |
|
|
343 |
|
/** |
344 |
|
* Tests whether the geo object is disposed. |
345 |
|
*/ |
346 |
|
public boolean isDisposed() { |
347 |
|
return geoObject == null; |
348 |
|
} |
349 |
|
|
350 |
|
/** |
351 |
|
* Does nothing, because the {@link AbstractStyledLayer} bases on existing |
352 |
|
* objects (in memory) which can not be uncached and reloaded. |
353 |
|
*/ |
354 |
|
public void uncache() { |
355 |
|
|
356 |
|
/** It will be recreated on the next getFetureSource() **/ |
357 |
|
featureSource = null; |
358 |
|
|
359 |
|
LOGGER |
360 |
|
.warn("Uncache onyl uncached any virtual FeatureSource. Object remains in memory."); |
361 |
|
} |
362 |
|
|
363 |
|
/* |
364 |
|
* (non-Javadoc) |
365 |
|
* |
366 |
|
* @see skrueger.geotools.StyledLayerInterface#getInfoURL() |
367 |
|
*/ |
368 |
|
public URL getInfoURL() { |
369 |
|
return null; |
370 |
|
} |
371 |
|
|
372 |
|
/** |
373 |
|
* Same as {@link #getGeoObject()} method, but complies to the |
374 |
|
* {@link StyledFeaturesInterface}. The associated {@link Filter} is NOT |
375 |
|
* automatically applied. |
376 |
|
* |
377 |
|
* @see {@link StyledFeaturesInterface} |
378 |
|
* @see #getFeatureCollectionFiltered() |
379 |
|
*/ |
380 |
|
@Override |
381 |
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() { |
382 |
|
return getGeoObject(); |
383 |
|
} |
384 |
|
|
385 |
|
/** |
386 |
|
* Same as {@link #getGeoObject()} method, but complies to the |
387 |
|
* {@link StyledFeaturesInterface}. The associated {@link Filter} is |
388 |
|
* automatically applied by creating a {@link SubFeatureCollection}. |
389 |
|
* |
390 |
|
* @see {@link StyledFeaturesInterface} |
391 |
|
* @see #getFeatureCollectionFiltered() |
392 |
|
*/ |
393 |
|
@Override |
394 |
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() { |
395 |
|
final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection(); |
396 |
|
if (filter == Filter.EXCLUDE) |
397 |
|
return new EmptyFeatureCollection(fc.getSchema()); |
398 |
|
if (filter == Filter.INCLUDE) |
399 |
|
return fc; |
400 |
|
return fc.subCollection(filter); |
401 |
|
} |
402 |
|
|
403 |
|
/** |
404 |
|
* Returns a virtual {@link FeatureSource} to access the |
405 |
|
* {@link FeatureCollection}. Once created, it will be reused until |
406 |
|
* {@link #uncache()} is called.<br/> |
407 |
|
* |
408 |
|
* @see {@link StyledFeaturesInterface} |
409 |
|
*/ |
410 |
|
@Override |
411 |
|
public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() { |
412 |
|
if (featureSource == null) { |
413 |
|
CollectionDataStore store = new CollectionDataStore(getGeoObject()); |
414 |
|
try { |
415 |
|
featureSource = store.getFeatureSource(store.getTypeNames()[0]); |
416 |
|
} catch (IOException e) { |
417 |
|
throw new RuntimeException( |
418 |
|
"Could not create a FeatureSource from the CollectionDataStore:", |
419 |
|
e); |
420 |
|
} |
421 |
|
} |
422 |
|
return featureSource; |
423 |
|
} |
424 |
|
|
425 |
|
@Override |
426 |
|
public Filter getFilter() { |
427 |
|
return filter; |
428 |
|
} |
429 |
|
|
430 |
|
@Override |
431 |
|
public void setFilter(Filter filter) { |
432 |
|
this.filter = filter; |
433 |
|
} |
434 |
|
|
435 |
|
@Override |
436 |
|
public SimpleFeatureType getSchema() { |
437 |
|
return getGeoObject().getSchema(); |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
|
} |