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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Apr 24 18:19:45 CEST 2010


Author: alfonx
Date: 2010-04-24 18:19:42 +0200 (Sat, 24 Apr 2010)
New Revision: 821

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/schmitzm/lang/LangUtil.java
Log:
Neue SLD zu String Hilfsmethoden in StylingUtil

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-04-23 15:04:27 UTC (rev 820)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-04-24 16:19:42 UTC (rev 821)
@@ -2028,9 +2028,9 @@
 	 * This method determines the average distance to next centroid.
 	 * 
 	 * @param styledFeatures
+	 * @throws IOException if features can't be accessed
 	 */
-	public static Double calcAvgNN(StyledFeaturesInterface<?> styledFeatures) {
-		try {
+	public static Double calcAvgNN(StyledFeaturesInterface<?> styledFeatures) throws IOException {
 			final Integer SAMPLESIZE = 60;
 
 			final DynamicBin1D dists = new DynamicBin1D();
@@ -2057,9 +2057,13 @@
 				}
 
 			});
-			final Query random100query = new DefaultQuery(styledFeatures
+			final DefaultQuery random100query = new DefaultQuery(styledFeatures
 					.getSchema().getTypeName(), filter, SAMPLESIZE, null,
 					"random query for " + ratio);
+			
+			// nur das geometrieobjekt abfragen 
+			random100query.setPropertyNames(new String[] {styledFeatures
+					.getSchema().getGeometryDescriptor().getLocalName()});
 
 			final GeometryForm geometryForm = FeatureUtil
 					.getGeometryForm(styledFeatures.getSchema());
@@ -2075,7 +2079,7 @@
 				switch (geometryForm) {
 				case POINT:
 					final FeatureCollection<SimpleFeatureType, SimpleFeature> allFeatures = styledFeatures
-							.getFeatureCollectionFiltered();
+							.getFeatureSource().getFeatures(random100query);
 
 					dists.add(extractedPoint(allFeatures, f1));
 					break;
@@ -2104,9 +2108,6 @@
 
 			return inPixels;
 
-		} catch (IOException e) {
-			throw new RuntimeException("Can calculate AvgNN!", e);
-		}
 	}
 
 	private static double extractedPoint(

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-04-23 15:04:27 UTC (rev 820)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-04-24 16:19:42 UTC (rev 821)
@@ -38,6 +38,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.lang.reflect.Array;
 import java.net.URL;
 import java.nio.charset.Charset;
@@ -104,12 +106,14 @@
 import org.geotools.styling.Style;
 import org.geotools.styling.StyleBuilder;
 import org.geotools.styling.StyleFactory;
+import org.geotools.styling.StyledLayerDescriptor;
 import org.geotools.styling.Symbolizer;
 import org.geotools.styling.TextSymbolizer;
 import org.geotools.styling.visitor.DuplicatingStyleVisitor;
 import org.geotools.util.NumberRange;
 import org.jdom.Element;
 import org.jdom.output.XMLOutputter;
+import org.jfree.util.Log;
 import org.opengis.coverage.grid.Grid;
 import org.opengis.coverage.grid.GridCoverage;
 import org.opengis.feature.simple.SimpleFeature;
@@ -1070,9 +1074,7 @@
 			IOUtils.closeQuietly(inputStream);
 		}
 	}
-	
 
-
 	/**
 	 * Saves the {@link Style} to OGC SLD. Overwrites any existing file. If a
 	 * FeatureTypeStyle for selection is used, it is automatically removed. This
@@ -1083,72 +1085,51 @@
 	 * @param origStyle
 	 *            {@link Style} to save. Any selectino related FeatureTypeStyle
 	 *            will be removed.
-	 * @param charset
-	 *            The charset to use for the XML, e.g. <?xml version="1.0"
-	 *            encoding="UTF-8"?>. If <code>null</code>, non is set and the
-	 *            system default is used.
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
+	 * 
+	 * @return <code>true</code> if the file was really written.
+	 *         <code>false</code> means, that the existing file already was
+	 *         equals.
+	 * @throws IOException 
+	 * @throws TransformerException 
 	 */
-	public static final boolean saveStyleToSLD(Style origStyle,
-			File exportFile, Charset charset) throws TransformerException,
-			IOException {
+	public static final boolean saveStyleToSLD(Style origStyle, File exportFile) throws TransformerException, IOException {
+
 		// Wenn Datei nicht mit .sld endet, die Dateierweiterung
 		// anhängen
 		exportFile = IOUtil.appendFileExt(exportFile, ".sld");
 
 		SLDTRANSFORMER.setIndentation(2);
-		// LOGGER.debug("default charset = "+ Charset.defaultCharset());
-		// SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
 
 		Style exportStyle = removeSelectionFeatureTypeStyle(origStyle);
 
+		// Nur in Datei speichern, wenn
 		if (!isStyleDifferent(exportStyle, exportFile)) {
-			// LOGGER.debug("Style " + exportFile +
-			// " didn't change, not saving.");
 			return false;
 		}
 
 		SLDTRANSFORMER.transform(exportStyle, new FileWriter(exportFile));
-
 		return true;
 	}
 
-	
-	
 	/**
-	 * Exports the {@link Style} to OGC SLD. If a FeatureTypeStyle for selection is used, it is automatically removed. 
+	 * Exports the {@link Style} to OGC SLD. If a FeatureTypeStyle for selection
+	 * is used, it is automatically removed.
 	 * 
-	 * @param origStyle
+	 * @param style
 	 *            {@link Style} to save. Any selectino related FeatureTypeStyle
 	 *            will be removed.
-	 * @param charset
-	 *            The charset to use for the XML, e.g. <?xml version="1.0"
-	 *            encoding="UTF-8"?>. If <code>null</code>, non is set and the
-	 *            system default is used.
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
+	 * @throws TransformerException
 	 */
-	public static final boolean saveStyleToSLD(Style origStyle,
-			OutputStream exportStream, Charset charset) throws TransformerException {
-
+	public static final void saveStyleToSLD(Style style,
+			OutputStream exportStream) throws TransformerException {
 		SLDTRANSFORMER.setIndentation(2);
-		// LOGGER.debug("default charset = "+ Charset.defaultCharset());
-		// SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
-
-//		Style exportStyle = removeSelectionFeatureTypeStyle(origStyle);
-
-//		if (!isStyleDifferent(exportStyle, exportFile)) {
-//			// LOGGER.debug("Style " + exportFile +
-//			// " didn't change, not saving.");
-//			return false;
-//		}
-
-		SLDTRANSFORMER.transform(origStyle, exportStream);
-
-		return true;
+		SLDTRANSFORMER.transform(style, exportStream);
 	}
 
 	/**
@@ -1268,24 +1249,6 @@
 	}
 
 	/**
-	 * Saves the {@link Style} to OGC SLD using UTF-8 as charset. Overwrites any
-	 * existing file.
-	 * 
-	 * @param style
-	 *            {@link Style} to save
-	 * 
-	 * @throws TransformerException
-	 * @throws IOException
-	 * 
-	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
-	 *         Kr&uuml;ger</a>
-	 */
-	public static final boolean saveStyleToSLD(Style style, File exportFile)
-			throws TransformerException, IOException {
-		return saveStyleToSLD(style, exportFile, null);
-	}
-
-	/**
 	 * SLD Rules können die Paramter MinScaleDenominator und MaxScaleDenominator
 	 * enthalten. Dadurch können Elemente für manche Zoom-Stufen deaktiviert
 	 * werden.
@@ -2871,4 +2834,42 @@
 				Double.NaN);
 	}
 
+	public static StyledLayerDescriptor loadStyledLayerDescriptor(Reader reader) {
+		StyledLayerDescriptor sld = null;
+		try {
+			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY,
+					reader);
+			sld = stylereader.parseSLD();
+			return sld;
+		} catch (Exception e) {
+			LOGGER
+					.warn(
+							" ... no StyledLayerDescriptor recognized. Returning null ",
+							e);
+			return sld;
+		}
+	}
+
+	public static StyledLayerDescriptor loadStyledLayerDescriptor(
+			InputStream inputStream) {
+		StyledLayerDescriptor sld = null;
+		try {
+			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY,
+					inputStream);
+			sld = stylereader.parseSLD();
+			return sld;
+		} catch (Exception e) {
+			LOGGER
+					.warn(
+							" ... no StyledLayerDescriptor recognized. Returning null ",
+							e);
+			return sld;
+		}
+	}
+
+	public static String toXMLString(StyledLayerDescriptor sld)
+			throws TransformerException {
+		return SLDTRANSFORMER.transform(sld);
+	}
+
 }

Modified: trunk/src/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/src/schmitzm/lang/LangUtil.java	2010-04-23 15:04:27 UTC (rev 820)
+++ trunk/src/schmitzm/lang/LangUtil.java	2010-04-24 16:19:42 UTC (rev 821)
@@ -1372,4 +1372,15 @@
 							+ numClass.getCanonicalName());
 		}
 	}
+
+	/**
+	 * Calls Thread.sleep( delay ) and drops any InterruptedException thrown
+	 * @param delay ms to sleep
+	 */
+	public static void sleepExceptionless(int delay) {
+		try {
+			Thread.sleep(delay);
+		} catch (InterruptedException e) {
+		}
+	}
 }



More information about the Schmitzm-commits mailing list