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 0a33751 Portrayal : add SEPortrayer preserve properties hint and
testcase
0a33751 is described below
commit 0a337517f3c636ea2c98eb9b0d8e1c7e2dd1eeca
Author: jsorel <[email protected]>
AuthorDate: Fri Feb 19 09:58:57 2021 +0100
Portrayal : add SEPortrayer preserve properties hint and testcase
---
.../org/apache/sis/internal/map/SEPortrayer.java | 24 ++++++-
.../apache/sis/internal/map/SEPortrayerTest.java | 74 ++++++++++++++++++++++
2 files changed, 97 insertions(+), 1 deletion(-)
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 58ade2e..b253c05 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
@@ -85,7 +85,7 @@ import org.opengis.util.GenericName;
* Generation a Stream of Presentation for a map.
*
* <p>
- * NOTE: this class is a first draft subject to modifications.
+ * NOTE: this class is experimental and subject to modifications.
* </p>
*
* <p>
@@ -145,6 +145,28 @@ public final class SEPortrayer {
}
/**
+ * Hint to avoid decimating feature properties because they may be used
+ * later for other purposes.
+ * Default value is false.
+ *
+ * @return true if all feature properties are preserved in Presentation
instances.
+ */
+ public boolean isPreserveProperties() {
+ return preserveProperties;
+ }
+
+ /**
+ * Hint to avoid decimating feature properties because they may be used
+ * later for other purposes.
+ * Default value is false.
+ *
+ * @param preserveProperties set to true to preserve all feature
properties in Presentation instances.
+ */
+ public void setPreserveProperties(boolean preserveProperties) {
+ this.preserveProperties = preserveProperties;
+ }
+
+ /**
* Replace default margin solver.
* The margin solver try to guess the expected symbolizer size to expand
the query bounding box.
* @param marginSolver
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 7a22100..ad73edb 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
@@ -94,6 +94,7 @@ public class SEPortrayerTest extends TestCase {
fishbuilder.setName("fish");
fishbuilder.addAttribute(String.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
fishbuilder.addAttribute(Point.class).setCRS(crs).setName("geom").addRole(AttributeRole.DEFAULT_GEOMETRY);
+ fishbuilder.addAttribute(String.class).setName("description");
final FeatureType fishType = fishbuilder.build();
final Point point1 = gf.createPoint(new Coordinate(0, 0));
@@ -101,12 +102,14 @@ public class SEPortrayerTest extends TestCase {
final Feature fish1 = fishType.newInstance();
fish1.setPropertyValue("id", "1");
fish1.setPropertyValue("geom", point1);
+ fish1.setPropertyValue("description", "A red fish");
final Point point2 = gf.createPoint(new Coordinate(10, 20));
point2.setUserData(crs);
final Feature fish2 = fishType.newInstance();
fish2.setPropertyValue("id", "2");
fish2.setPropertyValue("geom", point2);
+ fish2.setPropertyValue("description", "A small blue fish");
fishes = new MemoryFeatureSet(null, fishType, Arrays.asList(fish1,
fish2));
@@ -115,6 +118,7 @@ public class SEPortrayerTest extends TestCase {
boatbuilder.setName("boat");
boatbuilder.addAttribute(String.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
boatbuilder.addAttribute(Polygon.class).setCRS(crs).setName("geom").addRole(AttributeRole.DEFAULT_GEOMETRY);
+ boatbuilder.addAttribute(String.class).setName("description");
final FeatureType boatType = boatbuilder.build();
final Polygon poly1 = gf.createPolygon(gf.createLinearRing(new
Coordinate[]{new Coordinate(0, 0),new Coordinate(0, 1),new Coordinate(1, 1),new
Coordinate(0, 0)}));
@@ -122,12 +126,14 @@ public class SEPortrayerTest extends TestCase {
final Feature boat1 = boatType.newInstance();
boat1.setPropertyValue("id", "10");
boat1.setPropertyValue("geom", poly1);
+ boat1.setPropertyValue("description", "A fishing boat");
final Polygon poly2 = gf.createPolygon(gf.createLinearRing(new
Coordinate[]{new Coordinate(0, 0),new Coordinate(0, 1),new Coordinate(1, 1),new
Coordinate(0, 0)}));
poly2.setUserData(crs);
final Feature boat2 = boatType.newInstance();
boat2.setPropertyValue("id", "20");
boat2.setPropertyValue("geom", poly2);
+ boat2.setPropertyValue("description", "A submarine");
boats = new MemoryFeatureSet(null, boatType, Arrays.asList(boat1,
boat2));
}
@@ -523,6 +529,74 @@ public class SEPortrayerTest extends TestCase {
assertTrue(presentations.contains(new Match("20", aggLayer, boats,
symbolizerBase)));
}
+ /**
+ * Portray preserving all feature attributes test.
+ */
+ @Test
+ public void testPreserveProperties() {
+
+ final Set<Identifier> ids = new HashSet<>();
+ ids.add(filterFactory.featureId("2"));
+ final Filter filter = filterFactory.id(ids);
+
+ final MockLineSymbolizer symbolizer = new MockLineSymbolizer();
+
+ 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 only identifier and geometry to be available.
+ 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(2, type.getProperties(true).size());
+ type.getProperty(AttributeConvention.IDENTIFIER);
+ type.getProperty(AttributeConvention.GEOMETRY);
+ }
+
+ {
+ // test with preserve properties
+ // we expect only identifier and geometry to be available.
+ final SEPortrayer portrayer = new SEPortrayer();
+ portrayer.setPreserveProperties(true);
+ 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(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");
+ }
+
+ }
+
private static class Match {
private final String identifier;
private final MapLayer layer;