[Schmitzm-commits] r666 - in branches/2.0-RC2/src: schmitzm/jfree/feature/style skrueger skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 3 19:05:58 CET 2010


Author: alfonx
Date: 2010-02-03 19:05:50 +0100 (Wed, 03 Feb 2010)
New Revision: 666

Modified:
   branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
   branches/2.0-RC2/src/skrueger/AttributeMetadata.java
   branches/2.0-RC2/src/skrueger/geotools/StyledLayerUtil.java
Log:
After importing FeatureChartStyles, their attributes names are checked against the schema

Modified: branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2010-02-03 17:58:37 UTC (rev 665)
+++ branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2010-02-03 18:05:50 UTC (rev 666)
@@ -56,6 +56,8 @@
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.GeometryDescriptor;
+import org.opengis.feature.type.Name;
 
 import schmitzm.geotools.feature.FeatureUtil;
 import schmitzm.geotools.feature.PipedFeatureIterator;
@@ -67,6 +69,8 @@
 import schmitzm.jfree.feature.Feature2SeriesDatasetMapping;
 import schmitzm.jfree.feature.FeatureDatasetMetaData;
 import schmitzm.jfree.feature.FeatureDatasetSelectionModel;
+import skrueger.AttributeMetadata;
+import skrueger.geotools.AttributeMetadataMap;
 
 /**
  * This class contains static utility methods related to chart styles based on
@@ -519,4 +523,46 @@
 
 		return dataset;
 	}
+	
+
+	/**
+	 * After loading from XML, the ChartStyle contains whatever is written
+	 * in the XML. But the DBF Schema can change quickly by accident! This method checks an
+	 * {@link FeatureChartStyle} against a schema and also corrects
+	 * upperCase/lowerCase problems. 
+	 * 
+	 * Returns false if attributes had to be removed from the {@link FeatureChartStyle}. 
+	 */
+	public static boolean correctAttributeNames(FeatureChartStyle featureChartStyle,
+			SimpleFeatureType schema) {
+
+		ArrayList<Integer> willRemove = new ArrayList<Integer>();
+
+		// 1. Check.. all attributes in the atm should be in the schema as well.
+		// maybe correct some upperCase/loweCase stuff
+
+		for (int idx = 0; idx < featureChartStyle.getAttributeCount(); idx++) {
+
+			String attributeName = featureChartStyle.getAttributeName(idx);
+			
+			AttributeDescriptor foundDescr = schema
+					.getDescriptor(attributeName);
+			if (foundDescr == null) {
+				Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema,
+						attributeName);
+				if (bestMatch == null)
+					willRemove.add(idx);
+				else
+					featureChartStyle.setAttributeName(idx,bestMatch.getLocalPart());
+			} 
+		}
+
+		// Remove the ones that were not findable in the schema
+		for (Integer removeIdx : willRemove) {
+			featureChartStyle.removeAttribute(removeIdx);
+		}
+
+		//	 * Returns false if attributes had to be removed from the {@link FeatureChartStyle}. 
+		return willRemove.isEmpty();
+	}
 }

Modified: branches/2.0-RC2/src/skrueger/AttributeMetadata.java
===================================================================
--- branches/2.0-RC2/src/skrueger/AttributeMetadata.java	2010-02-03 17:58:37 UTC (rev 665)
+++ branches/2.0-RC2/src/skrueger/AttributeMetadata.java	2010-02-03 18:05:50 UTC (rev 666)
@@ -79,7 +79,7 @@
 	 * be set and will always be interpreted as NULL internally and will usually
 	 * be ignored. This overcomes the problem, that 
 	 **/
-	protected HashSet<Object> nodataValues = new HashSet<Object>();
+	protected final HashSet<Object> nodataValues = new HashSet<Object>();
 
 	/** Translation of the attribute's title **/
 	protected Translation title = new Translation();
@@ -340,9 +340,13 @@
 		this.name = name;
 	}
 
-	public void setNodataValues(final HashSet<Object> nodataValues) {
-		this.nodataValues = nodataValues;
+	public void addNodataValue(Object nodataValue) {
+		this.nodataValues.add(nodataValue);
 	}
+	
+	public void removeNodataValue(Object nodataValue) {
+		this.nodataValues.remove(nodataValue);
+	}
 
 	public void setTitle(final Translation title) {
 		this.title = title;
@@ -387,19 +391,14 @@
 	}
 
 	/**
-	 * Takes any value object and checks it againsts the NODATA values. If the
+	 * Takes any value object and checks it against the NODATA values. If the
 	 * value equals a NODATA value, <code>null</code> is returned. Otherwise the
 	 * same object is returned.
 	 * 
 	 * Note: This method is called often.
 	 */
 	public Object fiterNodata(final Object value) {
-
-		// contains.. hash
-		for (final Object nodataValue : getNodataValues()) {
-			if (nodataValue.equals(value))
-				return null;
-		}
+		if (nodataValues.contains(value)) return null;
 		return value;
 	}
 }

Modified: branches/2.0-RC2/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/StyledLayerUtil.java	2010-02-03 17:58:37 UTC (rev 665)
+++ branches/2.0-RC2/src/skrueger/geotools/StyledLayerUtil.java	2010-02-03 18:05:50 UTC (rev 666)
@@ -1271,7 +1271,6 @@
 								.getLanguages()));
 			}
 		}
-
 	}
 
 }



More information about the Schmitzm-commits mailing list