2 |
* Copyright (c) 2009 Martin O. J. Schmitz. |
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
* |
* |
4 |
* This file is part of the SCHMITZM library - a collection of utility |
* This file is part of the SCHMITZM library - a collection of utility |
5 |
* classes based on Java 1.6, focussing (not only) on Java Swing |
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
* and the Geotools library. |
* and the Geotools library. |
7 |
* |
* |
8 |
* The SCHMITZM project is hosted at: |
* The SCHMITZM project is hosted at: |
38 |
import org.geotools.data.FeatureSource; |
import org.geotools.data.FeatureSource; |
39 |
import org.geotools.data.Query; |
import org.geotools.data.Query; |
40 |
import org.geotools.data.memory.MemoryDataStore; |
import org.geotools.data.memory.MemoryDataStore; |
|
import org.geotools.feature.AttributeType; |
|
41 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
42 |
|
import org.opengis.feature.simple.SimpleFeature; |
43 |
|
import org.opengis.feature.simple.SimpleFeatureType; |
44 |
|
import org.opengis.feature.type.AttributeDescriptor; |
45 |
|
import org.opengis.feature.type.FeatureType; |
46 |
import org.opengis.filter.Filter; |
import org.opengis.filter.Filter; |
47 |
|
|
48 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
143 |
* {@link AttributeMetaData}-Map to define the visible attributes |
* {@link AttributeMetaData}-Map to define the visible attributes |
144 |
* and translation |
* and translation |
145 |
*/ |
*/ |
146 |
protected void setFeatureSource(FeatureSource fs, |
protected void setFeatureSource(FeatureSource<SimpleFeatureType, SimpleFeature> fs, |
147 |
Map<Integer, AttributeMetaData> amd, Filter filter) |
Map<Integer, AttributeMetaData> amd, Filter filter) |
148 |
throws Exception { |
throws Exception { |
149 |
if (filter == null) |
if (filter == null) |
159 |
|
|
160 |
bounds = fs.getBounds(); |
bounds = fs.getBounds(); |
161 |
|
|
162 |
Query query = new DefaultQuery(fs.getSchema().getTypeName(), filter); |
Query query = new DefaultQuery(fs.getSchema().getName().getLocalPart(), filter); |
163 |
if (amd != null) { |
if (amd != null) { |
164 |
// determine the names of the visible Attributes |
// determine the names of the visible Attributes |
165 |
this.visibleAMD = StyledLayerUtil.getVisibleAttributeMetaData( |
this.visibleAMD = StyledLayerUtil.getVisibleAttributeMetaData( |
166 |
amd, true); |
amd, true); |
167 |
Vector<String> visibleAttrNames = new Vector<String>(); |
Vector<String> visibleAttrNames = new Vector<String>(); |
168 |
// Add the column with the geometry (usually "the_geom") |
// Add the column with the geometry (usually "the_geom") |
169 |
visibleAttrNames.add(fs.getSchema().getDefaultGeometry() |
visibleAttrNames.add(fs.getSchema().getGeometryDescriptor() |
170 |
.getLocalName()); |
.getLocalName()); |
171 |
for (int attrIdx : visibleAMD.keySet()) { |
for (int attrIdx : visibleAMD.keySet()) { |
172 |
|
|
177 |
* ArrayOutOfIndex. |
* ArrayOutOfIndex. |
178 |
*/ |
*/ |
179 |
if (attrIdx < fs.getSchema().getAttributeCount()) { |
if (attrIdx < fs.getSchema().getAttributeCount()) { |
180 |
final AttributeType attributeTypeAtIdx = fs.getSchema() |
final AttributeDescriptor attributeTypeAtIdx = fs.getSchema() |
181 |
.getAttributeType(attrIdx); |
.getAttributeDescriptors().get(attrIdx); |
182 |
visibleAttrNames.add(attributeTypeAtIdx.getLocalName()); |
visibleAttrNames.add(attributeTypeAtIdx.getLocalName()); |
183 |
} else { |
} else { |
184 |
LOGGER.warn("AttributeMetaData has been found for columnIdx="+attrIdx+", but fs.getSchema().getAttributeCount() = "+fs.getSchema().getAttributeCount()+". Ignored."); |
LOGGER.warn("AttributeMetaData has been found for columnIdx="+attrIdx+", but fs.getSchema().getAttributeCount() = "+fs.getSchema().getAttributeCount()+". Ignored."); |
230 |
setFeatureSource(null, null, null); |
setFeatureSource(null, null, null); |
231 |
else { |
else { |
232 |
FeatureCollection fc = layer.getFeatureCollection(); |
FeatureCollection fc = layer.getFeatureCollection(); |
233 |
String fcName = fc.getSchema().getTypeName(); |
String fcName = fc.getSchema().getName().getLocalPart(); |
234 |
FeatureSource fs = new MemoryDataStore(fc) |
FeatureSource fs = new MemoryDataStore(fc) |
235 |
.getFeatureSource(fcName); |
.getFeatureSource(fcName); |
236 |
setFeatureSource(fs, layer.getAttributeMetaDataMap(), filter); |
setFeatureSource(fs, layer.getAttributeMetaDataMap(), filter); |