42 |
import org.geotools.data.FeatureSource; |
import org.geotools.data.FeatureSource; |
43 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
44 |
import org.geotools.feature.NameImpl; |
import org.geotools.feature.NameImpl; |
45 |
|
import org.geotools.geometry.jts.ReferencedEnvelope; |
46 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
47 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
48 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
77 |
* A unique ID which identifies the Layer in the Atlas. It's more important |
* A unique ID which identifies the Layer in the Atlas. It's more important |
78 |
* than it should be ;-) |
* than it should be ;-) |
79 |
*/ |
*/ |
80 |
private String id; |
final private String id; |
81 |
|
|
82 |
private Style style; |
private Style style; |
83 |
|
|
102 |
* @param sldFile |
* @param sldFile |
103 |
* may be <code>null</code>. Otherwise the SLD {@link File} to |
* may be <code>null</code>. Otherwise the SLD {@link File} to |
104 |
* import and associate with this {@link StyledFS} |
* import and associate with this {@link StyledFS} |
105 |
|
* |
106 |
|
* @param id |
107 |
|
* <code>null</code> is allowed and will autogenerate an id |
108 |
*/ |
*/ |
109 |
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, |
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, |
110 |
File sldFile) { |
File sldFile, String id) { |
111 |
|
|
112 |
this.fs = fs; |
this.fs = fs; |
113 |
|
|
114 |
id = StyledFS.class.getSimpleName() |
if (id == null) { |
115 |
+ new Random(new Date().getTime()).nextInt(10000000); |
this.id = StyledFS.class.getSimpleName() |
116 |
|
+ new Random(new Date().getTime()).nextInt(10000000); |
117 |
|
} else { |
118 |
|
this.id = id; |
119 |
|
} |
120 |
|
|
121 |
this.sldFile = sldFile; |
this.sldFile = sldFile; |
122 |
|
|
141 |
} |
} |
142 |
|
|
143 |
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) { |
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) { |
144 |
this(fs, null); |
this(fs, (File) null, null); |
145 |
|
} |
146 |
|
|
147 |
|
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, |
148 |
|
String id) { |
149 |
|
this(fs, null, id); |
150 |
} |
} |
151 |
|
|
152 |
public void dispose() { |
public void dispose() { |
169 |
public CoordinateReferenceSystem getCrs() { |
public CoordinateReferenceSystem getCrs() { |
170 |
if (crs == null) { |
if (crs == null) { |
171 |
crs = fs.getSchema().getCoordinateReferenceSystem(); |
crs = fs.getSchema().getCoordinateReferenceSystem(); |
172 |
if (fs.getSchema().getCoordinateReferenceSystem() == null) { |
if (crs == null) { |
173 |
LOGGER.warn("Could not determine the CRS of " + getTitle() |
|
174 |
+ ". Using default " + GeoImportUtil.getDefaultCRS()); |
crs = fs.getSchema().getGeometryDescriptor() |
175 |
crs = GeoImportUtil.getDefaultCRS(); |
.getCoordinateReferenceSystem(); |
176 |
|
|
177 |
|
if (crs == null) { |
178 |
|
LOGGER.warn("Could not determine the CRS of " + getTitle() |
179 |
|
+ ". Using default " |
180 |
|
+ GeoImportUtil.getDefaultCRS()); |
181 |
|
crs = GeoImportUtil.getDefaultCRS(); |
182 |
|
} |
183 |
} |
} |
184 |
} |
} |
185 |
return crs; |
return crs; |
295 |
// with Translations ;-) |
// with Translations ;-) |
296 |
AttributeMetadataImpl attMetaData = new AttributeMetadataImpl( |
AttributeMetadataImpl attMetaData = new AttributeMetadataImpl( |
297 |
new NameImpl(attDesc.getName().getNamespaceURI(), |
new NameImpl(attDesc.getName().getNamespaceURI(), |
298 |
attDesc.getName().getLocalPart()), map |
attDesc.getName().getLocalPart()), |
299 |
.getLanguages()); |
map.getLanguages()); |
300 |
if (String.class.isAssignableFrom(attDesc.getType() |
if (String.class.isAssignableFrom(attDesc.getType() |
301 |
.getBinding())) { |
.getBinding())) { |
302 |
// For Strings we add the "" as NODATA values |
// For Strings we add the "" as NODATA values |
312 |
* @return The {@link File} where the SLD was loaded from or |
* @return The {@link File} where the SLD was loaded from or |
313 |
* <code>null</code> if there didn't exist a {@link File}. |
* <code>null</code> if there didn't exist a {@link File}. |
314 |
* |
* |
315 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
|
* Tzeggai</a> |
|
316 |
*/ |
*/ |
317 |
public File getSldFile() { |
public File getSldFile() { |
318 |
return sldFile; |
return sldFile; |
319 |
} |
} |
320 |
|
|
321 |
|
/** |
322 |
|
* Associates this .sld with the {@link FeatureSource}, but does not |
323 |
|
* automatically load the file. It must not even exist. |
324 |
|
* |
325 |
|
* @param sldFile |
326 |
|
*/ |
327 |
public void setSldFile(File sldFile) { |
public void setSldFile(File sldFile) { |
328 |
this.sldFile = sldFile; |
this.sldFile = sldFile; |
329 |
} |
} |
367 |
// return fc.subCollection(filter); |
// return fc.subCollection(filter); |
368 |
|
|
369 |
try { |
try { |
370 |
return getFeatureSource().getFeatures(filter); |
if (filter != Filter.INCLUDE) |
371 |
|
return getFeatureSource().getFeatures(filter); |
372 |
|
else |
373 |
|
return getFeatureSource().getFeatures(); |
374 |
} catch (IOException e) { |
} catch (IOException e) { |
375 |
throw new RuntimeException(e); |
throw new RuntimeException(e); |
376 |
} |
} |
394 |
/** |
/** |
395 |
* Tries to load a style from the file denoted in {@link #getSldFile()}. If |
* Tries to load a style from the file denoted in {@link #getSldFile()}. If |
396 |
* the file doesn't exits, return <code>null</code>; |
* the file doesn't exits, return <code>null</code>; |
397 |
|
* |
398 |
* @return <code>true</code> is style was loaded |
* @return <code>true</code> is style was loaded |
399 |
*/ |
*/ |
400 |
public boolean loadStyle() { |
public boolean loadStyle() { |
401 |
if (getSldFile() == null) |
if (getSldFile() == null) |
402 |
return false; |
return false; |
403 |
|
|
404 |
try { |
try { |
405 |
Style[] loadSLD = StylingUtil.loadSLD(getSldFile()); |
Style[] loadSLD = StylingUtil.loadSLD(getSldFile()); |
406 |
setStyle(loadSLD[0]); |
setStyle(loadSLD[0]); |
411 |
|
|
412 |
} |
} |
413 |
|
|
414 |
|
public void setTitle(String title) { |
415 |
|
setTitle(new Translation(title)); |
416 |
|
} |
417 |
|
|
418 |
|
public void setDesc(String desc) { |
419 |
|
setDesc(new Translation(desc)); |
420 |
|
} |
421 |
|
|
422 |
|
public void setCRS(CoordinateReferenceSystem crs2) { |
423 |
|
crs = crs2; |
424 |
|
} |
425 |
|
|
426 |
|
@Override |
427 |
|
public ReferencedEnvelope getReferencedEnvelope() { |
428 |
|
return new ReferencedEnvelope(getEnvelope(), getCrs()); |
429 |
|
} |
430 |
|
|
431 |
} |
} |