You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by mi...@apache.org on 2023/03/03 22:19:15 UTC

[streampipes] 02/04: [#1321] add switch between interior and centroid point as output. add resources

This is an automated email from the ASF dual-hosted git repository.

micklich pushed a commit to branch 1321-geo-create-derived-point-of-input-geometry-processor
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit b8891bf8196649a8d16f27757239c5573709cda6
Author: micklich <mi...@apache.org>
AuthorDate: Thu Feb 23 21:13:36 2023 +0100

    [#1321] add switch between interior and centroid point as output. add resources
---
 .../streampipes/processors/geo/jvm/GeoJvmInit.java |   7 +++--
 .../CreateDerivedPointProcessor.java}              |  33 ++++++++++++++-------
 .../documentation.md                               |  17 +++++++----
 .../icon.png                                       | Bin
 .../strings.en                                     |   7 +++--
 5 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java
index d3024ff10..6dcdc5b3f 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java
@@ -30,6 +30,7 @@ import org.apache.streampipes.messaging.mqtt.SpMqttProtocolFactory;
 import org.apache.streampipes.processors.geo.jvm.config.ConfigKeys;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.buffergeometry.BufferGeomProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.bufferpoint.BufferPointProcessor;
+import org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point.CreateDerivedPointProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.epsg.EpsgProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.latlngtojtspoint.LatLngToJtsPointProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.reprojection.ReprojectionProcessor;
@@ -78,7 +79,9 @@ public class GeoJvmInit extends ExtensionsModelSubmitter {
             new GeometryValidationProcessor(),
             new TopologyValidationProcessor(),
             new BufferGeomProcessor(),
-            new BufferPointProcessor())
+            new BufferPointProcessor(),
+            new ReprojectionProcessor(),
+            new CreateDerivedPointProcessor())
         .registerMessagingFormats(
             new JsonDataFormatFactory(),
             new CborDataFormatFactory(),
@@ -97,7 +100,7 @@ public class GeoJvmInit extends ExtensionsModelSubmitter {
     PGSimpleDataSource ds = new PGSimpleDataSource();
     String[] serverAddresses = {"localhost"};
     ds.setServerNames(serverAddresses);
-    int[] portNumbers = {54320};
+    int [] portNumbers = {54320};
     ds.setPortNumbers(portNumbers);
     ds.setDatabaseName("EPSG");
     ds.setUser("streampipes");
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/derivedgeometry/interior/CreateInteriorPointProcessor.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/derivedgeometry/point/CreateDerivedPointProcessor.java
similarity index 79%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/derivedgeometry/interior/CreateInteriorPointProcessor.java
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/derivedgeometry/point/CreateDerivedPointProcessor.java
index 8018b84b7..0113cc08a 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/derivedgeometry/interior/CreateInteriorPointProcessor.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/derivedgeometry/point/CreateDerivedPointProcessor.java
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior;
+package org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point;
 
 import org.apache.streampipes.commons.exceptions.SpRuntimeException;
 import org.apache.streampipes.model.DataProcessorType;
@@ -30,6 +30,7 @@ import org.apache.streampipes.sdk.helpers.EpProperties;
 import org.apache.streampipes.sdk.helpers.EpRequirements;
 import org.apache.streampipes.sdk.helpers.Labels;
 import org.apache.streampipes.sdk.helpers.Locales;
+import org.apache.streampipes.sdk.helpers.Options;
 import org.apache.streampipes.sdk.helpers.OutputStrategies;
 import org.apache.streampipes.sdk.utils.Assets;
 import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
@@ -42,22 +43,23 @@ import org.locationtech.jts.geom.Point;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class CreateInteriorPointProcessor extends StreamPipesDataProcessor {
-  public static final String GEOM_KEY = "geom-key";
+public class CreateDerivedPointProcessor extends StreamPipesDataProcessor {
+  public static final String GEOM_KEY = "geometry-key";
   public static final String EPSG_KEY = "epsg-key";
-  // OUTPUT RUNTIME NAME
+  public static final String POINT_OUTPUT_TYPE_KEY = "point-output-type-key";
   public static final String INTERIOR_GEOM_KEY = "interior-geom-key";
   public static final String INTERIOR_EPSG_KEY = "interior-epsg-key";
   public static final String INTERIOR_GEOM_RUNTIME = "interior-point";
   public static final String INTERIOR_EPSG_RUNTIME = "epsg-interior-point";
   private String geometryMapper;
   private String epsgMapper;
-  private static final Logger LOG = LoggerFactory.getLogger(CreateInteriorPointProcessor.class);
+  private String outputType;
+  private static final Logger LOG = LoggerFactory.getLogger(CreateDerivedPointProcessor.class);
 
   @Override
   public DataProcessorDescription declareModel() {
     return ProcessingElementBuilder.create(
-        "org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior")
+            "org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point")
         .category(DataProcessorType.GEO)
         .withAssets(Assets.DOCUMENTATION, Assets.ICON)
         .withLocales(Locales.EN)
@@ -72,7 +74,8 @@ public class CreateInteriorPointProcessor extends StreamPipesDataProcessor {
                 Labels.withId(EPSG_KEY),
                 PropertyScope.MEASUREMENT_PROPERTY)
             .build())
-        // adjust output method
+        .requiredSingleValueSelection(Labels.withId(POINT_OUTPUT_TYPE_KEY),
+            Options.from("Centroid Point", "Interior Point"))
         .outputStrategy(OutputStrategies.append(
                 EpProperties.stringEp(
                     Labels.withId(INTERIOR_GEOM_KEY),
@@ -93,8 +96,10 @@ public class CreateInteriorPointProcessor extends StreamPipesDataProcessor {
 
     this.geometryMapper = parameters.extractor().mappingPropertyValue(GEOM_KEY);
     this.epsgMapper = parameters.extractor().mappingPropertyValue(EPSG_KEY);
+    this.outputType = parameters.extractor().selectedSingleValue(POINT_OUTPUT_TYPE_KEY, String.class);
 
   }
+
   @Override
   public void onEvent(Event event, SpOutputCollector collector) throws SpRuntimeException {
     String geom = event.getFieldBySelector(geometryMapper).getAsPrimitive().getAsString();
@@ -104,9 +109,17 @@ public class CreateInteriorPointProcessor extends StreamPipesDataProcessor {
       // TODO remove check after harmonized semantic types and multiple tpes
       LOG.debug("geom is already a point");
     } else {
-      Point cendroidPoint = (Point) SpGeometryBuilder.createSPGeom(geometry.getCentroid(), geometry.getSRID());
-      event.addField(INTERIOR_GEOM_RUNTIME, cendroidPoint.toText());
-      event.addField(INTERIOR_EPSG_RUNTIME, cendroidPoint.getSRID());
+      Point derivedPointOutput = null;
+      switch (this.outputType) {
+        case "Interior Point":
+          derivedPointOutput = (Point) SpGeometryBuilder.createSPGeom(geometry.getInteriorPoint(), geometry.getSRID());
+          break;
+        case "Centroid Point":
+          derivedPointOutput = (Point) SpGeometryBuilder.createSPGeom(geometry.getCentroid(), geometry.getSRID());
+          break;
+      }
+      event.addField(INTERIOR_GEOM_RUNTIME, derivedPointOutput.toText());
+      event.addField(INTERIOR_EPSG_RUNTIME, derivedPointOutput.getSRID());
       collector.collect(event);
     }
   }
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/documentation.md b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/documentation.md
similarity index 72%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/documentation.md
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/documentation.md
index c6b47978c..6f9322a2a 100755
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/documentation.md
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/documentation.md
@@ -25,17 +25,15 @@
 ***
 
 ## Description
+Creates a Point of every other Geometry (not included a Point itself).
 
-Creates an interior point from a geometry other than a Point itself.
-An interior point is guaranteed to lie in the interior of the input geometry, if 
-it possible to calculate such a point exactly. Otherwise, the point may 
-lie on the boundary of the geometry.
 ***
 
 ## Required inputs
 
 * JTS Geometry
 * EPSG Code
+* Point Output Type
 ***
 
 ## Configuration
@@ -46,10 +44,19 @@ Input Geometry
 ### EPSG field
 Integer value representing EPSG code
 
+### Point Output Type
+Chose between 
+* Interior Point
+  *  An interior point is guaranteed to lie in the interior of the Geometry, 
+  if it is possible to calculate such a point exactly. Otherwise, the point may lie on 
+  the boundary of the geometry.
+* Centroid Point
+  * Computes the centroid of a Geometry 
+
 ***
 
 ## Output
-A point geometry with EPSG code. Location is based on 
+A point geometry with EPSG code.
 
 
 ### Example
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/icon.png b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/icon.png
similarity index 100%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/icon.png
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/icon.png
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/strings.en b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/strings.en
similarity index 82%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/strings.en
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/strings.en
index d0b0956d8..c8b8d84b3 100755
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior/strings.en
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point/strings.en
@@ -15,11 +15,14 @@
 # limitations under the License.
 #
 
-org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior.title=Geo Create Interior Point
-org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.interior.description=Creates a Point from other Geometries greater than point
+org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point.title=Geo Derived Point Creation
+org.apache.streampipes.processors.geo.jvm.jts.processor.derivedgeometry.point.description=Creates a Point from other Geometries greater than point
 
 geometry-key.title=JTS Geometry Event
 geometry-key.description=Single Geometry
 
 epsg-key.title=EPSG
 epsg-key.description=EPSG
+
+point-output-type-key.title=Point Type
+point-output-type-key.description=Choose Output Type