41 |
|
|
42 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
43 |
import org.geotools.data.FeatureSource; |
import org.geotools.data.FeatureSource; |
44 |
|
import org.geotools.data.store.EmptyFeatureCollection; |
45 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
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; |
49 |
import org.opengis.feature.type.AttributeDescriptor; |
import org.opengis.feature.type.AttributeDescriptor; |
50 |
|
import org.opengis.filter.Filter; |
51 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
52 |
|
|
53 |
|
import schmitzm.geotools.io.GeoImportUtil; |
54 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
55 |
import skrueger.AttributeMetaData; |
import skrueger.AttributeMetaData; |
56 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
84 |
|
|
85 |
private AttributeMetadataMap map; |
private AttributeMetadataMap map; |
86 |
|
|
87 |
|
private Filter filter = Filter.INCLUDE; |
88 |
|
|
89 |
/** |
/** |
90 |
* This class enables a non Atlas context to use the Atlas LayerPanel |
* This class enables a non Atlas context to use the Atlas LayerPanel |
91 |
* {@link JPanel} as a {@link MapContextManagerInterface} |
* {@link JPanel} as a {@link MapContextManagerInterface} |
97 |
* may be <code>null</code>. Otherwise the SLD {@link File} to |
* may be <code>null</code>. Otherwise the SLD {@link File} to |
98 |
* import and associate with this {@link StyledFS} |
* import and associate with this {@link StyledFS} |
99 |
*/ |
*/ |
100 |
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, File sldFile) { |
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, |
101 |
|
File sldFile) { |
102 |
|
|
103 |
this.fs = fs; |
this.fs = fs; |
104 |
id = StyledFS.class.getSimpleName() |
id = StyledFS.class.getSimpleName() |
117 |
} |
} |
118 |
} |
} |
119 |
title = new Translation(); |
title = new Translation(); |
|
title.fromOneLine(sldFile.getName()); |
|
|
|
|
120 |
desc = new Translation(); |
desc = new Translation(); |
121 |
desc.fromOneLine(sldFile.getAbsolutePath()); |
|
122 |
|
if (sldFile != null) { |
123 |
|
title.fromOneLine(sldFile.getName()); |
124 |
|
desc.fromOneLine(sldFile.getAbsolutePath()); |
125 |
|
} |
126 |
|
|
127 |
|
} |
128 |
|
|
129 |
|
public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) { |
130 |
|
this(fs, null); |
131 |
} |
} |
132 |
|
|
133 |
public void dispose() { |
public void dispose() { |
148 |
} |
} |
149 |
|
|
150 |
public CoordinateReferenceSystem getCrs() { |
public CoordinateReferenceSystem getCrs() { |
151 |
return fs.getSchema().getCoordinateReferenceSystem(); |
CoordinateReferenceSystem crs = fs.getSchema().getCoordinateReferenceSystem(); |
152 |
|
if (fs.getSchema().getCoordinateReferenceSystem() == null) { |
153 |
|
LOGGER.warn("Could not determine the CRS of "+getTitle()+". Using default "+GeoImportUtil.getDefaultCRS()); |
154 |
|
crs = GeoImportUtil.getDefaultCRS(); |
155 |
|
} |
156 |
|
return crs; |
157 |
} |
} |
158 |
|
|
159 |
public Translation getDesc() { |
public Translation getDesc() { |
261 |
|
|
262 |
/** |
/** |
263 |
* @return The {@link File} where the SLD was loaded from or |
* @return The {@link File} where the SLD was loaded from or |
264 |
* <code>null</code> if there didn't exist a {@link File}. |
* <code>null</code> if there didn't exist a {@link File}. |
265 |
* |
* |
266 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
267 |
* Krüger</a> |
* Krüger</a> |
280 |
* @see {@link StyledFeaturesInterface} |
* @see {@link StyledFeaturesInterface} |
281 |
*/ |
*/ |
282 |
@Override |
@Override |
283 |
public FeatureCollection getFeatureCollection() { |
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() { |
284 |
FeatureCollection features; |
FeatureCollection<SimpleFeatureType, SimpleFeature> features; |
285 |
try { |
try { |
286 |
features = getGeoObject().getFeatures(); |
features = getGeoObject().getFeatures(); |
287 |
} catch (IOException e) { |
} catch (IOException e) { |
298 |
* @see {@link StyledFeaturesInterface} |
* @see {@link StyledFeaturesInterface} |
299 |
*/ |
*/ |
300 |
@Override |
@Override |
301 |
public FeatureSource getFeatureSource() { |
public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() { |
302 |
return getGeoObject(); |
return getGeoObject(); |
303 |
} |
} |
304 |
|
|
305 |
|
@Override |
306 |
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() { |
307 |
|
final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection(); |
308 |
|
if (filter == Filter.EXCLUDE) |
309 |
|
return new EmptyFeatureCollection(fc.getSchema()); |
310 |
|
if (filter == Filter.INCLUDE) |
311 |
|
return fc; |
312 |
|
return fc.subCollection(filter); |
313 |
|
} |
314 |
|
|
315 |
|
@Override |
316 |
|
public Filter getFilter() { |
317 |
|
return filter; |
318 |
|
} |
319 |
|
|
320 |
|
@Override |
321 |
|
public void setFilter(Filter filter) { |
322 |
|
this.filter = filter; |
323 |
|
} |
324 |
|
|
325 |
|
@Override |
326 |
|
public SimpleFeatureType getSchema() { |
327 |
|
return getGeoObject().getSchema(); |
328 |
|
} |
329 |
|
|
330 |
} |
} |