38 |
|
|
39 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
40 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
41 |
|
import javax.xml.transform.TransformerException; |
42 |
|
|
43 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
44 |
import org.geotools.data.FeatureSource; |
import org.geotools.data.FeatureSource; |
|
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.jfree.util.AttributedStringUtilities; |
48 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
49 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
50 |
import org.opengis.feature.type.AttributeDescriptor; |
import org.opengis.feature.type.AttributeDescriptor; |
51 |
import org.opengis.filter.Filter; |
import org.opengis.filter.Filter; |
52 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
53 |
|
|
54 |
|
import schmitzm.geotools.io.GeoImportUtil; |
55 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
56 |
import skrueger.AttributeMetaData; |
import skrueger.AttributeMetadata; |
57 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
58 |
|
|
59 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
63 |
* {@link JPanel} as a {@link MapContextManagerInterface} |
* {@link JPanel} as a {@link MapContextManagerInterface} |
64 |
* |
* |
65 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
66 |
|
* |
67 |
|
* TODO Rename to StyledShapefile |
68 |
*/ |
*/ |
69 |
public class StyledFS implements StyledFeatureSourceInterface { |
public class StyledFS implements StyledFeatureSourceInterface { |
70 |
private static final Logger LOGGER = Logger.getLogger(StyledFS.class); |
private static final Logger LOGGER = Logger.getLogger(StyledFS.class); |
71 |
|
|
72 |
private final FeatureSource<SimpleFeatureType, SimpleFeature> fs; |
private final FeatureSource<SimpleFeatureType, SimpleFeature> fs; |
73 |
|
|
74 |
|
/** Caching the CRS of the layer **/ |
75 |
|
CoordinateReferenceSystem crs = null; |
76 |
|
|
77 |
/** |
/** |
78 |
* 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 |
107 |
File sldFile) { |
File sldFile) { |
108 |
|
|
109 |
this.fs = fs; |
this.fs = fs; |
110 |
|
|
111 |
id = StyledFS.class.getSimpleName() |
id = StyledFS.class.getSimpleName() |
112 |
+ new Random(new Date().getTime()).nextInt(10000000); |
+ new Random(new Date().getTime()).nextInt(10000000); |
113 |
|
|
114 |
this.sldFile = sldFile; |
this.sldFile = sldFile; |
115 |
|
|
116 |
|
// datei existiert, dann lesen |
117 |
if (sldFile != null && sldFile.exists()) { |
if (sldFile != null && sldFile.exists()) { |
118 |
try { |
try { |
119 |
style = StylingUtil.loadSLD(sldFile)[0]; |
style = StylingUtil.loadSLD(sldFile)[0]; |
|
} catch (FileNotFoundException e) { |
|
|
LOGGER |
|
|
.debug("The SLD file passed was empty. Leaving the Style untouched. (We are in the constructor.. so its null"); |
|
120 |
} catch (Exception e) { |
} catch (Exception e) { |
121 |
LOGGER.warn("Reading SLD failed: " + sldFile, e); |
LOGGER.warn("Reading SLD failed: " + sldFile, e); |
122 |
|
style = null; |
123 |
} |
} |
124 |
} |
} |
125 |
|
|
126 |
title = new Translation(); |
title = new Translation(); |
127 |
desc = new Translation(); |
desc = new Translation(); |
128 |
|
|
155 |
} |
} |
156 |
|
|
157 |
public CoordinateReferenceSystem getCrs() { |
public CoordinateReferenceSystem getCrs() { |
158 |
return fs.getSchema().getCoordinateReferenceSystem(); |
if (crs == null) { |
159 |
|
crs = fs.getSchema() |
160 |
|
.getCoordinateReferenceSystem(); |
161 |
|
if (fs.getSchema().getCoordinateReferenceSystem() == null) { |
162 |
|
LOGGER.warn("Could not determine the CRS of " + getTitle() |
163 |
|
+ ". Using default " + GeoImportUtil.getDefaultCRS()); |
164 |
|
crs = GeoImportUtil.getDefaultCRS(); |
165 |
|
} |
166 |
|
} |
167 |
|
return crs; |
168 |
} |
} |
169 |
|
|
170 |
public Translation getDesc() { |
public Translation getDesc() { |
256 |
public AttributeMetadataMap getAttributeMetaDataMap() { |
public AttributeMetadataMap getAttributeMetaDataMap() { |
257 |
if (map == null) { |
if (map == null) { |
258 |
|
|
259 |
map = new AttributeMetadataMap(); |
map = new AttributeMetadataMap(new String[] { Translation |
260 |
|
.getActiveLang() }); |
261 |
|
|
262 |
// Leaving out the first one, it will be the_geom |
// Leaving out the first one, it will be the_geom |
263 |
for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) { |
for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) { |
264 |
AttributeDescriptor att = fs.getSchema().getDescriptor(i); |
AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i); |
265 |
|
|
266 |
AttributeMetaData attMetaData = new AttributeMetaData(i, att |
AttributeMetadata attMetaData = new AttributeMetadata(attDesc |
267 |
.getLocalName()); |
.getName(), map.getLanguages()); |
268 |
map.put(i, attMetaData); |
map.put(attDesc.getName(), attMetaData); |
269 |
} |
} |
270 |
} |
} |
271 |
return map; |
return map; |
281 |
public File getSldFile() { |
public File getSldFile() { |
282 |
return sldFile; |
return sldFile; |
283 |
} |
} |
284 |
|
|
285 |
public void setSldFile(File sldFile) { |
public void setSldFile(File sldFile) { |
286 |
this.sldFile = sldFile; |
this.sldFile = sldFile; |
287 |
} |
} |
316 |
|
|
317 |
@Override |
@Override |
318 |
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() { |
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() { |
319 |
final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection(); |
// final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = |
320 |
if (filter == Filter.EXCLUDE) |
// getFeatureCollection(); |
321 |
return new EmptyFeatureCollection(fc.getSchema()); |
// if (filter == Filter.EXCLUDE) |
322 |
if (filter == Filter.INCLUDE) |
// return new EmptyFeatureCollection(fc.getSchema()); |
323 |
return fc; |
// if (filter == Filter.INCLUDE) |
324 |
return fc.subCollection(filter); |
// return fc; |
325 |
|
// return fc.subCollection(filter); |
326 |
|
|
327 |
|
try { |
328 |
|
return getFeatureSource().getFeatures(filter); |
329 |
|
} catch (IOException e) { |
330 |
|
throw new RuntimeException(e); |
331 |
|
} |
332 |
} |
} |
333 |
|
|
334 |
@Override |
@Override |