[Schmitzm-commits] r1279 - in trunk: src/schmitzm/geotools/feature src/schmitzm/geotools/styling src_junit/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 16 17:32:35 CET 2010
Author: alfonx
Date: 2010-11-16 17:32:34 +0100 (Tue, 16 Nov 2010)
New Revision: 1279
Modified:
trunk/src/schmitzm/geotools/feature/FeatureUtil.java
trunk/src/schmitzm/geotools/styling/StylingUtil.java
trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:
Fixed a AS to work better with geometries not stroed in a column called the_geom
Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java 2010-11-16 13:51:15 UTC (rev 1278)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java 2010-11-16 16:32:34 UTC (rev 1279)
@@ -2445,8 +2445,13 @@
Name bestmatch = findBestMatchingAttribute(schema, localName);
- if (bestmatch == null)
- return schema.getAttributeDescriptors().get(0).getName();
+ if (bestmatch == null && schema.getAttributeDescriptors().size() > 0) {
+ for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
+ if (!(Geometry.class.isAssignableFrom(ad.getType().getBinding())))
+ return ad.getName();
+ }
+ }
+
return bestmatch;
}
Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java 2010-11-16 13:51:15 UTC (rev 1278)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java 2010-11-16 16:32:34 UTC (rev 1279)
@@ -72,6 +72,7 @@
import org.geotools.factory.GeoTools;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.GeometryAttributeType;
+import org.geotools.feature.NameImpl;
import org.geotools.filter.AndImpl;
import org.geotools.filter.BinaryComparisonAbstract;
import org.geotools.filter.ConstantExpression;
@@ -122,6 +123,7 @@
import org.opengis.coverage.grid.GridCoverage;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.GeometryDescriptor;
import org.opengis.feature.type.Name;
import org.opengis.filter.And;
import org.opengis.filter.Filter;
@@ -613,25 +615,19 @@
@Override
public void visit(LineSymbolizer sym) {
- sym.setGeometryPropertyName(FeatureUtil
- .findBestMatchingAttributeFallBackFirst(schema,
- sym.getGeometryPropertyName()).getLocalPart());
+ correctGeometryPropertyname(schema, sym);
super.visit(sym);
}
@Override
public void visit(PointSymbolizer sym) {
- sym.setGeometryPropertyName(FeatureUtil
- .findBestMatchingAttributeFallBackFirst(schema,
- sym.getGeometryPropertyName()).getLocalPart());
+ correctGeometryPropertyname(schema, sym);
super.visit(sym);
}
@Override
public void visit(PolygonSymbolizer sym) {
- sym.setGeometryPropertyName(FeatureUtil
- .findBestMatchingAttributeFallBackFirst(schema,
- sym.getGeometryPropertyName()).getLocalPart());
+ correctGeometryPropertyname(schema, sym);
super.visit(sym);
}
@@ -643,9 +639,11 @@
@Override
public void visit(TextSymbolizer sym) {
- sym.setGeometryPropertyName(FeatureUtil
- .findBestMatchingAttributeFallBackFirst(schema,
- sym.getGeometryPropertyName()).getLocalPart());
+ // sym.setGeometryPropertyName(FeatureUtil
+ // .findBestMatchingAttributeFallBackFirst(schema,
+ // sym.getGeometryPropertyName()).getLocalPart());
+ correctGeometryPropertyname(schema, sym);
+
if (sym.getLabel() != null)
sym.setLabel(copy(sym.getLabel()));
@@ -3155,16 +3153,33 @@
}
public static String sldToString(Style style) throws TransformerException {
-
- // StringWriter w = null;
String xml = SLDTRANSFORMER.transform(style);
- // w = new StringWriter();
- // w.write(xml);
- // w.close();
- // w.getBuffer();
- // final String sldString = w.getBuffer().toString();
-
return xml;
+ }
+ public static void correctGeometryPropertyname(
+ final SimpleFeatureType schema, Symbolizer sym) {
+ String newGpn = sym.getGeometryPropertyName();
+
+ if (schema != null) {
+ // If we have a schema,
+ GeometryDescriptor geometryDescriptor = schema
+ .getGeometryDescriptor();
+ if (geometryDescriptor != null)
+ newGpn = geometryDescriptor.getName().toString();
+
+ if (newGpn != null) {
+ NameImpl found = FeatureUtil.findBestMatchingAttribute(schema,
+ newGpn);
+ if (found != null)
+ newGpn = found.getLocalPart();
+ else
+ newGpn = null;
+ }
+ } else {
+ newGpn = null;
+ }
+ sym.setGeometryPropertyName(newGpn == null ? null : newGpn.toString());
}
+
}
Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-11-16 13:51:15 UTC (rev 1278)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-11-16 16:32:34 UTC (rev 1279)
@@ -17,6 +17,7 @@
import junit.framework.TestCase;
+import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureCollection;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
@@ -24,6 +25,8 @@
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.ColorMap;
import org.geotools.styling.ColorMapEntry;
+import org.geotools.styling.PointSymbolizer;
+import org.geotools.styling.PolygonSymbolizer;
import org.geotools.styling.RasterSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
@@ -153,21 +156,21 @@
assertTrue(sldToString.contains("UTF-8"));
}
- // @Test
- // @Ignore
- // 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"));
- // }
+ @Test
+ public void testCorrectGeometryPropertynameNull() {
+ PointSymbolizer ps = StylingUtil.STYLE_BUILDER.createPointSymbolizer();
+ assertNull(ps.getGeometryPropertyName());
+ StylingUtil.correctGeometryPropertyname(null, ps);
+ assertNull(ps.getGeometryPropertyName());
+ }
+ @Test
+ public void testCorrectGeometryPropertynamePolygon() throws IOException {
+ PolygonSymbolizer ps = StylingUtil.STYLE_BUILDER.createPolygonSymbolizer();
+ FeatureSource<SimpleFeatureType, SimpleFeature> fs = TestingUtil.TestDatasetsVector.polygonSnow.getFeatureSource();
+ assertNull(ps.getGeometryPropertyName());
+ StylingUtil.correctGeometryPropertyname(fs.getSchema(), ps);
+ assertEquals("the_geom", ps.getGeometryPropertyName());
+ }
+
}
More information about the Schmitzm-commits
mailing list