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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 26 00:20:25 CEST 2010


Author: alfonx
Date: 2010-10-26 00:20:24 +0200 (Tue, 26 Oct 2010)
New Revision: 1166

Added:
   trunk/src_junit/schmitzm/geotools/styling/gdaloutput.txt
Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
   trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:
Improved the FeatureUtil.findBestMatching to used regex. Any noascii character will be changed to a noascii wildcard

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-10-25 08:50:00 UTC (rev 1165)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-10-25 22:20:24 UTC (rev 1166)
@@ -52,6 +52,7 @@
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.measure.converter.ConversionException;
@@ -60,6 +61,7 @@
 import javax.measure.unit.Unit;
 
 import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.xml.type.internal.RegEx;
 import org.geotools.coverage.grid.GridCoverage2D;
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
 import org.geotools.data.AbstractDataStore;
@@ -2039,9 +2041,10 @@
 				// When parsing GML it can be all mixed.
 				Log.info("This is "
 						+ schema.getGeometryDescriptor().getType().getBinding());
-				
-//		WOuld be cool, if we could set a default type here:		schema.getGeometryDescriptor().set...
 
+				// WOuld be cool, if we could set a default type here:
+				// schema.getGeometryDescriptor().set...
+
 			}
 
 			SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
@@ -2417,6 +2420,10 @@
 		if (localName == null) {
 			return null;
 		}
+		//
+		// if (localName.startsWith("DENSI")) {
+		// System.out.println(localName);
+		// }
 
 		// asdads _ _ _
 		List<AttributeDescriptor> attributeDescriptors = schema
@@ -2506,6 +2513,34 @@
 			}
 		}
 
+		/*
+		 * <dataAttribute functionA="0.0" functionX="1.0" localname="C�R�ALIC_1"
+		 * namespace="" visible="false" weight="15">
+		 * 
+		 * Für solche Fälle ersetzen wir alle � mit . in RegEx und versuchen
+		 * etwas zu finden
+		 */
+
+		// Checking for IGNORECASE match with a CLEANED version of the localname
+		for (AttributeDescriptor d : attributeDescriptors) {
+			//
+			// if (d.getLocalName().startsWith("DENSI")) {
+			// System.out.println(localName);
+			// }
+			String s1 = localName;
+			String s2 = s1.replaceAll("[^\\w]", "[\\w]");
+			String s3 = Pattern.quote(s2);
+			Pattern compile = Pattern.compile(s3);
+			Matcher matcher = compile.matcher(d.getLocalName());
+			if (matcher.find()) {
+				Log.info("New Matching Debug " + localName + " zu "
+						+ d.getLocalName());
+
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
+			}
+		}
+
 		return null;
 	}
 

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-10-25 08:50:00 UTC (rev 1165)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-10-25 22:20:24 UTC (rev 1166)
@@ -49,6 +49,8 @@
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.measure.unit.Unit;
 import javax.xml.transform.TransformerException;
@@ -62,6 +64,7 @@
 import org.geotools.coverage.GridSampleDimension;
 import org.geotools.coverage.grid.GridCoverage2D;
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+import org.geotools.data.DataUtilities;
 import org.geotools.data.FeatureSource;
 import org.geotools.data.memory.MemoryFeatureCollection;
 import org.geotools.data.store.EmptyFeatureCollection;
@@ -128,6 +131,7 @@
 import org.opengis.filter.expression.Literal;
 import org.opengis.filter.expression.PropertyName;
 
+import schmitzm.data.DataUtil;
 import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.feature.FeatureUtil;
 import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
@@ -2917,4 +2921,42 @@
 		return SLDTRANSFORMER.transform(sld);
 	}
 
+	static public ColorMap parseColormapToSld(URL colormapUrl)
+			throws IOException {
+		return parseColormapToSld(DataUtilities.urlToFile(colormapUrl));
+	}
+
+	static Pattern GDALCOLORMAP_4 = Pattern
+			.compile("(\\d+): (\\d+),(\\d+),(\\d+),(\\d+).*$");
+
+	static public ColorMap parseColormapToSld(File file) throws IOException {
+		String[] labels = new String[0];
+		double[] quantities = new double[0];
+		Color[] colors = new Color[0];
+
+		String readFileAsString = IOUtil.readFileAsString(file);
+		for (String line : readFileAsString.split("\\n")) {
+			Matcher matcher = GDALCOLORMAP_4.matcher(line);
+			if (matcher.find()) {
+				String q = matcher.group(1);
+				String r = matcher.group(2);
+				String g = matcher.group(3);
+				String b = matcher.group(4);
+				String o = matcher.group(5);
+				
+				Color color = new Color(Integer.valueOf(r), Integer.valueOf(g),Integer.valueOf(b), Integer.valueOf(o));
+				
+				// Arrays verlängern
+				labels = LangUtil.extendArray(labels, "");
+				colors = LangUtil.extendArray(colors, color);
+				quantities = LangUtil.extendArray(quantities, Double.valueOf(q));
+			}
+		}
+
+		int type = ColorMap.TYPE_VALUES;
+		ColorMap createColorMap = STYLE_BUILDER.createColorMap(labels,
+				quantities, colors, type);
+		return createColorMap;
+	}
+
 }

Modified: trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java	2010-10-25 08:50:00 UTC (rev 1165)
+++ trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java	2010-10-25 22:20:24 UTC (rev 1166)
@@ -11,6 +11,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 import org.geotools.data.DataUtilities;
 import org.geotools.data.FeatureSource;
@@ -189,4 +190,17 @@
 		assertEquals("N123123123", FeatureUtil.cleanAttname("123123123123"));
 	}
 
+	@Test
+	/**
+	 * 		 *     <dataAttribute functionA="0.0" functionX="1.0" localname="C�R�ALIC_1" namespace="" visible="false" weight="15">
+
+	 */
+	public void testFindBestMatchingAttribute()
+	{
+		String s1 = "C�R�ALIC_1";
+		String s2 = s1.replaceAll("[^\\w]", ".");
+		String s3 = Pattern.quote(s2);
+		Pattern.compile(s2);
+	}
+
 }

Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-10-25 08:50:00 UTC (rev 1165)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-10-25 22:20:24 UTC (rev 1166)
@@ -7,10 +7,14 @@
 import java.awt.Rectangle;
 import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
 
 import javax.swing.ImageIcon;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.xml.transform.TransformerException;
 
 import junit.framework.TestCase;
 
@@ -54,7 +58,8 @@
 	@Test
 	public void testSelectionStyles() throws Throwable {
 
-		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise.getFeatureCollection();
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
+				.getFeatureCollection();
 
 		JPanel jPanel = new JPanel();
 
@@ -111,7 +116,8 @@
 				wrongOrderColormap, 1.);
 		Style brokenStyle = StylingUtil.STYLE_BUILDER.createStyle(rS);
 
-		Style correctRasterStyle = StylingUtil.correctPropertyNames(brokenStyle, null);
+		Style correctRasterStyle = StylingUtil.correctPropertyNames(
+				brokenStyle, null);
 
 		RasterSymbolizer rs = (RasterSymbolizer) correctRasterStyle
 				.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
@@ -122,9 +128,20 @@
 	}
 
 	@Test
-	public void testGetSecondPropertyName()
-	{
-	
+	public void testGetSecondPropertyName() {
+
 	}
 
+	@Test
+	public void testParseColormapToSld() throws IOException, TransformerException {
+		URL colormapUrl = StylingUtilTest.class.getResource("gdaloutput.txt");
+		assertNotNull(colormapUrl);
+		ColorMap cm = StylingUtil.parseColormapToSld(colormapUrl);
+		assertEquals(256, cm.getColorMapEntries().length);
+		
+		RasterSymbolizer createRasterSymbolizer = StylingUtil.STYLE_BUILDER.createRasterSymbolizer(cm, 1.0);
+		Style style = StylingUtil.STYLE_BUILDER.createStyle(createRasterSymbolizer);
+		StylingUtil.saveStyleToSLD(style, new File("/home/stefan/Desktop/colors.sld"));
+	}
+
 }

Added: trunk/src_junit/schmitzm/geotools/styling/gdaloutput.txt
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/gdaloutput.txt	2010-10-25 08:50:00 UTC (rev 1165)
+++ trunk/src_junit/schmitzm/geotools/styling/gdaloutput.txt	2010-10-25 22:20:24 UTC (rev 1166)
@@ -0,0 +1,291 @@
+Driver: GTiff/GeoTIFF
+Files: satbild.tif
+Size is 9128, 10474
+Coordinate System is:
+PROJCS["Merchich_Lambert_Conformal_Conic",
+    GEOGCS["Merchich",
+        DATUM["Merchich",
+            SPHEROID["Clarke 1880 (IGN)",6378249.2,293.466020999993,
+                AUTHORITY["EPSG","7011"]],
+            AUTHORITY["EPSG","6261"]],
+        PRIMEM["Greenwich",0],
+        UNIT["degree",0.0174532925199433]],
+    PROJECTION["Lambert_Conformal_Conic_2SP"],
+    PARAMETER["standard_parallel_1",31.7239256],
+    PARAMETER["standard_parallel_2",34.8664577],
+    PARAMETER["latitude_of_origin",33.3],
+    PARAMETER["central_meridian",-5.4],
+    PARAMETER["false_easting",500000],
+    PARAMETER["false_northing",300000],
+    UNIT["metre",1,
+        AUTHORITY["EPSG","9001"]]]
+Origin = (273706.831999999994878,158065.021000000007916)
+Pixel Size = (25.000000000000000,-25.000000000000000)
+Metadata:
+  AREA_OR_POINT=Area
+Image Structure Metadata:
+  INTERLEAVE=BAND
+Corner Coordinates:
+Upper Left  (  273706.832,  158065.021) (  7d47'42.46"W, 31d59'46.61"N)
+Lower Left  (  273706.832, -103784.979) (  7d43'59.43"W, 29d38'10.99"N)
+Upper Right (  501906.832,  158065.021) (  5d22'47.33"W, 32d 1'10.93"N)
+Lower Right (  501906.832, -103784.979) (  5d22'49.21"W, 29d39'33.01"N)
+Center      (  387806.832,   27140.021) (  6d34'19.44"W, 30d50'0.08"N)
+Band 1 Block=9128x1 Type=Byte, ColorInterp=Palette
+  Color Table (RGB with 256 entries)
+    0: 80,56,52,255
+    1: 60,88,104,255
+    2: 172,208,136,255
+    3: 248,104,100,255
+    4: 32,48,76,255
+    5: 152,196,228,255
+    6: 76,40,92,255
+    7: 16,84,76,255
+    8: 144,116,112,255
+    9: 72,80,92,255
+   10: 248,248,232,255
+   11: 120,72,88,255
+   12: 36,132,120,255
+   13: 184,188,220,255
+   14: 144,176,164,255
+   15: 164,168,156,255
+   16: 56,48,96,255
+   17: 128,132,128,255
+   18: 136,152,136,255
+   19: 48,12,28,255
+   20: 124,144,152,255
+   21: 152,124,136,255
+   22: 88,80,120,255
+   23: 104,24,24,255
+   24: 96,96,76,255
+   25: 4,0,20,255
+   26: 48,64,76,255
+   27: 104,128,140,255
+   28: 152,132,168,255
+   29: 12,32,20,255
+   30: 96,56,92,255
+   31: 136,144,136,255
+   32: 32,92,120,255
+   33: 40,124,196,255
+   34: 208,204,200,255
+   35: 140,116,48,255
+   36: 76,68,120,255
+   37: 248,200,228,255
+   38: 28,92,112,255
+   39: 200,132,52,255
+   40: 120,132,128,255
+   41: 56,40,20,255
+   42: 224,200,168,255
+   43: 104,32,68,255
+   44: 0,0,4,255
+   45: 80,80,76,255
+   46: 152,172,184,255
+   47: 140,68,136,255
+   48: 80,16,20,255
+   49: 72,100,112,255
+   50: 56,56,60,255
+   51: 232,212,232,255
+   52: 176,140,156,255
+   53: 216,232,200,255
+   54: 200,196,52,255
+   55: 96,112,136,255
+   56: 104,112,108,255
+   57: 60,72,88,255
+   58: 88,52,92,255
+   59: 60,80,96,255
+   60: 4,12,32,255
+   61: 104,136,136,255
+   62: 104,124,152,255
+   63: 128,116,136,255
+   64: 164,20,40,255
+   65: 56,48,24,255
+   66: 56,72,76,255
+   67: 104,76,104,255
+   68: 128,92,32,255
+   69: 76,88,92,255
+   70: 60,80,104,255
+   71: 84,120,136,255
+   72: 148,76,40,255
+   73: 188,200,204,255
+   74: 96,76,112,255
+   75: 80,64,60,255
+   76: 212,236,224,255
+   77: 140,156,152,255
+   78: 108,128,128,255
+   79: 48,24,76,255
+   80: 20,48,60,255
+   81: 124,180,160,255
+   82: 108,120,128,255
+   83: 184,184,156,255
+   84: 136,116,112,255
+   85: 108,144,192,255
+   86: 140,156,160,255
+   87: 164,176,164,255
+   88: 232,244,248,255
+   89: 112,68,92,255
+   90: 8,0,4,255
+   91: 184,208,232,255
+   92: 80,24,64,255
+   93: 104,80,76,255
+   94: 124,144,136,255
+   95: 76,88,104,255
+   96: 48,32,20,255
+   97: 136,128,116,255
+   98: 144,124,136,255
+   99: 20,12,8,255
+  100: 208,144,168,255
+  101: 20,36,88,255
+  102: 20,40,24,255
+  103: 24,12,44,255
+  104: 104,112,120,255
+  105: 152,160,168,255
+  106: 56,72,96,255
+  107: 104,136,48,255
+  108: 120,116,136,255
+  109: 164,148,136,255
+  110: 152,220,192,255
+  111: 24,92,104,255
+  112: 124,116,52,255
+  113: 24,92,96,255
+  114: 248,248,116,255
+  115: 184,188,172,255
+  116: 152,128,160,255
+  117: 212,188,184,255
+  118: 76,68,112,255
+  119: 96,128,136,255
+  120: 128,64,132,255
+  121: 76,100,120,255
+  122: 200,160,136,255
+  123: 20,56,76,255
+  124: 56,48,60,255
+  125: 88,80,112,255
+  126: 224,244,248,255
+  127: 80,72,76,255
+  128: 144,168,164,255
+  129: 120,124,152,255
+  130: 96,72,104,255
+  131: 20,72,24,255
+  132: 76,56,104,255
+  133: 80,84,24,255
+  134: 128,36,40,255
+  135: 12,24,76,255
+  136: 96,120,136,255
+  137: 48,196,200,255
+  138: 248,228,100,255
+  139: 24,88,88,255
+  140: 152,128,152,255
+  141: 188,236,232,255
+  142: 84,112,136,255
+  143: 136,164,52,255
+  144: 188,224,172,255
+  145: 104,68,92,255
+  146: 124,152,196,255
+  147: 104,64,24,255
+  148: 64,92,112,255
+  149: 16,12,44,255
+  150: 4,16,20,255
+  151: 80,80,92,255
+  152: 228,204,200,255
+  153: 104,92,32,255
+  154: 60,64,76,255
+  155: 200,132,116,255
+  156: 176,188,216,255
+  157: 20,40,128,255
+  158: 136,124,136,255
+  159: 196,116,48,255
+  160: 152,184,216,255
+  161: 44,132,56,255
+  162: 148,144,136,255
+  163: 84,136,120,255
+  164: 216,20,40,255
+  165: 12,32,56,255
+  166: 80,64,76,255
+  167: 212,140,156,255
+  168: 88,76,104,255
+  169: 80,48,20,255
+  170: 232,244,228,255
+  171: 36,140,136,255
+  172: 120,76,136,255
+  173: 92,124,192,255
+  174: 96,96,92,255
+  175: 112,128,140,255
+  176: 56,80,24,255
+  177: 124,144,196,255
+  178: 56,56,76,255
+  179: 76,72,92,255
+  180: 164,168,172,255
+  181: 160,156,160,255
+  182: 224,228,168,255
+  183: 208,148,136,255
+  184: 80,100,112,255
+  185: 20,40,60,255
+  186: 208,208,232,255
+  187: 56,44,88,255
+  188: 152,172,220,255
+  189: 128,132,140,255
+  190: 4,16,4,255
+  191: 48,12,8,255
+  192: 60,100,104,255
+  193: 232,232,232,255
+  194: 88,96,92,255
+  195: 220,188,172,255
+  196: 124,116,116,255
+  197: 112,76,144,255
+  198: 56,40,56,255
+  199: 136,172,116,255
+  200: 104,72,68,255
+  201: 80,88,60,255
+  202: 128,92,76,255
+  203: 40,84,76,255
+  204: 108,120,140,255
+  205: 104,140,108,255
+  206: 108,200,200,255
+  207: 120,132,140,255
+  208: 160,156,152,255
+  209: 76,100,104,255
+  210: 60,96,96,255
+  211: 188,228,204,255
+  212: 208,148,212,255
+  213: 136,180,136,255
+  214: 248,248,240,255
+  215: 108,112,136,255
+  216: 104,76,148,255
+  217: 152,216,164,255
+  218: 52,48,76,255
+  219: 80,56,72,255
+  220: 212,236,244,255
+  221: 4,12,52,255
+  222: 20,80,60,255
+  223: 56,52,128,255
+  224: 116,124,200,255
+  225: 220,184,156,255
+  226: 196,116,112,255
+  227: 76,100,92,255
+  228: 84,148,136,255
+  229: 108,96,76,255
+  230: 96,84,152,255
+  231: 48,32,56,255
+  232: 200,124,136,255
+  233: 60,92,88,255
+  234: 152,136,208,255
+  235: 236,232,200,255
+  236: 88,80,160,255
+  237: 104,144,120,255
+  238: 80,96,76,255
+  239: 48,12,52,255
+  240: 56,92,76,255
+  241: 200,196,116,255
+  242: 124,204,212,255
+  243: 216,188,220,255
+  244: 76,76,160,255
+  245: 104,164,136,255
+  246: 56,84,60,255
+  247: 200,76,40,255
+  248: 152,228,228,255
+  249: 32,92,160,255
+  250: 216,208,136,255
+  251: 196,68,132,255
+  252: 248,248,0,255
+  253: 248,240,228,255
+  254: 240,244,248,255
+  255: 248,248,248,255


Property changes on: trunk/src_junit/schmitzm/geotools/styling/gdaloutput.txt
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list