[Schmitzm-commits] r1280 - in branches/2.3.x: src/schmitzm/geotools/feature src/schmitzm/geotools/feature/resource/locales src/schmitzm/geotools/styling src/skrueger/geotools/io src_junit/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 16 17:35:02 CET 2010
Author: alfonx
Date: 2010-11-16 17:35:02 +0100 (Tue, 16 Nov 2010)
New Revision: 1280
Modified:
branches/2.3.x/src/schmitzm/geotools/feature/FeatureUtil.java
branches/2.3.x/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_ru.properties
branches/2.3.x/src/schmitzm/geotools/styling/StylingUtil.java
branches/2.3.x/src/skrueger/geotools/io/TwistedLatLonFeatureSource.java
branches/2.3.x/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: branches/2.3.x/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- branches/2.3.x/src/schmitzm/geotools/feature/FeatureUtil.java 2010-11-16 16:32:34 UTC (rev 1279)
+++ branches/2.3.x/src/schmitzm/geotools/feature/FeatureUtil.java 2010-11-16 16:35:02 UTC (rev 1280)
@@ -2434,7 +2434,7 @@
* @param localName
* localname of an attribte to look for
*
- * @return If no match is found, the first attribute is returned.
+ * @return If no match is found, the first NON geometry attribute is returned.
*/
public static Name findBestMatchingAttributeFallBackFirst(
SimpleFeatureType schema, String localName) {
@@ -2444,8 +2444,12 @@
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: branches/2.3.x/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_ru.properties
===================================================================
--- branches/2.3.x/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_ru.properties 2010-11-16 16:32:34 UTC (rev 1279)
+++ branches/2.3.x/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_ru.properties 2010-11-16 16:35:02 UTC (rev 1280)
@@ -42,4 +42,4 @@
org.geotools.err.attr.name.length=\u0422\u043E\u043B\u044C\u043A\u043E 10 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D\u044B \u0434\u043B\u044F \u0438\u043C\u0435\u043D\u0438\!
org.geotools.err.attr.name.null=\u0418\u043C\u044F \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u043F\u0443\u0441\u0442\u044B\u043C\!
org.geotools.err.attr.name.start=\u0418\u043C\u044F \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0434\u043E\u043B\u0436\u043D\u043E \u043D\u0430\u0447\u0438\u043D\u0430\u0442\u0441\u044C\u044F \u0441 \u0441\u0438\u043C\u0432\u043E\u043B\u0430 (A-Z,a-z)\!
-org.geotools.err.attr.name=\u0418\u043C\u044F \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043D\u0435 \u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u043E
\ No newline at end of file
+org.geotools.err.attr.name=\u0418\u043C\u044F \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043D\u0435 \u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u043E
Modified: branches/2.3.x/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/2.3.x/src/schmitzm/geotools/styling/StylingUtil.java 2010-11-16 16:32:34 UTC (rev 1279)
+++ branches/2.3.x/src/schmitzm/geotools/styling/StylingUtil.java 2010-11-16 16:35:02 UTC (rev 1280)
@@ -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;
@@ -605,25 +607,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);
}
@@ -634,9 +630,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()));
@@ -3136,4 +3134,31 @@
saveStyleToSld(style, tempFile);
return validates(new FileInputStream(tempFile));
}
+
+
+ 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: branches/2.3.x/src/skrueger/geotools/io/TwistedLatLonFeatureSource.java
===================================================================
--- branches/2.3.x/src/skrueger/geotools/io/TwistedLatLonFeatureSource.java 2010-11-16 16:32:34 UTC (rev 1279)
+++ branches/2.3.x/src/skrueger/geotools/io/TwistedLatLonFeatureSource.java 2010-11-16 16:35:02 UTC (rev 1280)
@@ -29,7 +29,6 @@
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.crs.GeographicCRS;
-import schmitzm.geotools.feature.FeatureUtil;
import schmitzm.lang.LangUtil;
import com.vividsolutions.jts.geom.Envelope;
Modified: branches/2.3.x/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- branches/2.3.x/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-11-16 16:32:34 UTC (rev 1279)
+++ branches/2.3.x/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-11-16 16:35:02 UTC (rev 1280)
@@ -7,6 +7,7 @@
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
+import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
@@ -14,6 +15,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;
@@ -21,6 +23,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;
@@ -136,4 +140,21 @@
// 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