[Schmitzm-commits] r44 - in trunk: dist src/schmitzm/geotools/feature src/schmitzm/geotools/gui src/schmitzm/geotools/styling src/skrueger/i8n

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 14 22:23:44 CEST 2009


Author: alfonx
Date: 2009-04-14 22:23:41 +0200 (Tue, 14 Apr 2009)
New Revision: 44

Modified:
   trunk/dist/schmitzm-src.zip
   trunk/dist/schmitzm.jar
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/gui/JMapPane.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/skrueger/i8n/I8NUtil.java
   trunk/src/skrueger/i8n/Translation.java
Log:
* Added a static public convenience method isEmpty to i8n.Translation which deals with null, "", and the deprectaed NO_TRANSLATION constant.
* Moved the method "public static MemoryFeatureCollection filterSLDVisibleOnly(...)" from FeatureUtil to StylingUtil.

Modified: trunk/dist/schmitzm-src.zip
===================================================================
(Binary files differ)

Modified: trunk/dist/schmitzm.jar
===================================================================
(Binary files differ)

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-04-14 14:19:30 UTC (rev 43)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-04-14 20:23:41 UTC (rev 44)
@@ -20,8 +20,6 @@
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -30,7 +28,6 @@
 import org.apache.log4j.Logger;
 import org.geotools.data.DataUtilities;
 import org.geotools.data.FeatureSource;
-import org.geotools.data.memory.MemoryFeatureCollection;
 import org.geotools.feature.AttributeType;
 import org.geotools.feature.AttributeTypeFactory;
 import org.geotools.feature.DefaultFeatureCollection;
@@ -45,18 +42,11 @@
 import org.geotools.feature.SchemaException;
 import org.geotools.feature.type.GeometricAttributeType;
 import org.geotools.map.MapLayer;
-import org.geotools.renderer.lite.RendererUtilities;
-import org.geotools.styling.FeatureTypeStyle;
-import org.geotools.styling.LineSymbolizer;
-import org.geotools.styling.PointSymbolizer;
-import org.geotools.styling.PolygonSymbolizer;
-import org.geotools.styling.Rule;
 import org.geotools.styling.Style;
 import org.geotools.styling.StyleBuilder;
 import org.geotools.styling.Symbolizer;
 import org.geotools.styling.Mark;
 import org.geotools.styling.Graphic;
-import org.opengis.filter.Filter;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
 import schmitzm.lang.LangUtil;
@@ -179,99 +169,6 @@
   }
 
     /**
-	 *  SLD Rules können die Paramter MinScaleDenominator und
-	 * MaxScaleDenominator enthalten. Dadurch können Elemente für manche
-	 * Zoom-Stufen deaktiviert werden.
-	 *
-	 * Kommentar: "Sichtbarkeit" bezieht es nicht darauf, ob die Elemente auf dem Kartenausschnitt sichtbar sind, sondern um die SLD Regeln, welche das Feature evt. nur Scalenabhängig zeichnen.
-	 *
-	 * @param fc
-	 *            Die zu filternde FeatureCollection. Diese wird nicht
-	 *            verändert.
-	 * @param style
-	 *            Der Style, mit dem die Features gerendert werden (z.b.
-	 *            layer.getStyle() )
-	 *
-	 * @param scaleDenominator Der aktuelle ScaleDenomitor für den die Sichtbarkeit ermittelt wird.
-	 *
-	 * @see RendererUtilities.calculateOGCScale
-   *
-	 * @return Eine FeatureCollection in welcher nur die Features enthalten
-	 *         sind, welche bei aktuellen Scale mit dem übergebenen Style
-	 *         gerendert werden.
-	 *
-	 *         TODO Was ist mit raster?!
-	 *
-	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
-	 */
-	public static MemoryFeatureCollection filterSLDVisibleOnly(final FeatureCollection fc,
-			final Style style, final Double scaleDenominator) {
-
-		// Eine im Speicher gehaltene FeatureCollection der sichtbaren
-		MemoryFeatureCollection fcVisible = new MemoryFeatureCollection(fc
-				.getFeatureType());
-
-		// Prüfen aller Features in der Collection
-		Iterator<Feature> fcIt = fc.iterator();
-		while (fcIt.hasNext()) {
-			Feature feature = fcIt.next();
-
-			for (FeatureTypeStyle fts : style.getFeatureTypeStyles()) {
-				List<Rule> rules = fts.rules();
-
-				for (Rule rule : rules) {
-					double maxScaleDenominator = rule.getMaxScaleDenominator();
-					double minScaleDenominator = rule.getMinScaleDenominator();
-
-					// 1. Check: Trifft die Rule auf den aktuellen Scale der JMapPane?
-					if ((minScaleDenominator > scaleDenominator)
-							|| (scaleDenominator > maxScaleDenominator)) {
-						continue;
-					}
-
-					// 2. Check: Eine Rule ist gülrig, aber trifft der Filter für dieses Feature?
-					Filter rFilter = rule.getFilter();
-					if ( (rFilter != null) && (!rFilter.evaluate(feature))) continue;
-
-
-					// 3. Check: Passt einer der Symbolizer dieser Rule zu dem Feature? Dieser Check wird in
-				    // "real world" meistens klappen, es sei denn, ein Hansel gibt einen LineSymbolizer für ein PointLayer an.
-					boolean passt = false;
-					for (Symbolizer symb : rule.getSymbolizers()){
-						Geometry geom = feature.getDefaultGeometry();
-						if ( (geom instanceof MultiPoint) || (geom instanceof com.vividsolutions.jts.geom.Point)){
-							if (symb instanceof PointSymbolizer) {
-								passt =true; break;
-							}
-					    } else
-							if ( (geom instanceof MultiLineString) || (geom instanceof LineString)){
-								if (symb instanceof LineSymbolizer) {
-									passt =true; break;
-								}
-					    	}else
-								if ( (geom instanceof MultiPolygon) || (geom instanceof Polygon)){
-									if (symb instanceof PolygonSymbolizer) {
-										passt =true; break;
-									}
-						    	}
-					}
-					if (!passt) continue;
-
-					// Nun sollte das feature wiklich sichtbar sein
-					fcVisible.add( feature);
-				}
-			}
-		}
-
-//		LOGGER.info("filterSLDVisibleOnly removed "+ (fc.size() - fcVisible.size()) + " features.");
-
-		return fcVisible;
-	}
-
-
-
-
-  /**
    * Extrahiert alle Geometrien aus einem Feature.
    * @param f Feature
    * @return Array aller Geometrien im Feature.

Modified: trunk/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-04-14 14:19:30 UTC (rev 43)
+++ trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-04-14 20:23:41 UTC (rev 44)
@@ -76,7 +76,6 @@
 import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.GTUtil;
 import schmitzm.geotools.JTSUtil;
-import schmitzm.geotools.feature.FeatureUtil;
 import schmitzm.geotools.grid.GridUtil;
 import schmitzm.geotools.map.event.FeatureSelectedEvent;
 import schmitzm.geotools.map.event.GeneralSelectionEvent;
@@ -86,6 +85,7 @@
 import schmitzm.geotools.map.event.JMapPaneListener;
 import schmitzm.geotools.map.event.MapAreaChangedEvent;
 import schmitzm.geotools.map.event.ScaleChangedEvent;
+import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.swing.SwingUtil;
 
 import com.vividsolutions.jts.geom.Coordinate;
@@ -1619,7 +1619,7 @@
 						getContext().getCoordinateReferenceSystem()),
 						getSize().width, null);
 
-		return FeatureUtil.filterSLDVisibleOnly(fc, style, scaleDenominator);
+		return StylingUtil.filterSLDVisibleOnly(fc, style, scaleDenominator);
 	}
 
 	/**

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-04-14 14:19:30 UTC (rev 43)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-04-14 20:23:41 UTC (rev 44)
@@ -24,6 +24,7 @@
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -36,10 +37,13 @@
 import org.geotools.coverage.GridSampleDimension;
 import org.geotools.coverage.grid.GridCoverage2D;
 import org.geotools.data.FeatureSource;
+import org.geotools.data.memory.MemoryFeatureCollection;
 import org.geotools.factory.CommonFactoryFinder;
 import org.geotools.factory.Hints;
+import org.geotools.feature.Feature;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.GeometryAttributeType;
+import org.geotools.renderer.lite.RendererUtilities;
 import org.geotools.resources.i18n.Vocabulary;
 import org.geotools.resources.i18n.VocabularyKeys;
 import org.geotools.styling.ColorMap;
@@ -48,6 +52,9 @@
 import org.geotools.styling.ColorMapImpl;
 import org.geotools.styling.FeatureTypeStyle;
 import org.geotools.styling.FeatureTypeStyleImpl;
+import org.geotools.styling.LineSymbolizer;
+import org.geotools.styling.PointSymbolizer;
+import org.geotools.styling.PolygonSymbolizer;
 import org.geotools.styling.RasterSymbolizer;
 import org.geotools.styling.RasterSymbolizerImpl;
 import org.geotools.styling.Rule;
@@ -63,8 +70,17 @@
 import org.jdom.output.XMLOutputter;
 import org.opengis.coverage.grid.Grid;
 import org.opengis.coverage.grid.GridCoverage;
+import org.opengis.filter.Filter;
 import org.opengis.filter.expression.Expression;
 
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.MultiLineString;
+import com.vividsolutions.jts.geom.MultiPoint;
+import com.vividsolutions.jts.geom.MultiPolygon;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
+
 import schmitzm.geotools.feature.FeatureUtil;
 import schmitzm.geotools.grid.GridUtil;
 
@@ -771,9 +787,146 @@
 		saveStyleToSLD(style, exportFile, Charset.forName("ISO-8859-1") );
 	}
 
+	/**
+	 * SLD Rules können die Paramter MinScaleDenominator und MaxScaleDenominator
+	 * enthalten. Dadurch können Elemente für manche Zoom-Stufen deaktiviert
+	 * werden.
+	 * 
+	 * Kommentar: "Sichtbarkeit" bezieht es nicht darauf, ob die Elemente auf
+	 * dem Kartenausschnitt sichtbar sind, sondern um die SLD Regeln, welche das
+	 * Feature evt. nur Scalenabhängig zeichnen.
+	 * 
+	 * @param fc
+	 *            Die zu filternde FeatureCollection. Diese wird nicht
+	 *            verändert.
+	 * @param style
+	 *            Der Style, mit dem die Features gerendert werden (z.b.
+	 *            layer.getStyle() )
+	 * 
+	 * @param scaleDenominator
+	 *            Der aktuelle ScaleDenomitor für den die Sichtbarkeit ermittelt
+	 *            wird.
+	 * 
+	 * @see RendererUtilities.calculateOGCScale
+	 * 
+	 * @return Eine FeatureCollection in welcher nur die Features enthalten
+	 *         sind, welche bei aktuellen Scale mit dem übergebenen Style
+	 *         gerendert werden.
+	 * 
+	 *         TODO Was ist mit raster?!
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public static MemoryFeatureCollection filterSLDVisibleOnly(
+			final FeatureCollection fc, final Style style,
+			final Double scaleDenominator) {
+	
+		// Eine im Speicher gehaltene FeatureCollection der sichtbaren
+		MemoryFeatureCollection fcVisible = new MemoryFeatureCollection(fc
+				.getFeatureType());
+	
+		// Prüfen aller Features in der Collection
+		Iterator<Feature> fcIt = fc.iterator();
+	
+		try {
 
+			while (fcIt.hasNext()) {
+				Feature feature = fcIt.next();
 
+				for (FeatureTypeStyle fts : style.getFeatureTypeStyles()) {
+					List<Rule> rules = fts.rules();
 
+					for (Rule rule : rules) {
+						double maxScaleDenominator = rule
+								.getMaxScaleDenominator();
+						double minScaleDenominator = rule
+								.getMinScaleDenominator();
+
+						// 1. Check: Trifft die Rule auf den aktuellen Scale der
+						// JMapPane?
+						if ((minScaleDenominator > scaleDenominator)
+								|| (scaleDenominator > maxScaleDenominator)) {
+							continue;
+						}
+
+						// 2. Check: Eine Rule ist gülrig, aber trifft der
+						// Filter
+						// für dieses Feature?
+						Filter rFilter = rule.getFilter();
+						if ((rFilter != null) && (!rFilter.evaluate(feature)))
+							continue;
+
+						// 3. Check: Passt einer der Symbolizer dieser Rule zu
+						// dem
+						// Feature? Dieser Check wird in
+						// "real world" meistens klappen, es sei denn, ein
+						// Hansel
+						// gibt einen LineSymbolizer für ein PointLayer an.
+						boolean passt = false;
+						for (Symbolizer symb : rule.getSymbolizers()) {
+							Geometry geom = feature.getDefaultGeometry();
+							if ((geom instanceof MultiPoint)
+									|| (geom instanceof com.vividsolutions.jts.geom.Point)) {
+								if (symb instanceof PointSymbolizer) {
+									passt = true;
+									break;
+								}
+							} else if ((geom instanceof MultiLineString)
+									|| (geom instanceof LineString)) {
+								if (symb instanceof LineSymbolizer) {
+									passt = true;
+									break;
+								}
+							} else if ((geom instanceof MultiPolygon)
+									|| (geom instanceof Polygon)) {
+								if (symb instanceof PolygonSymbolizer) {
+									passt = true;
+									break;
+								}
+							}
+						}
+						if (!passt)
+							continue;
+
+						// Nun sollte das feature wiklich sichtbar sein
+						fcVisible.add(feature);
+					}
+				}
+			}
+		} catch (java.lang.IllegalStateException e) {
+			LOGGER.error(e);
+			/**
+			 * SK: 14.Apri 2009. It happened a few time to that fcIt.hasNext
+			 * suddenly threw an exception for the "africa countries.shp": Exception
+			 * in thread "AWT-EventQueue-0" java.lang.IllegalStateException:
+			 * ShapeType changed illegally from Polygon to Undefined at
+			 * org.geotools.
+			 * data.shapefile.shp.ShapefileReader.nextRecord(ShapefileReader
+			 * .java:452) at org.geotools.data.shapefile.indexed.
+			 * IndexedShapefileDataStore$Reader
+			 * .next(IndexedShapefileDataStore.java:1272) at
+			 * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.java:92) at
+			 * org
+			 * .geotools.data.FilteringFeatureReader.hasNext(FilteringFeatureReader
+			 * .java:125) at org.geotools.data.store.FeatureReaderIterator.hasNext(
+			 * FeatureReaderIterator.java:44) at
+			 * schmitzm.geotools.feature.FeatureUtil
+			 * .filterSLDVisibleOnly(FeatureUtil.java:216) *
+			 * 
+			 */
+		}
+	
+		// LOGGER.info("filterSLDVisibleOnly removed "+ (fc.size() -
+		// fcVisible.size()) + " features.");
+	
+		return fcVisible;
+	}
+
+
+	
+
+
 //	/**
 //	 * Sorts a {@link ColorMap} by its quantity values. This is mentioned in the
 //	 * OGC SLD Definition, page 52:

Modified: trunk/src/skrueger/i8n/I8NUtil.java
===================================================================
--- trunk/src/skrueger/i8n/I8NUtil.java	2009-04-14 14:19:30 UTC (rev 43)
+++ trunk/src/skrueger/i8n/I8NUtil.java	2009-04-14 20:23:41 UTC (rev 44)
@@ -44,12 +44,46 @@
 	 */
 	public static Locale getLocaleFor(String code) {
 		for (Locale l : Locale.getAvailableLocales()) {
-//			System.out.println(l.getLanguage()+" not = "+code);
+			// System.out.println(l.getLanguage()+" not = "+code);
 			if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) {
 				return l;
 			}
 		}
-		LOGGER.error("Can't create a Locale for code "+code+"! Returning the system default locale to avoid NPEs.");
+		LOGGER.error("Can't create a Locale for code " + code
+				+ "! Returning the system default locale to avoid NPEs.");
 		return Locale.getDefault();
 	}
+
+	/**
+	 * A convenience method that checks if the {@link Translation} object
+	 * contains a translation for the active language. A {@link String}
+	 * containing only spaces will return <code>false</code>.
+	 * 
+	 * @param trans
+	 *            {@link Translation} to check.
+	 */
+	public static boolean isEmpty(final Translation trans) {
+		if (trans == null)
+			return true;
+		return isEmpty(trans.toString());
+	}
+
+	/**
+	 * A convenience method that checks if the {@link String} returned by from a
+	 * {@link Translation} object contains a "valid" translation for the active
+	 * language. A {@link String} containing only spaces or equals
+	 * {@link Translation}.NO_TRANSLATION will return <code>false</code>.
+	 * 
+	 * @param transString
+	 *            {@link String} to check.
+	 */
+	public static boolean isEmpty(final String transString) {
+		if (transString == null)
+			return true;
+		if (transString.trim().isEmpty())
+			return true;
+		if (transString.equals(Translation.NO_TRANSLATION))
+			return true;
+		return false;
+	}
 }

Modified: trunk/src/skrueger/i8n/Translation.java
===================================================================
--- trunk/src/skrueger/i8n/Translation.java	2009-04-14 14:19:30 UTC (rev 43)
+++ trunk/src/skrueger/i8n/Translation.java	2009-04-14 20:23:41 UTC (rev 44)
@@ -128,7 +128,6 @@
 	 * Sometimes Translations are optional, like for keywords.
 	 */
 	public Translation() {
-		super();
 	}
 
 	/**
@@ -145,7 +144,7 @@
 	public void fromOneLine(final String oneLineCoded) {
 		clear();
 		if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {
-			put(DEFAULT_KEY, NO_TRANSLATION);
+			put(DEFAULT_KEY, "");
 			return;
 		}
 



More information about the Schmitzm-commits mailing list