[Schmitzm-commits] r1143 - in trunk: src/schmitzm/geotools/feature src_junit/schmitzm/geotools/feature src_junit/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Oct 17 02:14:48 CEST 2010
Author: alfonx
Date: 2010-10-17 02:14:45 +0200 (Sun, 17 Oct 2010)
New Revision: 1143
Modified:
trunk/src/schmitzm/geotools/feature/FeatureUtil.java
trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:
Reorganized the AtlasStyler GUI a bit, so that it's now more compact. Also found some GUI updateing bug when changing text symbolizer classes.
Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java 2010-10-16 21:32:08 UTC (rev 1142)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java 2010-10-17 00:14:45 UTC (rev 1143)
@@ -40,6 +40,7 @@
import java.sql.SQLException;
import java.text.NumberFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -142,13 +143,13 @@
private static final NameImpl GC_NAME = new NameImpl(
"http://www.opengis.net/gml", "GridCoverage");
- /**
- * Prueft, ob ein Attribut ein Geometrie-Attribut ist.
- */
- public static boolean isGeometryAttribute(Object attrType) {
- return attrType instanceof GeometryAttributeType ||
- attrType instanceof GeometryDescriptor;
- }
+ /**
+ * Prueft, ob ein Attribut ein Geometrie-Attribut ist.
+ */
+ public static boolean isGeometryAttribute(Object attrType) {
+ return attrType instanceof GeometryAttributeType
+ || attrType instanceof GeometryDescriptor;
+ }
/**
* This is a cheap and not good hack to extract the names of attributes used
@@ -313,7 +314,7 @@
else if (Polygon.class.isAssignableFrom(geometryType)
|| MultiPolygon.class.isAssignableFrom(geometryType))
return GeometryForm.POLYGON;
-
+
// Aus anderem, doppelem alten code
// if (geometryAttrib != null
// && (com.vividsolutions.jts.geom.Polygon.class
@@ -379,7 +380,7 @@
for (int j = 0; j < f.getFeatureType().getAttributeCount(); j++)
// if ( f.getFeatureType().getAttributeType(j).isGeometry() )
- if ( isGeometryAttribute(f.getFeatureType() ))
+ if (isGeometryAttribute(f.getFeatureType()))
geomVec.add(f.getAttribute(j));
Geometry[] geomArr = new Geometry[geomVec.size()];
@@ -412,7 +413,7 @@
}
return result;
}
-
+
/**
* Erzeugt einen Standard-Style fuer eine {@link FeatureCollection} Und
* setzt eine default namen
@@ -441,8 +442,8 @@
}
/**
- * Erzeugt einen Standard-Style fuer einen {@link GeometryForm} Und
- * setzt eine default Namen.
+ * Erzeugt einen Standard-Style fuer einen {@link GeometryForm} Und setzt
+ * eine default Namen.
*
* @param geometryAttrib
* GeometryAttributeType
@@ -702,7 +703,8 @@
// if it is a GeometryAttributeType, the CRS must be stored
// in the meta data
if (aType instanceof GeometryDescriptor)
- metaData = ((GeometryDescriptor)aType).getCoordinateReferenceSystem();
+ metaData = ((GeometryDescriptor) aType)
+ .getCoordinateReferenceSystem();
// combine the restrictions of the attribute type for the
// AttributeTypeFactory
@@ -848,8 +850,8 @@
try {
builder.add(aType);
- if ( isGeometryAttribute(aType) &&
- builder.getDefaultGeometry() == null)
+ if (isGeometryAttribute(aType)
+ && builder.getDefaultGeometry() == null)
builder.setDefaultGeometry(aType.getLocalName());
} catch (IllegalArgumentException err) {
builder.add(AttributeTypeFactory.newAttributeType(
@@ -2298,7 +2300,7 @@
*/
public static Vector<String> getNumericalFieldNames(
final SimpleFeatureType schema) {
- return getNumericalFieldNames(schema, false);
+ return getNumericalFieldNames(schema, false, true);
}
/**
@@ -2308,9 +2310,12 @@
* @param empty
* if <code>true</code>, the last entry of this list will always
* be a virtual 0/"" value.
+ * @param validOnly
+ * if <code>true</code> , the list is filtered for attribute
+ * names that do not contain any special characters
*/
public static Vector<String> getNumericalFieldNames(
- final SimpleFeatureType schema, boolean empty) {
+ final SimpleFeatureType schema, boolean empty, boolean validOnly) {
final Vector<String> numericalFieldNames = new Vector<String>();
final List<AttributeDescriptor> attributeDescs = schema
@@ -2449,7 +2454,7 @@
.getLocalPart());
}
}
-
+
// Checking for excact match with a CLEANED version of the localname
for (AttributeDescriptor d : attributeDescriptors) {
if (FeatureUtil.cleanAttname(d.getLocalName()).equals(localName)) {
@@ -2460,106 +2465,122 @@
// Checking for IGNORECASE match with a CLEANED version of the localname
for (AttributeDescriptor d : attributeDescriptors) {
- if (FeatureUtil.cleanAttname(d.getLocalName()).equalsIgnoreCase(localName)) {
+ if (FeatureUtil.cleanAttname(d.getLocalName()).equalsIgnoreCase(
+ localName)) {
return new NameImpl(d.getName().getNamespaceURI(), d.getName()
.getLocalPart());
}
}
-
return null;
}
-
/**
* "Modifies" a {@link FeatureSource} according to the given
- * {@link AttributeModificationRule AttributeModificationDefinitions}
- * and stores the resulting {@link FeatureSource} in a data store.<br>
- * <b>Note</b>:
- * Only the attibutes for which a {@link AttributeModificationRule} is
- * specified, are copied to the destination {@link FeatureSource}. So even
- * if an attribute should be transfered unchanged, there must be an
- * {@link AttributeModificationRule} for it!!
- * This <b>also</b> applies to the geometry attribute!!
- * @param sourceFs source {@link FeatureSource}
- * @param destDataStore destination for the new {@link FeatureSource}
- * @param destAttrRule defines which attributes of the source {@link FeatureSource}
- * are copied in the destination, and (optionally) how the
- * attributes are modified during this procedure
+ * {@link AttributeModificationRule AttributeModificationDefinitions} and
+ * stores the resulting {@link FeatureSource} in a data store.<br>
+ * <b>Note</b>: Only the attibutes for which a
+ * {@link AttributeModificationRule} is specified, are copied to the
+ * destination {@link FeatureSource}. So even if an attribute should be
+ * transfered unchanged, there must be an {@link AttributeModificationRule}
+ * for it!! This <b>also</b> applies to the geometry attribute!!
+ *
+ * @param sourceFs
+ * source {@link FeatureSource}
+ * @param destDataStore
+ * destination for the new {@link FeatureSource}
+ * @param destAttrRule
+ * defines which attributes of the source {@link FeatureSource}
+ * are copied in the destination, and (optionally) how the
+ * attributes are modified during this procedure
*/
- public static void modifyFeatureSource(FeatureSource<SimpleFeatureType,SimpleFeature> sourceFs, AbstractDataStore destDataStore, AttributeModificationRule... destAttrRule) throws IOException {
- SimpleFeatureType sType = sourceFs.getSchema();
- SimpleFeatureTypeBuilder typebuilder = new SimpleFeatureTypeBuilder();
- typebuilder.setName(sType.getTypeName());
-
- //***** Create the new attribute type for the destination FeatureSource *****
- // Loop the attributes, which should be transfered to the
- // destination FeatureSource
- for (AttributeModificationRule rule : destAttrRule) {
- AttributeDescriptor sDescr = sType.getDescriptor(rule.getAttrIdx());
- AttributeDescriptor dDescr = rule.applyToAttributeType(sDescr);
- typebuilder.add(dDescr);
- }
- // create the FeatureType for the destination FeatureSource
- SimpleFeatureType dType = typebuilder.buildFeatureType();
+ public static void modifyFeatureSource(
+ FeatureSource<SimpleFeatureType, SimpleFeature> sourceFs,
+ AbstractDataStore destDataStore,
+ AttributeModificationRule... destAttrRule) throws IOException {
+ SimpleFeatureType sType = sourceFs.getSchema();
+ SimpleFeatureTypeBuilder typebuilder = new SimpleFeatureTypeBuilder();
+ typebuilder.setName(sType.getTypeName());
- //***** Create the new FeatureSource *****
- destDataStore.createSchema(dType);
- FeatureWriter<SimpleFeatureType, SimpleFeature> fWriter = destDataStore.getFeatureWriter(dType.getTypeName(), Transaction.AUTO_COMMIT);
- FeatureCollection<SimpleFeatureType, SimpleFeature> sourceFc = sourceFs.getFeatures();
- FeatureIterator<SimpleFeature> fIter = sourceFc.features();
- try {
- for (SimpleFeature sFeature = null; fIter.hasNext(); ) {
- // Determine source feature
- sFeature = fIter.next();
- // Create destination feature
- SimpleFeature dFeature = fWriter.next();
- // Set the values in the destination feature
- for (AttributeModificationRule modRule : destAttrRule)
- modRule.applyToFeature(sFeature, dFeature);
- // write the destination feature
- fWriter.write();
- }
- } finally {
- sourceFc.close(fIter);
- fWriter.close();
- }
+ // ***** Create the new attribute type for the destination FeatureSource
+ // *****
+ // Loop the attributes, which should be transfered to the
+ // destination FeatureSource
+ for (AttributeModificationRule rule : destAttrRule) {
+ AttributeDescriptor sDescr = sType.getDescriptor(rule.getAttrIdx());
+ AttributeDescriptor dDescr = rule.applyToAttributeType(sDescr);
+ typebuilder.add(dDescr);
+ }
+ // create the FeatureType for the destination FeatureSource
+ SimpleFeatureType dType = typebuilder.buildFeatureType();
+
+ // ***** Create the new FeatureSource *****
+ destDataStore.createSchema(dType);
+ FeatureWriter<SimpleFeatureType, SimpleFeature> fWriter = destDataStore
+ .getFeatureWriter(dType.getTypeName(), Transaction.AUTO_COMMIT);
+ FeatureCollection<SimpleFeatureType, SimpleFeature> sourceFc = sourceFs
+ .getFeatures();
+ FeatureIterator<SimpleFeature> fIter = sourceFc.features();
+ try {
+ for (SimpleFeature sFeature = null; fIter.hasNext();) {
+ // Determine source feature
+ sFeature = fIter.next();
+ // Create destination feature
+ SimpleFeature dFeature = fWriter.next();
+ // Set the values in the destination feature
+ for (AttributeModificationRule modRule : destAttrRule)
+ modRule.applyToFeature(sFeature, dFeature);
+ // write the destination feature
+ fWriter.write();
+ }
+ } finally {
+ sourceFc.close(fIter);
+ fWriter.close();
+ }
}
-
+
/**
* Transforms a value to another type.
- * @param value a value
- * @param destType destination type
- * @return {@code null} if {@code value} is {@code null} or if the transformation can
- * not be applied; the {@code value} itself if no destination type is given or
- * {@code value} is already in instance of the destination type
+ *
+ * @param value
+ * a value
+ * @param destType
+ * destination type
+ * @return {@code null} if {@code value} is {@code null} or if the
+ * transformation can not be applied; the {@code value} itself if no
+ * destination type is given or {@code value} is already in instance
+ * of the destination type
*/
public static Object transformAttributeValue(Object value, Class<?> destType) {
- if ( value == null )
- return null;
- if ( destType == null )
- return value;
- if ( destType.isInstance(value) )
- return value;
-
- // convert to string --> easy!
- if ( String.class.equals(destType) )
- return value.toString();
- // convert to number
- if ( Number.class.isAssignableFrom(destType) ) {
- if ( value instanceof Number )
- return BaseTypeUtil.convertNumber((Number)value,(Class<Number>)destType);
- if ( value instanceof String )
- return BaseTypeUtil.convertFromString((String)value,(Class<Number>)destType);
- }
-
- // TODO: implement more transformation rules
-
- LOGGER.warn("Can not apply attribute value transformation: "+LangUtil.getSimpleClassName(value)+" --> "+LangUtil.getSimpleClassName(destType)+" (for '"+value+"')");
-
- return null;
+ if (value == null)
+ return null;
+ if (destType == null)
+ return value;
+ if (destType.isInstance(value))
+ return value;
+
+ // convert to string --> easy!
+ if (String.class.equals(destType))
+ return value.toString();
+ // convert to number
+ if (Number.class.isAssignableFrom(destType)) {
+ if (value instanceof Number)
+ return BaseTypeUtil.convertNumber((Number) value,
+ (Class<Number>) destType);
+ if (value instanceof String)
+ return BaseTypeUtil.convertFromString((String) value,
+ (Class<Number>) destType);
+ }
+
+ // TODO: implement more transformation rules
+
+ LOGGER.warn("Can not apply attribute value transformation: "
+ + LangUtil.getSimpleClassName(value) + " --> "
+ + LangUtil.getSimpleClassName(destType) + " (for '" + value
+ + "')");
+
+ return null;
}
-
/**
* @returns a "cleaned" (DBF compatible) proposal for a attribute name based
@@ -2585,7 +2606,7 @@
clean = "_" + clean;
}
- clean = clean.substring(0, Math.min(10, clean.length() ));
+ clean = clean.substring(0, Math.min(10, clean.length()));
if (!FeatureUtil.checkAttributeNameRestrictions(clean)) {
if (counter != null)
@@ -2597,6 +2618,19 @@
return clean;
}
+ /**
+ * @return A list of fields that can be used for a quantification (e.g.
+ * numerical fields)
+ *
+ * @param empty
+ * if <code>true</code>, the last entry of this list will always
+ * be a virtual 0/"" value.
+ */
+ public static Collection<String> getNumericalFieldNames(
+ SimpleFeatureType schema, boolean empty) {
+ return getNumericalFieldNames(schema, empty, true);
+ }
+
// /**
// * Extrahiert alle Geometrien aus einer FeatureCollection. Fuer jedes
// * Geometry-Attribut der FeatureCollection wird eine GeometrieCollection
Modified: trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java 2010-10-16 21:32:08 UTC (rev 1142)
+++ trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java 2010-10-17 00:14:45 UTC (rev 1143)
@@ -7,7 +7,6 @@
import static org.junit.Assert.fail;
import java.io.File;
-import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -23,7 +22,6 @@
import org.opengis.feature.type.GeometryDescriptor;
import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
-import schmitzm.geotools.io.GeoExportUtil;
import schmitzm.io.IOUtil;
import schmitzm.swing.TestingUtil;
import schmitzm.swing.TestingUtil.TestDatasets;
Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-10-16 21:32:08 UTC (rev 1142)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-10-17 00:14:45 UTC (rev 1143)
@@ -122,4 +122,10 @@
assertEquals("4.0", colorMapEntries[2].getQuantity().toString());
}
+ @Test
+ public void testGetSecondPropertyName()
+ {
+
+ }
+
}
More information about the Schmitzm-commits
mailing list