This is an automated email from the ASF dual-hosted git repository.
jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 3dae4f4 Portrayal : fix cases where rule filter properties are not
returned
3dae4f4 is described below
commit 3dae4f46566167cdf4e2b024cbc5e102393bb791
Author: jsorel <[email protected]>
AuthorDate: Fri Feb 19 10:32:42 2021 +0100
Portrayal : fix cases where rule filter properties are not returned
---
.../org/apache/sis/internal/map/SEPortrayer.java | 5 +-
.../sis/internal/map/MockLineSymbolizer.java | 12 ++---
.../apache/sis/internal/map/SEPortrayerTest.java | 63 +++++++++++++++++++---
3 files changed, 65 insertions(+), 15 deletions(-)
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java
b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java
index b253c05..3377c8a 100644
---
a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java
+++
b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java
@@ -653,7 +653,10 @@ public final class SEPortrayer {
*/
private static Set<String> propertiesNames(final Collection<? extends
Rule> rules) {
final PropertyNameCollector collector = new PropertyNameCollector();
- rules.forEach(collector::visit);
+ for (Rule r : rules) {
+ collector.visit(r);
+ collector.visit(r.getFilter());
+ }
return collector.getPropertyNames()
.stream()
.map(PropertyName::getPropertyName).collect(Collectors.toSet());
diff --git
a/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/MockLineSymbolizer.java
b/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/MockLineSymbolizer.java
index 61412f8..b6a7973 100644
---
a/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/MockLineSymbolizer.java
+++
b/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/MockLineSymbolizer.java
@@ -30,13 +30,13 @@ import org.opengis.style.StyleVisitor;
*/
public final class MockLineSymbolizer implements LineSymbolizer {
- private String name;
- private Description description;
+ String name;
+ Description description;
- private Stroke stroke;
- private Expression perpendicularOffset;
- private Unit<Length> unitOfMeasure;
- private Expression geometry;
+ Stroke stroke;
+ Expression perpendicularOffset;
+ Unit<Length> unitOfMeasure;
+ Expression geometry;
@Override
public String getName() {
diff --git
a/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/SEPortrayerTest.java
b/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/SEPortrayerTest.java
index ad73edb..9d55236 100644
---
a/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/SEPortrayerTest.java
+++
b/core/sis-portrayal/src/test/java/org/apache/sis/internal/map/SEPortrayerTest.java
@@ -61,6 +61,7 @@ import org.opengis.feature.FeatureType;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.FilterFactory2;
+import org.opengis.filter.PropertyIsEqualTo;
import org.opengis.filter.identity.Identifier;
import org.opengis.geometry.Envelope;
import org.opengis.metadata.Metadata;
@@ -571,8 +572,8 @@ public class SEPortrayerTest extends TestCase {
final Feature feature = presentation.getCandidate();
final FeatureType type = feature.getType();
assertEquals(2, type.getProperties(true).size());
- type.getProperty(AttributeConvention.IDENTIFIER);
- type.getProperty(AttributeConvention.GEOMETRY);
+ assertNotNull(type.getProperty(AttributeConvention.IDENTIFIER));
+ assertNotNull(type.getProperty(AttributeConvention.GEOMETRY));
}
{
@@ -587,14 +588,60 @@ public class SEPortrayerTest extends TestCase {
final Feature feature = presentation.getCandidate();
final FeatureType type = feature.getType();
assertEquals(6, type.getProperties(true).size());
- type.getProperty(AttributeConvention.IDENTIFIER);
- type.getProperty(AttributeConvention.GEOMETRY);
- type.getProperty(AttributeConvention.ENVELOPE_PROPERTY.toString());
- type.getProperty("id");
- type.getProperty("geom");
- type.getProperty("description");
+ assertNotNull(type.getProperty(AttributeConvention.IDENTIFIER));
+ assertNotNull(type.getProperty(AttributeConvention.GEOMETRY));
+
assertNotNull(type.getProperty(AttributeConvention.ENVELOPE_PROPERTY.toString()));
+ assertNotNull(type.getProperty("id"));
+ assertNotNull(type.getProperty("geom"));
+ assertNotNull(type.getProperty("description"));
}
+ }
+
+ /**
+ * Test all properties used in the style are returned
+ * in the presentation features.
+ */
+ @Test
+ public void testStylePropertiesReturned() {
+
+ final PropertyIsEqualTo filter =
filterFactory.equals(filterFactory.property("id"), filterFactory.literal("2"));
+
+ final MockLineSymbolizer symbolizer = new MockLineSymbolizer();
+ symbolizer.perpendicularOffset = filterFactory.property("description");
+ final MockRule rule = new MockRule();
+ rule.symbolizers().add(symbolizer);
+ rule.setFilter(filter);
+
+ final MockStyle style = new MockStyle();
+ final MockFeatureTypeStyle fts = new MockFeatureTypeStyle();
+ style.featureTypeStyles().add(fts);
+ fts.rules().add(rule);
+
+ final MapLayer fishLayer = new MapLayer();
+ fishLayer.setData(fishes);
+ fishLayer.setStyle(style);
+ final MapLayers layers = new MapLayers();
+ layers.getComponents().add(fishLayer);
+
+
+ final GridGeometry grid = new GridGeometry(new GridExtent(360, 180),
CRS.getDomainOfValidity(CommonCRS.WGS84.normalizedGeographic()),
GridOrientation.REFLECTION_Y);
+
+ // test without preserve properties
+ // we expect identifier, geometry, id(used by rule filter),
description (used in symbolizer)
+ final SEPortrayer portrayer = new SEPortrayer();
+ portrayer.setPreserveProperties(false);
+ final Stream<Presentation> stream = portrayer.present(grid, layers);
+ final List<Presentation> presentations =
stream.collect(Collectors.toList());
+ assertEquals(1, presentations.size());
+ final SEPresentation presentation = (SEPresentation)
presentations.get(0);
+ final Feature feature = presentation.getCandidate();
+ final FeatureType type = feature.getType();
+ assertEquals(4, type.getProperties(true).size());
+ assertNotNull(type.getProperty(AttributeConvention.IDENTIFIER));
+ assertNotNull(type.getProperty(AttributeConvention.GEOMETRY));
+ assertNotNull(type.getProperty("id"));
+ assertNotNull(type.getProperty("description"));
}
private static class Match {