[Schmitzm-commits] r980 - in trunk/src/schmitzm/geotools: feature styling

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Aug 18 17:40:55 CEST 2010


Author: alfonx
Date: 2010-08-18 17:40:54 +0200 (Wed, 18 Aug 2010)
New Revision: 980

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
Log:


Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-08-17 12:46:04 UTC (rev 979)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-08-18 15:40:54 UTC (rev 980)
@@ -101,6 +101,7 @@
 
 import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.GTUtil;
+import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
 import schmitzm.lang.LangUtil;
 import schmitzm.lang.ResourceProvider;
 import skrueger.geotools.StyledFeaturesInterface;
@@ -126,8 +127,8 @@
 	/**
 	 * {@link ResourceProvider}, der die Lokalisation fuer Komponenten des
 	 * Package {@code schmitzm.geotools.feature} zur Verfuegung stellt. Diese
-	 * sind in properties-Dateien unter {@code
-	 * schmitzm.geotools.feature.resource.locales} hinterlegt.
+	 * sind in properties-Dateien unter
+	 * {@code schmitzm.geotools.feature.resource.locales} hinterlegt.
 	 */
 	public static ResourceProvider RESOURCE = ResourceProvider.newInstance(
 			LangUtil.extendPackagePath(FeatureUtil.class,
@@ -299,6 +300,22 @@
 		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
+		// .isAssignableFrom(geometryAttrib.getType().getBinding()) ||
+		// com.vividsolutions.jts.geom.MultiPolygon.class
+		// .isAssignableFrom(geometryAttrib.getType().getBinding())))
+		// style = createPolygonStyle(Color.ORANGE, Color.BLACK, 1);
+		// else if (geometryAttrib != null
+		// && (com.vividsolutions.jts.geom.Point.class
+		// .isAssignableFrom(geometryAttrib.getType().getBinding()) ||
+		// com.vividsolutions.jts.geom.MultiPoint.class
+		// .isAssignableFrom(geometryAttrib.getType().getBinding())))
+		// style = createPointStyle(Color.RED);
+		// else
+		// style = createLineStyle(Color.BLUE, 1);
 
 		throw new UnsupportedOperationException("Unknown geometry type: "
 				+ geometryType.getName());
@@ -382,7 +399,7 @@
 		}
 		return result;
 	}
-
+	
 	/**
 	 * Erzeugt einen Standard-Style fuer eine {@link FeatureCollection} Und
 	 * setzt eine default namen
@@ -405,19 +422,42 @@
 	public static Style createDefaultStyle(GeometryDescriptor geometryAttrib) {
 		Style style = null;
 
-		if (geometryAttrib != null
-				&& (com.vividsolutions.jts.geom.Polygon.class
-						.isAssignableFrom(geometryAttrib.getType().getBinding()) || com.vividsolutions.jts.geom.MultiPolygon.class
-						.isAssignableFrom(geometryAttrib.getType().getBinding())))
+		GeometryForm geoForm = getGeometryForm(geometryAttrib);
+
+		return createDefaultStyle(geoForm);
+	}
+
+	/**
+	 * Erzeugt einen Standard-Style fuer einen {@link GeometryForm} Und
+	 * setzt eine default Namen.
+	 * 
+	 * @param geometryAttrib
+	 *            GeometryAttributeType
+	 */
+	public static Style createDefaultStyle(GeometryForm geoForm) {
+		Style style;
+		if (geoForm == GeometryForm.POLYGON)
 			style = createPolygonStyle(Color.ORANGE, Color.BLACK, 1);
-		else if (geometryAttrib != null
-				&& (com.vividsolutions.jts.geom.Point.class
-						.isAssignableFrom(geometryAttrib.getType().getBinding()) || com.vividsolutions.jts.geom.MultiPoint.class
-						.isAssignableFrom(geometryAttrib.getType().getBinding())))
+		else if (geoForm == GeometryForm.POINT)
 			style = createPointStyle(Color.RED);
 		else
 			style = createLineStyle(Color.BLUE, 1);
 
+		// if (geometryAttrib != null
+		// && (com.vividsolutions.jts.geom.Polygon.class
+		// .isAssignableFrom(geometryAttrib.getType().getBinding()) ||
+		// com.vividsolutions.jts.geom.MultiPolygon.class
+		// .isAssignableFrom(geometryAttrib.getType().getBinding())))
+		// style = createPolygonStyle(Color.ORANGE, Color.BLACK, 1);
+		// else if (geometryAttrib != null
+		// && (com.vividsolutions.jts.geom.Point.class
+		// .isAssignableFrom(geometryAttrib.getType().getBinding()) ||
+		// com.vividsolutions.jts.geom.MultiPoint.class
+		// .isAssignableFrom(geometryAttrib.getType().getBinding())))
+		// style = createPointStyle(Color.RED);
+		// else
+		// style = createLineStyle(Color.BLUE, 1);
+
 		style.setName(DEFAULT_VECTOR_STYLE_NAME);
 
 		// 26 style.setTitle(DEFAULT_VECTOR_STYLE_NAME);
@@ -703,20 +743,20 @@
 			throws Exception {
 		// NULL not allowed
 		if (attrName == null || attrName.trim().equals(""))
-			throw new Exception(RESOURCE
-					.getString("org.geotools.err.attr.name.null"));
+			throw new Exception(
+					RESOURCE.getString("org.geotools.err.attr.name.null"));
 		// Maximum 10 characters
 		if (attrName.length() > 10)
-			throw new Exception(RESOURCE
-					.getString("org.geotools.err.attr.name.length"));
+			throw new Exception(
+					RESOURCE.getString("org.geotools.err.attr.name.length"));
 		// Digit not allowed as first character
 		if (!attrName.matches("[a-zA-Z].*"))
-			throw new Exception(RESOURCE
-					.getString("org.geotools.err.attr.name.start"));
+			throw new Exception(
+					RESOURCE.getString("org.geotools.err.attr.name.start"));
 		// Only "normal" characters, digits and '_' allowed
 		if (!attrName.matches("\\w+"))
-			throw new Exception(RESOURCE
-					.getString("org.geotools.err.attr.name.chars"));
+			throw new Exception(
+					RESOURCE.getString("org.geotools.err.attr.name.chars"));
 	}
 
 	/**
@@ -751,8 +791,8 @@
 	 */
 	public static SimpleFeatureType extendFeatureType(SimpleFeatureType fType,
 			List<AttributeDescriptor> aTypes) throws SchemaException {
-		return extendFeatureType(fType, aTypes
-				.toArray(new AttributeDescriptor[0]));
+		return extendFeatureType(fType,
+				aTypes.toArray(new AttributeDescriptor[0]));
 	}
 
 	/**
@@ -799,11 +839,10 @@
 						&& builder.getDefaultGeometry() == null)
 					builder.setDefaultGeometry(aType.getLocalName());
 			} catch (IllegalArgumentException err) {
-				builder.add(AttributeTypeFactory.newAttributeType(aType
-						.getLocalName()
-						+ "_2", aType.getType().getBinding(), aType
-						.isNillable(), restrictions, aType.getDefaultValue(),
-						null));
+				builder.add(AttributeTypeFactory.newAttributeType(
+						aType.getLocalName() + "_2", aType.getType()
+								.getBinding(), aType.isNillable(),
+						restrictions, aType.getDefaultValue(), null));
 			}
 		}
 		SimpleFeatureType resultType = builder.buildFeatureType();
@@ -941,8 +980,8 @@
 		try {
 
 			// Array fuer die Attribut-Werte eines Features
-			List<Object> fValues = new ArrayList<Object>(resultType
-					.getAttributeCount());
+			List<Object> fValues = new ArrayList<Object>(
+					resultType.getAttributeCount());
 			for (; fi.hasNext();) {
 				// Werte der alten Attribute in Array schreiben
 				fValues = fi.next().getAttributes();
@@ -1033,8 +1072,8 @@
 		// Wenn keine Projektion, dann alle Attribute von fc1 mit denen
 		// von fc2 vereinen; sonst neuen SimpleFeatureType aufbauen
 		if (!projection)
-			resultType = extendFeatureType(fType1, fType2
-					.getAttributeDescriptors());
+			resultType = extendFeatureType(fType1,
+					fType2.getAttributeDescriptors());
 		else {
 			// Leeren SimpleFeature-Type erzeugen
 			SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
@@ -1095,8 +1134,8 @@
 					if (!joinedFeaturesIterator.hasNext()
 							&& joinType == JoinType.LEFT_OUTER) {
 						if (!projection)
-							getDefaultAttributeValues(fType2, fValues, fType1
-									.getAttributeCount());
+							getDefaultAttributeValues(fType2, fValues,
+									fType1.getAttributeCount());
 						else
 							getDefaultAttributeValues(fType2, fValues, 0,
 									projAttr);
@@ -1110,8 +1149,8 @@
 							f2 = joinedFeaturesIterator.next();
 							// Werte der 2. Features in Array schreiben
 							if (!projection)
-								getAttributeValues(f2, fValues, fType1
-										.getAttributeCount());
+								getAttributeValues(f2, fValues,
+										fType1.getAttributeCount());
 							else
 								getAttributeValues(f2, fValues, 0, projAttr);
 							// Erweitertes SimpleFeature erzeugen und
@@ -1234,8 +1273,8 @@
 	 *            abgelegt werden
 	 * @param attrName
 	 *            Attribute aus {@link f}
-	 * @return {@code destArray} oder einen neuen Array {@code
-	 *         Object[destStartIdx + attrName.length]}
+	 * @return {@code destArray} oder einen neuen Array
+	 *         {@code Object[destStartIdx + attrName.length]}
 	 */
 	public static Object[] getDefaultAttributeValues(SimpleFeatureType ft,
 			Object[] destArray, int destStartIdx, String... attrName) {
@@ -1294,12 +1333,10 @@
 			attrValue = getDefaultAttributeValue(attrType.getType()
 					.getBinding());
 			if (attrValue == null)
-				LOGGER
-						.warn("Could not create default value for not-null attribute '"
-								+ attrType.getLocalName()
-								+ "': "
-								+ attrType.getType().getBinding()
-										.getSimpleName());
+				LOGGER.warn("Could not create default value for not-null attribute '"
+						+ attrType.getLocalName()
+						+ "': "
+						+ attrType.getType().getBinding().getSimpleName());
 		}
 		return attrValue;
 	}
@@ -1343,8 +1380,8 @@
 	 * @param attrName
 	 *            Attribute des Features, deren Werte geliefert werden (wenn
 	 *            {@code null} werden alle Attribute geliefert)
-	 * @return {@code destArray} oder einen neuen Array {@code
-	 *         Object[destStartIdx + attrName.length]}
+	 * @return {@code destArray} oder einen neuen Array
+	 *         {@code Object[destStartIdx + attrName.length]}
 	 */
 	public static Object[] getAttributeValues(SimpleFeature f,
 			Object[] destArray, int destStartIdx, String... attrName) {
@@ -1397,8 +1434,8 @@
 	 * @param attrName
 	 *            Attribute des Features, deren Werte geliefert werden (wenn
 	 *            {@code null} werden alle Attribute geliefert)
-	 * @return {@code destArray} oder einen neuen Array {@code
-	 *         Object[destStartIdx + attrName.length]}
+	 * @return {@code destArray} oder einen neuen Array
+	 *         {@code Object[destStartIdx + attrName.length]}
 	 */
 	public static Map<String, Object> getAttributeValues(SimpleFeature f,
 			Map<String, Object> destMap, String... attrName) {
@@ -1410,8 +1447,8 @@
 				destMap.put(attrName[i], f.getAttribute(attrName[i]));
 		else
 			for (int i = 0; i < f.getAttributeCount(); i++)
-				destMap.put(f.getFeatureType().getName().getLocalPart(), f
-						.getAttribute(i));
+				destMap.put(f.getFeatureType().getName().getLocalPart(),
+						f.getAttribute(i));
 
 		return destMap;
 	}
@@ -1522,15 +1559,13 @@
 					break;
 				}
 			}
-			LOGGER
-					.warn("Join-Attribut for FeatureCollection not set. First attribute used: "
-							+ fcJoinAttr);
+			LOGGER.warn("Join-Attribut for FeatureCollection not set. First attribute used: "
+					+ fcJoinAttr);
 		}
 		if (rsJoinAttr == null || rsJoinAttr.trim().equals("")) {
 			rsJoinAttr = rs.getMetaData().getColumnName(1);
-			LOGGER
-					.warn("Join-Attribut for ResultSet not set. First column used: "
-							+ rsJoinAttr);
+			LOGGER.warn("Join-Attribut for ResultSet not set. First column used: "
+					+ rsJoinAttr);
 		}
 
 		// FeatureCollection aus ResultSet erzeugen
@@ -1683,11 +1718,8 @@
 			boolean nillable = metaData.isNullable(i) != ResultSetMetaData.columnNoNulls;
 			Object defaultValue = getDefaultAttributeValue(columnClass);
 			if (defaultValue == null && !nillable)
-				LOGGER
-						.warn("Could not create default value for not-null attribute '"
-								+ columnName
-								+ "': "
-								+ columnClass.getSimpleName());
+				LOGGER.warn("Could not create default value for not-null attribute '"
+						+ columnName + "': " + columnClass.getSimpleName());
 
 			// Add an attribute for the column to the SimpleFeatureType
 			featureTypeFac.add(AttributeTypeFactory.newAttributeType(
@@ -1989,10 +2021,9 @@
 			return new MemoryDataStore(features).getFeatureSource(features
 					.getSchema().getTypeName());
 		} catch (IOException e) {
-			LOGGER
-					.error(
-							"Creating a memory datastore for the allFeaturesCollection",
-							e);
+			LOGGER.error(
+					"Creating a memory datastore for the allFeaturesCollection",
+					e);
 			throw new RuntimeException(
 					"Creating a memory datastore for the allFeaturesCollection",
 					e);
@@ -2004,10 +2035,10 @@
 	 * oder GridCoverager oder {@link GridCoverageReader} auf dem ein Layer
 	 * basiert. Ein Raster-Layer zeichnen sich dadurch aus, dass die zugrunde
 	 * liegende {@link FeatureCollection} nur ein SimpleFeature enthaelt, das
-	 * genau ein Attribut mit Namen "GridCoverage" und Typ {@code
-	 * GridCoverage2D} oder {@link AbstractGridCoverageReader} hat. Sind diese
-	 * Bedingungen erfuellt, wird das 2. Attribut zurueckgegeben, ansonsten die
-	 * {@link FeatureCollection}.
+	 * genau ein Attribut mit Namen "GridCoverage" und Typ
+	 * {@code GridCoverage2D} oder {@link AbstractGridCoverageReader} hat. Sind
+	 * diese Bedingungen erfuellt, wird das 2. Attribut zurueckgegeben,
+	 * ansonsten die {@link FeatureCollection}.
 	 * 
 	 * @see {@link FeatureUtilities#wrapGridCoverage(GridCoverage2D)} and
 	 *      {@link FeatureUtilities#wrapGridCoverageReader(AbstractGridCoverage2DReader, GeneralParameterValue[])}
@@ -2037,10 +2068,10 @@
 	 * oder GridCoverager oder {@link GridCoverageReader} auf dem ein Layer
 	 * basiert. Ein Raster-Layer zeichnen sich dadurch aus, dass die zugrunde
 	 * liegende {@link FeatureCollection} nur ein SimpleFeature enthaelt, das
-	 * genau ein Attribut mit Namen "GridCoverage" und Typ {@code
-	 * GridCoverage2D} oder {@link AbstractGridCoverageReader} hat. Sind diese
-	 * Bedingungen erfuellt, wird das 2. Attribut zurueckgegeben, ansonsten die
-	 * {@link FeatureCollection}.
+	 * genau ein Attribut mit Namen "GridCoverage" und Typ
+	 * {@code GridCoverage2D} oder {@link AbstractGridCoverageReader} hat. Sind
+	 * diese Bedingungen erfuellt, wird das 2. Attribut zurueckgegeben,
+	 * ansonsten die {@link FeatureCollection}.
 	 * 
 	 * @see {@link FeatureUtilities#wrapGridCoverage(GridCoverage2D)} and
 	 *      {@link FeatureUtilities#wrapGridCoverageReader(AbstractGridCoverage2DReader, GeneralParameterValue[])}
@@ -2358,8 +2389,8 @@
 
 		// Checking for exact match with empty spaces converted to _
 		for (AttributeDescriptor d : attributeDescriptors) {
-			if (d.getName().getLocalPart().replace(" ", "_").equals(
-					localName.replace(" ", "_"))) {
+			if (d.getName().getLocalPart().replace(" ", "_")
+					.equals(localName.replace(" ", "_"))) {
 				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
 						.getLocalPart());
 			}
@@ -2367,8 +2398,8 @@
 
 		// Checking for ignoreCase match with empty spaces converted to _
 		for (AttributeDescriptor d : attributeDescriptors) {
-			if (d.getName().getLocalPart().replace(" ", "_").equalsIgnoreCase(
-					localName.replace(" ", "_"))) {
+			if (d.getName().getLocalPart().replace(" ", "_")
+					.equalsIgnoreCase(localName.replace(" ", "_"))) {
 				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
 						.getLocalPart());
 			}

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-08-17 12:46:04 UTC (rev 979)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-08-18 15:40:54 UTC (rev 980)
@@ -237,6 +237,7 @@
 	 *            oder {@link FeatureCollection}
 	 * @return {@code null} falls kein Style generiert werden kann
 	 * 
+	 * @Deprectated Use FeatureUtil.createDefaultStyle and FeatureUtil.getGeometryForm
 	 */
 	public static Style createDefaultStyle(Object object) {
 		Style style = STYLE_BUILDER.createStyle(); // SK.. nicer default than



More information about the Schmitzm-commits mailing list