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:06 UTC
[incubator-streampipes-extensions] 09/17: extended Geometry helper
with WKT Reader
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 156b8ca9a6fb9f441a0660a33dc5935ec15c1fa0
Author: micklich <fl...@disy.net>
AuthorDate: Tue Apr 28 17:24:42 2020 +0200
extended Geometry helper with WKT Reader
Revert "extended Geometry helper with WKT Reader"
This reverts commit e4cb162fef10504d67c83cc8340f93615d316d81.
added WKT reader, trajectory class and documentation
This reverts commit 953c1b65c30249fe10e7d8caae713892daa4e16f.
---
.../geo/jvm/jts/helper/SpGeometryBuilder.java | 40 +++++++-
.../geo/jvm/jts/helper/SpTrajectoryBuilder.java | 107 +++++++++++++++++++++
.../documentation.md | 77 +++++++++++++++
.../icon.png | Bin 0 -> 9399 bytes
.../strings.en | 6 ++
5 files changed, 227 insertions(+), 3 deletions(-)
diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java
index 274796c..e6e183a 100644
--- a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java
@@ -19,6 +19,8 @@
package org.apache.streampipes.processors.geo.jvm.jts.helper;
import org.locationtech.jts.geom.*;
+import org.locationtech.jts.io.ParseException;
+import org.locationtech.jts.io.WKTReader;
public class SpGeometryBuilder {
@@ -31,9 +33,9 @@ public class SpGeometryBuilder {
/**
* Creates a JTS point geometry from Longitude and Latitude values
*
- * @param lng Longitude value in the range -180 <Longitude > 180
- * @param lat Latitude value in the range -90 <LATITUDE > 90
- * @param epsg EPSG Code for projection onfo
+ * @param lng Longitude value in the range -180 <Longitude > 180
+ * @param lat Latitude value in the range -90 <LATITUDE > 90
+ * @param epsg EPSG Code for projection info
* @return a JTS Point Geometry Object with lat lng values. An empty point geometry is created if Latitude or Longitude values are out of range
* or has null values.
*/
@@ -61,7 +63,39 @@ public class SpGeometryBuilder {
return point;
}
+
+ /**
+ * creates a Geometry from a wkt_string. string has to be valid and is not be checked. If invalid, an empty point
+ * geom is returned. method calls getPrecision method and creates a jts geometry factory and a WKT-parser object.
+ * from the wktString the
+ *
+ * @param wktString wkt text
+ * @param epsg EPSG Code for projection info
+ * @return Geometry geom: a JTS Geometry Object depending on the WKT input. An empty point geometry is created if Latitude or Longitude values are out of range
+ * * or has null values
+ */
+ public static Geometry createSPGeom(String wktString, Integer epsg) {
+
+ Geometry geom;
+ PrecisionModel prec = getPrecisionModel(epsg);
+
+ GeometryFactory geomFactory = new GeometryFactory(prec, epsg);
+ WKTReader wktReader = new WKTReader(geomFactory);
+
+ try {
+ geom = wktReader.read(wktString);
+ } catch (ParseException e) {
+ // if wktString is invalid, an empty point geometry will be created as returnedGeom
+ geom = geomFactory.createPoint();
+ }
+
+ return geom;
+ }
+
+
+
/**
+ *
* @param checkedvalue Any Value
* @param min Min value to check
* @param max max value to check
diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpTrajectoryBuilder.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpTrajectoryBuilder.java
new file mode 100644
index 0000000..4c9cc0d
--- /dev/null
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpTrajectoryBuilder.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.processors.geo.jvm.jts.helper;
+
+
+import org.locationtech.jts.geom.*;
+
+public class SpTrajectoryBuilder {
+
+ private int numberSubPoints;
+ private String description;
+ private CoordinateList coordinateList;
+
+ /**
+ * Constructor of SpTrajectory
+ * @param numberSubPoints Integer number of allowed subpoints of the trajectory
+ * @param description Text Description of the single Trajectory
+ */
+ public SpTrajectoryBuilder(int numberSubPoints, String description) {
+ this.numberSubPoints = numberSubPoints;
+ this.description = description;
+ this.coordinateList = new CoordinateList();
+ }
+
+
+ /**
+ * getter method for description text
+ * @return
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Adds a Point to the trajectory object and also handle removement depending on the
+ * number of choosen Subpoints
+ * @param point Point geometry
+ * @param m stores an extra integer to the subpoint of a trajectory
+ */
+ public void addPointToTrajectory(Point point, Integer m) {
+ coordinateList.add(createSingleTrajectoryCoordinate(point, m));
+ if (coordinateList.size() > numberSubPoints) {
+ removeOldestPoint();
+ }
+ }
+
+
+ /**
+ * returns a JTS LineString geometry from the trajectory object. LineString only stores the point geometry without M value.
+ * The lineString is oriented to the trajectory direction. This means: the newest point is always the last point and has the
+ * highest subpoint index. The First point is the oldest point with the lowest index [0]
+ * @param factory a Geometry factory for creating the lineString with the same precision and CRS and should be
+ * the factory of the input point geometry
+ * @return JTS LineString JTS LineString
+ */
+ public LineString returnAsLineString(GeometryFactory factory){
+ LineString geom;
+ if ( coordinateList.size() > 1) {
+ //only linestring if more than 2 points.
+ // reverse output of linestring. so last added point is first
+ geom = factory.createLineString(coordinateList.toCoordinateArray());
+ } else {
+ geom = factory.createLineString();
+ }
+
+ return geom;
+ }
+
+ /**
+ * removes the oldest point (Index 0) from the CoordinateList object.
+ */
+ private void removeOldestPoint(){
+ coordinateList.remove(0);
+ }
+
+ /**
+ * Creates an Coordinate object with X, Y and M Value to be stored later directly in the trajectory object. Should be used
+ * always used if adding a subpoint to the trajectory list
+ * @param geom Point geometry, which coordinates will be added to the trajectory list
+ * @param m Integer M value, which will be used to store as extra parameter in the trajectory list
+ * @return CoordinateXYM coordinate object
+ */
+ private CoordinateXYM createSingleTrajectoryCoordinate(Point geom, Integer m){
+ CoordinateXYM coordinate =new CoordinateXYM((geom.getX()), geom.getY(), m);
+ return coordinate;
+ }
+
+
+}
+
+
diff --git a/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/documentation.md b/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/documentation.md
new file mode 100644
index 0000000..1fbec38
--- /dev/null
+++ b/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/documentation.md
@@ -0,0 +1,77 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ -->
+
+## Trajectory from JTS Point
+
+<p align="center">
+ <img src="icon.png" width="150px;" class="pe-image-documentation"/>
+</p>
+
+***
+
+## Description
+
+This processor creates a JTS LineString geometry from JTS Points events, represent a trajectory. A trajectory is defined as the path that a moving object follows through space as a function of time. Each sub-point of this LineString represents a single event. The latest sub-point represents the latest geo-event. For each Point event it is also possible to store an additional m-value representing for example actually speed, distance, duration or direction of this event. A trajectory con [...]
+***
+
+## Required input
+
+* WKT String of a JTS Point Geometry
+* Integer value representing EPSG code
+* Number value for M-value
+
+
+***
+
+## Configuration
+
+Creates a JTS Geometry LineString from a JTS Point Geometries events representing a trajectory.
+
+
+### 1st parameter
+Point WKT String
+
+### 2nd parameter
+EPSG code value
+
+### 3rd parameter
+M-value for each sub-point of the trajectory
+
+### 4rd parameter
+String for a description text for the trajectory
+
+### 5rd parameter
+Number of allowed sub-points
+
+***
+
+## Output
+
+Adds a LineString geometry in the Well Known Text to the event, representing a trajectory. Also the description text is added to the event stream. The first existing event creates an empty LineString.
+
+### Example
+Creating a LineString with a threshold of 2 allowed sub-points:
+
+* First Event:
+ * Point(8.12 41.23) --> LineString <empty>
+* Second Event:
+ * Point(8.56 41.25) --> LineString(8.12 41.23, 8.56 41.25)
+* Second Event:
+ * Point(8.84 40.98) --> LineString(8.56 41.25, 8.84 40.98)
+
+M-value is not represented in the LineString but will be stored for internal use!
diff --git a/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/icon.png b/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/icon.png
new file mode 100644
index 0000000..7389006
Binary files /dev/null and b/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/icon.png differ
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
new file mode 100644
index 0000000..a0dcba4
--- /dev/null
+++ b/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory/strings.en
@@ -0,0 +1,6 @@
+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.
+
+place.title=Place
+place.description=Trajectory from single point events