41 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
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.geometry.jts.ReferencedEnvelope; |
45 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
46 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
47 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
|
import org.opengis.feature.type.AttributeDescriptor; |
|
48 |
import org.opengis.filter.Filter; |
import org.opengis.filter.Filter; |
49 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
50 |
|
|
51 |
|
import schmitzm.geotools.feature.FeatureUtil; |
52 |
|
import schmitzm.geotools.feature.FeatureUtil.GeometryForm; |
53 |
import schmitzm.geotools.io.GeoImportUtil; |
import schmitzm.geotools.io.GeoImportUtil; |
54 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
55 |
import skrueger.AttributeMetadataImpl; |
import skrueger.AttributeMetadataImpl; |
61 |
* This class enables a non Atlas context to use the Atlas LayerPanel |
* This class enables a non Atlas context to use the Atlas LayerPanel |
62 |
* {@link JPanel} as a {@link MapContextManagerInterface} |
* {@link JPanel} as a {@link MapContextManagerInterface} |
63 |
* |
* |
64 |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
65 |
* |
* |
66 |
* TODO Rename to StyledShapefile |
* TODO Rename to StyledShapefile |
67 |
*/ |
*/ |
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 |
|
|
88 |
private File sldFile; |
private File sldFile; |
89 |
|
|
90 |
/** A map of simple attribute names to their meta-data **/ |
/** A map of simple attribute names to their meta-data **/ |
91 |
private AttributeMetadataMap<AttributeMetadataImpl> map; |
private AttributeMetadataMap<AttributeMetadataImpl> attMap; |
92 |
|
|
93 |
private Filter filter = Filter.INCLUDE; |
private Filter filter = Filter.INCLUDE; |
94 |
|
|
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() { |
173 |
|
|
174 |
crs = fs.getSchema().getGeometryDescriptor() |
crs = fs.getSchema().getGeometryDescriptor() |
175 |
.getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
176 |
|
|
177 |
if (crs == null) { |
if (crs == null) { |
178 |
LOGGER.warn("Could not determine the CRS of " + getTitle() |
LOGGER.warn("Could not determine the CRS of " + getTitle() |
179 |
+ ". Using default " |
+ ". Using default " |
271 |
/** |
/** |
272 |
* |
* |
273 |
*/ |
*/ |
274 |
|
@Override |
275 |
public AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap() { |
public AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap() { |
276 |
if (map == null) { |
if (attMap == null) { |
277 |
|
attMap = StyledLayerUtil |
278 |
map = new AttributeMetadataImplMap(); |
.createDefaultAttributeMetadataMap(getSchema()); |
|
|
|
|
// // Leaving out the first one, it will be the_geom |
|
|
// for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) { |
|
|
// AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i); |
|
|
// |
|
|
// AttributeMetadataImpl attMetaData = new AttributeMetadataImpl( |
|
|
// new NameImpl(attDesc |
|
|
// .getName().getNamespaceURI(), attDesc |
|
|
// .getName().getLocalPart()), map.getLanguages()); |
|
|
// map.put(attDesc.getName(), attMetaData); |
|
|
// } |
|
|
|
|
|
// Leaving out the first one, it will be the_geom |
|
|
for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) { |
|
|
AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i); |
|
|
|
|
|
// TODO AttributeMetadataAS would be nicer, which would not work |
|
|
// with Translations ;-) |
|
|
AttributeMetadataImpl attMetaData = new AttributeMetadataImpl( |
|
|
new NameImpl(attDesc.getName().getNamespaceURI(), |
|
|
attDesc.getName().getLocalPart()), map |
|
|
.getLanguages()); |
|
|
if (String.class.isAssignableFrom(attDesc.getType() |
|
|
.getBinding())) { |
|
|
// For Strings we add the "" as NODATA values |
|
|
attMetaData.addNodataValue(""); |
|
|
} |
|
|
map.put(attDesc.getName(), attMetaData); |
|
|
} |
|
279 |
} |
} |
280 |
return map; |
return attMap; |
281 |
} |
} |
282 |
|
|
283 |
/** |
/** |
284 |
* @return The {@link File} where the SLD was loaded from or |
* @return The {@link File} where the SLD was loaded from or |
285 |
* <code>null</code> if there didn't exist a {@link File}. |
* <code>null</code> if there didn't exist a {@link File}. |
286 |
* |
* |
287 |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
288 |
*/ |
*/ |
289 |
public File getSldFile() { |
public File getSldFile() { |
290 |
return sldFile; |
return sldFile; |
291 |
} |
} |
292 |
|
|
293 |
|
/** |
294 |
|
* Associates this .sld with the {@link FeatureSource}, but does not |
295 |
|
* automatically load the file. It must not even exist. |
296 |
|
* |
297 |
|
* @param sldFile |
298 |
|
*/ |
299 |
public void setSldFile(File sldFile) { |
public void setSldFile(File sldFile) { |
300 |
this.sldFile = sldFile; |
this.sldFile = sldFile; |
301 |
} |
} |
339 |
// return fc.subCollection(filter); |
// return fc.subCollection(filter); |
340 |
|
|
341 |
try { |
try { |
342 |
return getFeatureSource().getFeatures(filter); |
if (filter != Filter.INCLUDE) |
343 |
|
return getFeatureSource().getFeatures(filter); |
344 |
|
else |
345 |
|
return getFeatureSource().getFeatures(); |
346 |
} catch (IOException e) { |
} catch (IOException e) { |
347 |
throw new RuntimeException(e); |
throw new RuntimeException(e); |
348 |
} |
} |
383 |
|
|
384 |
} |
} |
385 |
|
|
386 |
|
public void setTitle(String title) { |
387 |
|
setTitle(new Translation(title)); |
388 |
|
} |
389 |
|
|
390 |
|
public void setDesc(String desc) { |
391 |
|
setDesc(new Translation(desc)); |
392 |
|
} |
393 |
|
|
394 |
|
public void setCRS(CoordinateReferenceSystem crs2) { |
395 |
|
crs = crs2; |
396 |
|
} |
397 |
|
|
398 |
|
@Override |
399 |
|
public ReferencedEnvelope getReferencedEnvelope() { |
400 |
|
return new ReferencedEnvelope(getEnvelope(), getCrs()); |
401 |
|
} |
402 |
|
|
403 |
|
/** |
404 |
|
* Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm, |
405 |
|
* but can be set to override ANY. |
406 |
|
*/ |
407 |
|
private GeometryForm geometryForm; |
408 |
|
|
409 |
|
/** |
410 |
|
* Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm, |
411 |
|
* but can be set to override ANY. |
412 |
|
*/ |
413 |
|
|
414 |
|
@Override |
415 |
|
public GeometryForm getGeometryForm() { |
416 |
|
if (geometryForm == null) { |
417 |
|
geometryForm = FeatureUtil.getGeometryForm(getSchema()); |
418 |
|
} |
419 |
|
return geometryForm; |
420 |
|
} |
421 |
|
|
422 |
|
/** |
423 |
|
* Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm, |
424 |
|
* but can be set to override ANY. |
425 |
|
*/ |
426 |
|
public void setGeometryForm(GeometryForm geometryForm) { |
427 |
|
this.geometryForm = geometryForm; |
428 |
|
} |
429 |
|
|
430 |
} |
} |