From: <svn...@os...> - 2012-04-04 12:24:26
|
Author: nielscharlier Date: 2012-04-04 05:24:14 -0700 (Wed, 04 Apr 2012) New Revision: 38657 Modified: trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java trunk/modules/library/main/src/main/java/org/geotools/filter/ExpressionDOMParser.java trunk/modules/library/main/src/main/java/org/geotools/filter/FilterDOMParser.java trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserNamespaceTest.java trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java Log: GEOT-4006 SLDParser needs to set namespace context for Geometry/PropertyName Modified: trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java =================================================================== --- trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java 2012-04-03 10:58:10 UTC (rev 38656) +++ trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java 2012-04-04 12:24:14 UTC (rev 38657) @@ -24,16 +24,17 @@ import org.geotools.filter.identity.FeatureIdImpl; import org.opengis.feature.Attribute; import org.opengis.feature.ComplexAttribute; +import org.opengis.feature.GeometryAttribute; import org.opengis.feature.Property; import org.opengis.filter.identity.FeatureId; /** * This converter retrieves the values out of attributes. * @author Rini Angreani (CSIRO Earth Science and Resource Engineering) + * @author Niels Charlier * * * - * * @source $URL$ */ public class ComplexAttributeConverterFactory implements ConverterFactory { @@ -59,6 +60,20 @@ } }; } + + //GeometryAttribute unwrapper + if (GeometryAttribute.class.isAssignableFrom(source)) { + return new Converter() { + public Object convert(Object source, Class target) throws Exception { + if (source instanceof GeometryAttribute) { + return Converters.convert(((GeometryAttribute) source).getValue(), target); + + } + return null; + } + }; + } + // String to FeatureId comparison if (FeatureId.class.isAssignableFrom(target) && String.class.isAssignableFrom(source)) { return new Converter() { Modified: trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java =================================================================== --- trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java 2012-04-03 10:58:10 UTC (rev 38656) +++ trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java 2012-04-04 12:24:14 UTC (rev 38657) @@ -26,18 +26,27 @@ import org.geotools.data.complex.ComplexFeatureConstants; import org.geotools.feature.AttributeImpl; import org.geotools.feature.ComplexAttributeImpl; +import org.geotools.feature.GeometryAttributeImpl; +import org.geotools.feature.NameImpl; import org.geotools.feature.type.AttributeDescriptorImpl; +import org.geotools.feature.type.GeometryDescriptorImpl; +import org.geotools.feature.type.GeometryTypeImpl; import org.geotools.gml3.GMLSchema; import org.geotools.xs.XSSchema; import org.opengis.feature.Attribute; import org.opengis.feature.ComplexAttribute; +import org.opengis.feature.GeometryAttribute; import org.opengis.feature.Property; import org.opengis.feature.type.AttributeDescriptor; import org.opengis.filter.identity.FeatureId; +import com.vividsolutions.jts.geom.EmptyGeometry; +import com.vividsolutions.jts.geom.Geometry; + /** * Tests for {@link ComplexAttributeConverterFactory}. * * @author Rini Angreani (CSIRO Earth Science and Resource Engineering) + * @author Niels Charlier * * * @@ -101,4 +110,15 @@ assertEquals(id.getID(), "blah"); } + /** + * Test extracting geometry from geometryattribute should be successful. + */ + public void testGeometry() { + Geometry geometry = new EmptyGeometry(); + GeometryAttribute geoatt = new GeometryAttributeImpl(geometry, new GeometryDescriptorImpl(new GeometryTypeImpl(new NameImpl(""), EmptyGeometry.class, null, false, false, null, null, null), new NameImpl(""), 0, 0, false, null), null); + Geometry geometry2 = Converters.convert(geoatt, Geometry.class); + assertTrue(geometry == geometry2); + } + + } Modified: trunk/modules/library/main/src/main/java/org/geotools/filter/ExpressionDOMParser.java =================================================================== --- trunk/modules/library/main/src/main/java/org/geotools/filter/ExpressionDOMParser.java 2012-04-03 10:58:10 UTC (rev 38656) +++ trunk/modules/library/main/src/main/java/org/geotools/filter/ExpressionDOMParser.java 2012-04-04 12:24:14 UTC (rev 38657) @@ -47,6 +47,7 @@ * can get away without a full parser here. * * @author iant + * @author Niels Charlier * * * @source $URL$ @@ -58,9 +59,6 @@ /** Factory for creating filters. */ private FilterFactory2 ff; - /** Namespace Context for creating expressions */ - private NamespaceSupport namespaceContext = null; - /** Factory for creating geometry objects */ private static GeometryFactory gfac = new GeometryFactory(); @@ -95,9 +93,30 @@ ff = factory; } - /** Namespace Support Setter */ - public void setNamespaceContext( NamespaceSupport namespaceContext ){ - this.namespaceContext = namespaceContext; + + private static NamespaceSupport getNameSpaces(Node node) + { + NamespaceSupport namespaces = new NamespaceSupport(); + while (node != null) + { + NamedNodeMap atts = node.getAttributes(); + + if (atts != null) { + for (int i=0; i<atts.getLength(); i++){ + Node att = atts.item(i); + + if (att.getNamespaceURI() != null + && att.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/") + && namespaces.getURI(att.getLocalName()) == null){ + namespaces.declarePrefix(att.getLocalName(), att.getNodeValue()); + } + } + } + + node = node.getParentNode(); + } + + return namespaces; } /** @@ -344,7 +363,7 @@ //JD: trim whitespace here String value = child.getFirstChild().getNodeValue(); value = value != null ? value.trim() : value; - PropertyName attribute = ff.property( value, namespaceContext ); + PropertyName attribute = ff.property( value, getNameSpaces(root) ); // attribute.setAttributePath(child.getFirstChild().getNodeValue()); return attribute; Modified: trunk/modules/library/main/src/main/java/org/geotools/filter/FilterDOMParser.java =================================================================== --- trunk/modules/library/main/src/main/java/org/geotools/filter/FilterDOMParser.java 2012-04-03 10:58:10 UTC (rev 38656) +++ trunk/modules/library/main/src/main/java/org/geotools/filter/FilterDOMParser.java 2012-04-04 12:24:14 UTC (rev 38657) @@ -45,6 +45,7 @@ * A dom based parser to build filters as per OGC 01-067 * * @author Ian Turton, CCG + * @author Niels Charlier * * * @source $URL$ @@ -116,31 +117,6 @@ private FilterDOMParser() { } - private static NamespaceSupport getNameSpaces(Node node) - { - NamespaceSupport namespaces = new NamespaceSupport(); - while (node != null) - { - NamedNodeMap atts = node.getAttributes(); - - if (atts != null) { - for (int i=0; i<atts.getLength(); i++){ - Node att = atts.item(i); - - if (att.getNamespaceURI() != null - && att.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/") - && namespaces.getURI(att.getLocalName()) == null){ - namespaces.declarePrefix(att.getLocalName(), att.getNodeValue()); - } - } - } - - node = node.getParentNode(); - } - - return namespaces; - } - /** * Parses the filter using DOM. * @@ -151,11 +127,8 @@ * @task TODO: split up this insanely long method. */ public static org.opengis.filter.Filter parseFilter(Node root) { - //NC - NameSpaceSupport - NamespaceSupport namespaces = getNameSpaces(root); final ExpressionDOMParser expressionDOMParser = new ExpressionDOMParser(FILTER_FACT); - expressionDOMParser.setNamespaceContext(namespaces); LOGGER.finer("parsingFilter " + root.getLocalName()); @@ -604,11 +577,7 @@ private static PropertyIsNull parseNullFilter(Node nullNode) throws IllegalFilterException { - //NC - NameSpaceSupport - NamespaceSupport namespaces = getNameSpaces(nullNode); - final ExpressionDOMParser expressionDOMParser = new ExpressionDOMParser(FILTER_FACT); - expressionDOMParser.setNamespaceContext(namespaces); LOGGER.finest("parsing null node: " + nullNode); Modified: trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserNamespaceTest.java =================================================================== --- trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserNamespaceTest.java 2012-04-03 10:58:10 UTC (rev 38656) +++ trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserNamespaceTest.java 2012-04-04 12:24:14 UTC (rev 38657) @@ -31,9 +31,10 @@ import junit.framework.TestCase; /** + * Tests whether SLD Parser encodes Namespace in PropertyNames * - * - * @source $URL$ + * + * @author Niels Charlier */ public class SLDParserNamespaceTest extends TestCase { @@ -52,7 +53,10 @@ " </ogc:PropertyIsEqualTo>"+ " </ogc:Filter>"+ " <PolygonSymbolizer>"+ - " <Fill>"+ + " <Geometry> " + + " <ogc:PropertyName>gsml:shape</ogc:PropertyName>" + + " </Geometry> " + + " <Fill>"+ " <CssParameter name=\"fill\">#FF0000</CssParameter>"+ " </Fill>"+ " </PolygonSymbolizer>"+ @@ -84,6 +88,14 @@ assertEquals(ns.getURI("gml"), "http://www.opengis.net/gml"); assertEquals(ns.getURI("gsml"), "urn:cgi:xmlns:CGI:GeoSciML:2.0"); + Symbolizer s = rule.getSymbolizers()[0]; + expr = s.getGeometry(); + assert(expr instanceof PropertyName); + ns = ((PropertyName) expr).getNamespaceContext(); + assertEquals(ns.getURI("xlink"), null); + assertEquals(ns.getURI("gml"), "http://www.opengis.net/gml"); + assertEquals(ns.getURI("gsml"), "urn:cgi:xmlns:CGI:GeoSciML:2.0"); + } Modified: trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java =================================================================== --- trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java 2012-04-03 10:58:10 UTC (rev 38656) +++ trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java 2012-04-04 12:24:14 UTC (rev 38657) @@ -2658,15 +2658,14 @@ String geomName = null; if(geometry instanceof PropertyName) { - geomName = ((PropertyName) geometry).getPropertyName(); - return getAttributeCRS(geomName, schema); + return getAttributeCRS((PropertyName) geometry, schema); } else if(geometry == null) { return getAttributeCRS(null, schema); } else { StyleAttributeExtractor attExtractor = new StyleAttributeExtractor(); geometry.accept(attExtractor, null); - for(String name : attExtractor.getAttributeNameSet()) { - if(schema.getDescriptor(name) instanceof GeometryDescriptor) { + for(PropertyName name : attExtractor.getAttributes()) { + if(name.evaluate(schema) instanceof GeometryDescriptor) { return getAttributeCRS(name, schema); } } @@ -2686,13 +2685,13 @@ * @param schema * @return */ - org.opengis.referencing.crs.CoordinateReferenceSystem getAttributeCRS(String geomName, + org.opengis.referencing.crs.CoordinateReferenceSystem getAttributeCRS(PropertyName geomName, FeatureType schema) { - if (geomName == null || "".equals(geomName)) { + if (geomName == null || "".equals (geomName.getPropertyName()) { GeometryDescriptor geom = schema.getGeometryDescriptor(); return geom.getType().getCoordinateReferenceSystem(); } else { - GeometryDescriptor geom = (GeometryDescriptor) schema.getDescriptor( geomName ); + GeometryDescriptor geom = (GeometryDescriptor) geomName.evaluate(schema); return geom.getType().getCoordinateReferenceSystem(); } } |