25 |
* |
* |
26 |
* Contributors: |
* Contributors: |
27 |
* Martin O. J. Schmitz - initial API and implementation |
* Martin O. J. Schmitz - initial API and implementation |
28 |
* Stefan A. Krüger - additional utility classes |
* Stefan A. Tzeggai - additional utility classes |
29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.geotools; |
package skrueger.geotools; |
31 |
|
|
32 |
import java.util.HashMap; |
import java.util.HashMap; |
33 |
|
import java.util.LinkedHashSet; |
34 |
import java.util.List; |
import java.util.List; |
|
import java.util.Vector; |
|
35 |
|
|
36 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
37 |
import org.geotools.data.DefaultQuery; |
import org.geotools.data.DefaultQuery; |
41 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
42 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
43 |
import org.opengis.feature.type.AttributeDescriptor; |
import org.opengis.feature.type.AttributeDescriptor; |
44 |
|
import org.opengis.feature.type.Name; |
45 |
import org.opengis.filter.Filter; |
import org.opengis.filter.Filter; |
46 |
|
|
47 |
import schmitzm.geotools.feature.FeatureUtil; |
import schmitzm.geotools.feature.FeatureUtil; |
48 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
|
import skrueger.AttributeMetadataInterface; |
|
49 |
import skrueger.AttributeMetadataImpl; |
import skrueger.AttributeMetadataImpl; |
50 |
|
import skrueger.AttributeMetadataInterface; |
51 |
|
|
52 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
53 |
|
|
62 |
* applied.</li> |
* applied.</li> |
63 |
* </ul> |
* </ul> |
64 |
* |
* |
65 |
* @author Stefan A. Krüger |
* @author Stefan A. Tzeggai |
66 |
*/ |
*/ |
67 |
public class StyledFeatureCollectionTableModel extends |
public class StyledFeatureCollectionTableModel extends |
68 |
FeatureCollectionTableModel { |
FeatureCollectionTableModel { |
126 |
this.filter = filter; |
this.filter = filter; |
127 |
this.amdMap = amdm; |
this.amdMap = amdm; |
128 |
this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly(); |
this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly(); |
129 |
|
|
130 |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null; |
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null; |
131 |
if (fs != null) { |
if (fs != null) { |
132 |
|
|
135 |
final SimpleFeatureType schema = fs.getSchema(); |
final SimpleFeatureType schema = fs.getSchema(); |
136 |
Query query = new DefaultQuery(schema.getTypeName(), filter); |
Query query = new DefaultQuery(schema.getTypeName(), filter); |
137 |
if (amdm != null) { |
if (amdm != null) { |
138 |
Vector<String> visibleAttrNames = new Vector<String>(); |
LinkedHashSet<String> visibleAttrNames = new LinkedHashSet<String>(); |
139 |
|
|
140 |
// Add the column with the geometry (usually "the_geom") always |
// Add the column with the geometry (usually "the_geom") always |
141 |
visibleAttrNames.add(schema.getGeometryDescriptor() |
String geomColumnLocalName = schema.getGeometryDescriptor() |
142 |
.getLocalName()); |
.getLocalName(); |
143 |
|
visibleAttrNames.add(geomColumnLocalName); |
144 |
|
|
145 |
// Add other visible attributes as ordered by weights |
// Add other visible attributes as ordered by weights |
146 |
for (AttributeMetadataInterface a : amdMapVisibleOnly) { |
for (AttributeMetadataInterface a : amdMapVisibleOnly) { |
159 |
// } else { |
// } else { |
160 |
// query = new DefaultQuery(schema.getTypeName(), filter); |
// query = new DefaultQuery(schema.getTypeName(), filter); |
161 |
// } |
// } |
162 |
|
|
163 |
|
System.out.println(query.getPropertyNames()); |
164 |
} |
} |
165 |
fc = fs.getFeatures(query); |
fc = fs.getFeatures(query); |
166 |
} |
} |
213 |
// Pruefen, welche Attribute angezeigt werden |
// Pruefen, welche Attribute angezeigt werden |
214 |
attrTypes.clear(); |
attrTypes.clear(); |
215 |
for (AttributeMetadataInterface amd : amdMapVisibleOnly) { |
for (AttributeMetadataInterface amd : amdMapVisibleOnly) { |
216 |
AttributeDescriptor type = schema.getDescriptor(amd.getName()); |
Name name = amd.getName(); |
217 |
|
AttributeDescriptor type = schema.getDescriptor(name); |
218 |
|
// if type can not be determined by complete name, |
219 |
|
// try only the local name |
220 |
|
if ( type == null ) |
221 |
|
type = schema.getDescriptor(name.getLocalPart()); |
222 |
if (attrFilter == null || attrFilter.accept(type)) |
if (attrFilter == null || attrFilter.accept(type)) |
223 |
attrTypes.add(type); |
attrTypes.add(type); |
224 |
} |
} |
229 |
colClass = new Class[attrTypes.size()]; |
colClass = new Class[attrTypes.size()]; |
230 |
attrIdxForCol = new int[attrTypes.size()]; |
attrIdxForCol = new int[attrTypes.size()]; |
231 |
for (int i = 0; i < colNames.length; i++) { |
for (int i = 0; i < colNames.length; i++) { |
232 |
AttributeDescriptor descriptor = schema |
Name name = amdMapVisibleOnly.get(i).getName(); |
233 |
.getDescriptor(amdMapVisibleOnly.get(i).getName()); |
AttributeDescriptor descriptor = schema.getDescriptor(name); |
234 |
|
// if type can not be determined by complete name, |
235 |
|
// try only the local name |
236 |
|
if ( descriptor == null ) |
237 |
|
descriptor = schema.getDescriptor(name.getLocalPart()); |
238 |
|
|
239 |
// Not so nice in 26: find the index of an attribute... |
// Not so nice in 26: find the index of an attribute... |
240 |
int idx = schema.getAttributeDescriptors().indexOf(descriptor); |
int idx = schema.getAttributeDescriptors().indexOf(descriptor); |