15 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
16 |
import org.geotools.data.FeatureSource; |
import org.geotools.data.FeatureSource; |
17 |
import org.geotools.feature.AttributeType; |
import org.geotools.feature.AttributeType; |
18 |
|
import org.geotools.feature.FeatureCollection; |
19 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
20 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
21 |
|
|
65 |
*/ |
*/ |
66 |
public StyledFS(FeatureSource fs, File sldFile) { |
public StyledFS(FeatureSource fs, File sldFile) { |
67 |
|
|
|
super(); |
|
68 |
this.fs = fs; |
this.fs = fs; |
69 |
id = StyledFS.class.getSimpleName() |
id = StyledFS.class.getSimpleName() |
70 |
+ new Random(new Date().getTime()).nextInt(10000000); |
+ new Random(new Date().getTime()).nextInt(10000000); |
77 |
} catch (FileNotFoundException e) { |
} catch (FileNotFoundException e) { |
78 |
LOGGER |
LOGGER |
79 |
.debug("The SLD file passed was empty. Leaving the Style untouched. (We are in the constructor.. so its null"); |
.debug("The SLD file passed was empty. Leaving the Style untouched. (We are in the constructor.. so its null"); |
80 |
|
} catch (Exception e) { |
81 |
|
LOGGER.warn("Reading SLD failed: " + sldFile, e); |
82 |
} |
} |
83 |
} |
} |
|
|
|
84 |
title = new Translation(); |
title = new Translation(); |
85 |
title.fromOneLine(sldFile.getName()); |
title.fromOneLine(sldFile.getName()); |
86 |
|
|
122 |
} |
} |
123 |
} |
} |
124 |
|
|
125 |
public FeatureSource getGeoObject() throws Exception { |
public FeatureSource getGeoObject() { |
126 |
return fs; |
return fs; |
127 |
} |
} |
128 |
|
|
166 |
* nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher |
* nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher |
167 |
* die Funktion genutzt. |
* die Funktion genutzt. |
168 |
* |
* |
169 |
// public boolean isHideInLegend() { |
* // public boolean isHideInLegend() { // return false; // } |
|
// return false; |
|
|
// } |
|
170 |
*/ |
*/ |
171 |
|
|
172 |
public void setDesc(Translation dec) { |
public void setDesc(Translation dec) { |
174 |
} |
} |
175 |
|
|
176 |
public void setImageIcon(ImageIcon icon) { |
public void setImageIcon(ImageIcon icon) { |
|
// TODO Auto-generated method stub |
|
|
|
|
177 |
} |
} |
178 |
|
|
179 |
public void setKeywords(Translation keywords) { |
public void setKeywords(Translation keywords) { |
192 |
public void uncache() { |
public void uncache() { |
193 |
} |
} |
194 |
|
|
195 |
|
/** |
196 |
|
* |
197 |
|
*/ |
198 |
public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() { |
public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() { |
199 |
if (map == null) { |
if (map == null) { |
200 |
|
|
201 |
map = new HashMap<Integer, AttributeMetaData>(); |
map = new HashMap<Integer, AttributeMetaData>(); |
202 |
|
|
203 |
// Leaving out the first one, it will be the_geom |
// Leaving out the first one, it will be the_geom |
204 |
for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) { |
for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) { |
205 |
AttributeType att = fs.getSchema().getAttributeType(i); |
AttributeType att = fs.getSchema().getAttributeType(i); |
206 |
|
|
207 |
AttributeMetaData attMetaData = new AttributeMetaData(i, att.getLocalName()); |
AttributeMetaData attMetaData = new AttributeMetaData(i, att |
208 |
|
.getLocalName()); |
209 |
map.put(i, attMetaData); |
map.put(i, attMetaData); |
210 |
} |
} |
211 |
} |
} |
214 |
|
|
215 |
/** |
/** |
216 |
* @return The {@link File} where the SLD was loaded from or |
* @return The {@link File} where the SLD was loaded from or |
217 |
* <code>null</code> if there didn't exist a {@link File}. (It |
* <code>null</code> if there didn't exist a {@link File}. (It could |
218 |
* could be a WFS or a PostGIS |
* be a WFS or a PostGIS |
219 |
* |
* |
220 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons |
221 |
|
* Krüger</a> |
222 |
*/ |
*/ |
223 |
public File getSldFile() { |
public File getSldFile() { |
224 |
return sldFile; |
return sldFile; |
228 |
this.sldFile = sldFile; |
this.sldFile = sldFile; |
229 |
} |
} |
230 |
|
|
231 |
|
/** |
232 |
|
* Returns the features of the {@link FeatureSource}. |
233 |
|
* |
234 |
|
* @see {@link StyledFeaturesInterface} |
235 |
|
*/ |
236 |
|
@Override |
237 |
|
public FeatureCollection getFeatureCollection() { |
238 |
|
FeatureCollection features; |
239 |
|
try { |
240 |
|
features = getGeoObject().getFeatures(); |
241 |
|
} catch (IOException e) { |
242 |
|
throw new RuntimeException( |
243 |
|
"Error getting the features of the FeatureSource"); |
244 |
|
} |
245 |
|
return features; |
246 |
|
} |
247 |
|
|
248 |
|
/** |
249 |
|
* Same as {@link #getGeoObject()} method, but complies to the |
250 |
|
* {@link StyledFeaturesInterface} |
251 |
|
* |
252 |
|
* @see {@link StyledFeaturesInterface} |
253 |
|
*/ |
254 |
|
@Override |
255 |
|
public FeatureSource getFeatureSource() { |
256 |
|
return getGeoObject(); |
257 |
|
} |
258 |
|
|
259 |
} |
} |