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 2020/05/12 18:38:10 UTC

[incubator-streampipes-extensions] 13/17: rewrite from labels.from to label.withID

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

micklich pushed a commit to branch feature/trajectory
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git

commit 4526f8cd75744fcc5372f56e027b4bdca8fefa24
Author: micklich <fl...@disy.net>
AuthorDate: Tue May 12 01:50:52 2020 +0200

    rewrite from labels.from to label.withID
---
 .../trajectory/CreateTrajectoryFromPoints.java     |  27 +++--
 .../CreateTrajectoryFromPointsController.java      | 129 +++++++++------------
 .../strings.en                                     |  24 +++-
 3 files changed, 95 insertions(+), 85 deletions(-)

diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPoints.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPoints.java
index 3ad78d9..26a695e 100755
--- a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPoints.java
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPoints.java
@@ -32,16 +32,21 @@ import org.locationtech.jts.geom.Point;
 public class CreateTrajectoryFromPoints implements EventProcessor<CreateTrajectoryFromPointsParameter> {
 
     private static Logger LOG;
-    private CreateTrajectoryFromPointsParameter params;
-    SpTrajectoryBuilder trajectory;
 
+    private SpTrajectoryBuilder trajectory;
+
+    private String geom_wkt;
+    private String epsg_code;
+    private String m_value;
 
 
     @Override
     public void onInvocation(CreateTrajectoryFromPointsParameter params, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) {
 
         LOG = params.getGraph().getLogger(CreateTrajectoryFromPointsParameter.class);
-        this.params = params;
+        this.geom_wkt =  params.getWkt();
+        this.epsg_code = params.getEpsg();
+        this.m_value = params.getM();
 
         trajectory = new SpTrajectoryBuilder(params.getSubpoints(), params.getDescription());
     }
@@ -49,18 +54,22 @@ public class CreateTrajectoryFromPoints implements EventProcessor<CreateTrajecto
     @Override
     public void onEvent(Event in, SpOutputCollector out) {
 
-        String wkt = in.getFieldBySelector(params.getWkt()).getAsPrimitive().getAsString();
-        Integer epsg = in.getFieldBySelector(params.getEpsg()).getAsPrimitive().getAsInt();
-        Integer m = in.getFieldBySelector(params.getM()).getAsPrimitive().getAsInt();
+        // extract values
+        String wkt = in.getFieldBySelector(geom_wkt).getAsPrimitive().getAsString();
+        Integer epsg = in.getFieldBySelector(epsg_code).getAsPrimitive().getAsInt();
+        Integer m = in.getFieldBySelector(m_value).getAsPrimitive().getAsInt();
 
+        //create JTS geometry
         Point eventGeom =  (Point) SpGeometryBuilder.createSPGeom(wkt,epsg);
 
-        //creates single trajectory
+        //adds point and m value to trajectory object
         trajectory.addPointToTrajectory(eventGeom, m);
+        // returns JTS LineString
         LineString geom = trajectory.returnAsLineString(eventGeom.getFactory());
 
-        in.addField(CreateTrajectoryFromPointsController.WKT, geom.toString());
-        in.addField(CreateTrajectoryFromPointsController.DESCRIPTION, trajectory.getDescription());
+        // adds to stream
+        in.addField("wkt-trajectory", geom.toString());
+        in.addField("description", trajectory.getDescription());
         out.collect(in);
 
     }
diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPointsController.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPointsController.java
index 654a907..a94140c 100755
--- a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPointsController.java
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/trajectory/CreateTrajectoryFromPointsController.java
@@ -35,78 +35,65 @@ public class CreateTrajectoryFromPointsController extends  StandaloneEventProces
 
 
 
-    public final static String WKT = "trajectory_wkt";
-    public final static String EPSG = "EPSG";
-    public final static String M = "M-Value";
-    public final static String DESCRIPTION = "description";
-    public final static String SUBPOINTS = "subpoints";
 
+    public final static String POINT_KEY = "point-key";
+    public final static String EPSG_KEY = "epsg-key";
+    public final static String M_KEY = "m-key";
+    public final static String DESCRIPTION_KEY = "description-key";
+    public final static String SUBPOINTS_KEY = "subpoints-key";
+
+    public final static String WKT = "trajectory_wkt";
     public final static String EPA_NAME = "Create Single Trajectory";
 
 
     @Override
     public DataProcessorDescription declareModel() {
-        return ProcessingElementBuilder
-                .create("org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory",
-                        EPA_NAME,
-                        "Creates a trajectory from Points")
-                .category(DataProcessorType.GEO)
-                .withAssets(Assets.DOCUMENTATION, Assets.ICON)
-                .requiredStream(
-                        StreamRequirementsBuilder
-                                .create()
-                                .requiredPropertyWithUnaryMapping(
-                                        EpRequirements.domainPropertyReq("http://www.opengis.net/spec/geosparql/1.0#wktLiteral"),
-                                        Labels.from(WKT,
-                                                "Geometry WKT",
-                                                "WKT of the requested Geometry"),
-                                        PropertyScope.NONE
-                                )
-                                .requiredPropertyWithUnaryMapping(
-                                        EpRequirements.domainPropertyReq("http://streampipes.org/epsg"),
-                                        Labels.from(EPSG, "EPSG Field", "EPSG Code for SRID"),
-                                        PropertyScope.NONE
-                                )
-                                .requiredPropertyWithUnaryMapping(
-                                        EpRequirements.numberReq(),
-                                        Labels.from(M, "M Value", "Choose a value add to trajectory"),
-                                        PropertyScope.NONE
-                                )
-                                .build()
-                )
-                .requiredTextParameter(
-                        Labels.from(
-                                DESCRIPTION,
-                                "description of trajectory",
-                                "Add a description for the trajectory")
-                )
-                .requiredIntegerParameter(
-                        Labels.from(
-                                SUBPOINTS,
-                                "number of allowed subpoints",
-                                "Number og allowed subpoints of the trajector"),
-                        2, 10, 1
-                )
-                .outputStrategy(OutputStrategies.append(
-                        EpProperties.stringEp(
-                                Labels.from(
-                                        "trajectory_wkt",
-                                        "trajectory_wkt",
-                                        "trajectory wkt (lineString) of a point stream"),
-                                WKT,
-                                SO.Text),
-                        EpProperties.stringEp(
-                                Labels.from(
-                                        "trajectory_description",
-                                        "trajectory_description",
-                                        "description of trajectory"),
-                                DESCRIPTION,
-                                SO.Text))
-                )
-
-                .supportedFormats(SupportedFormats.jsonFormat())
-                .supportedProtocols(SupportedProtocols.kafka())
-                .build();
+      return ProcessingElementBuilder
+          .create("org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory")
+          .category(DataProcessorType.GEO)
+          .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+          .withLocales(Locales.EN)
+          .requiredStream(
+              StreamRequirementsBuilder
+                  .create()
+                  .requiredPropertyWithUnaryMapping(
+                      EpRequirements.domainPropertyReq("http://www.opengis.net/ont/geosparql#Geometry"),
+                      Labels.withId(POINT_KEY), PropertyScope.MEASUREMENT_PROPERTY
+                  )
+                  .requiredPropertyWithUnaryMapping(
+                      EpRequirements.domainPropertyReq("http://data.ign.fr/def/ignf#CartesianCS"),
+                      Labels.withId(EPSG_KEY), PropertyScope.MEASUREMENT_PROPERTY
+                  )
+                  .requiredPropertyWithUnaryMapping(
+                      EpRequirements.numberReq(),
+                      Labels.withId(M_KEY),  PropertyScope.MEASUREMENT_PROPERTY
+                  )
+                  .build()
+          )
+          .requiredTextParameter(
+              Labels.withId(DESCRIPTION_KEY)
+          )
+          .requiredIntegerParameter(
+              Labels.withId(SUBPOINTS_KEY),
+              2, 30, 1
+          )
+
+          .outputStrategy(OutputStrategies.append(
+              EpProperties.numberEp(
+                  Labels.withId(M_KEY),
+                  "m-value",
+                  SO.Number
+              ),
+              EpProperties.numberEp(
+                  Labels.withId(WKT),
+                  "trajectory-wkt",
+                  "http://www.opengis.net/ont/geosparql#Geometry")
+              )
+          )
+
+          .supportedFormats(SupportedFormats.jsonFormat())
+          .supportedProtocols(SupportedProtocols.kafka())
+          .build();
     }
 
 
@@ -115,14 +102,14 @@ public class CreateTrajectoryFromPointsController extends  StandaloneEventProces
 
 
         String wkt = extractor.mappingPropertyValue(WKT);
-        String epsg_value = extractor.mappingPropertyValue(EPSG);
-        String m = extractor.mappingPropertyValue(M);
+        String epsg = extractor.mappingPropertyValue(EPSG_KEY);
+        String m = extractor.mappingPropertyValue(M_KEY);
 
-        String description = extractor.singleValueParameter(DESCRIPTION, String.class);
-        Integer subpoints = extractor.singleValueParameter(SUBPOINTS, Integer.class);
+        String description = extractor.singleValueParameter(DESCRIPTION_KEY, String.class);
+        Integer subpoints = extractor.singleValueParameter(SUBPOINTS_KEY, Integer.class);
 
 
-        CreateTrajectoryFromPointsParameter params = new CreateTrajectoryFromPointsParameter(graph, wkt, epsg_value, description, subpoints, m);
+        CreateTrajectoryFromPointsParameter params = new CreateTrajectoryFromPointsParameter(graph, wkt, epsg, description, subpoints, m);
 
         return new ConfiguredEventProcessor<>(params, CreateTrajectoryFromPoints::new);
     }
diff --git a/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/strings.en b/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/strings.en
index a0dcba4..f38fef7 100644
--- a/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/strings.en
+++ b/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/strings.en
@@ -1,6 +1,20 @@
-org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory.title=Static Google Maps Geocoder
-org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory.description=GTrajectory from JTS point events
-appends these coordinates to every input event.
+org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory.title=Single Trajectory Creator
+org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory.description=Creates a trajectory from JTS point events
 
-place.title=Place
-place.description=Trajectory from single point events
+point-key.title=JTS Point Event
+point-key.description=Single Point Event which will be added to the trajectory
+
+point-key.title=JTS Point Event
+point-key.description=Single Point Event which will be added to the trajectory
+
+epsg-key.title=CRS of Input Point
+epsg-key.description=EPSG-Code of input point
+
+m-key.title=measurement value
+m-key.description=Measurement value which will be stored with each point event
+
+description-key.title=description text of trajectory
+description-key.description=A description text for the trajectory
+
+subpoints-key.title=number of allowed sub-points
+subpoints-key.description=amount of allowed sub-points, creating the trajectory