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 2022/11/30 14:59:52 UTC
[streampipes] 01/11: [STREAMPIPES-642] style check on helper classes
This is an automated email from the ASF dual-hosted git repository.
micklich pushed a commit to branch STREAMPIPES-642
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit c19efa0581b78e5677ef0de4ab679db0339cc5be
Author: micklich <mi...@apache.org>
AuthorDate: Sat Nov 26 13:33:55 2022 +0100
[STREAMPIPES-642] style check on helper classes
---
.../geo/jvm/jts/helper/SpGeometryBuilder.java | 194 +++++++++++----------
.../geo/jvm/jts/helper/SpTrajectoryBuilder.java | 20 ++-
2 files changed, 112 insertions(+), 102 deletions(-)
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java
index 03e38a57a..b6c179332 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpGeometryBuilder.java
@@ -18,111 +18,117 @@
package org.apache.streampipes.processors.geo.jvm.jts.helper;
-import org.locationtech.jts.geom.*;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.GeometryFactory;
+import org.locationtech.jts.geom.Point;
+import org.locationtech.jts.geom.PrecisionModel;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
public class SpGeometryBuilder {
- final static double LONGITUDE_MIN = -180.00;
- final static double LONGITUDE_MAX = 180.00;
- final static double LATITUDE_MIN = -90;
- final static double LATITUDE_MAX = 90;
-
-
- /**
- * Creates a {@link org.locationtech.jts.geom.Point} from <code>Latitude</code> and <code> Longitude</code> 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 representing coordinate reference system
- * @return a {@link org.locationtech.jts.geom.Point}. An empty point geometry is created if Latitude or Longitude values are out of range or has null values.
- */
- public static Point createSPGeom(Double lng, Double lat, Integer epsg) {
- Point point;
- PrecisionModel precisionModel = getPrecisionModel(epsg);
- GeometryFactory geomFactory = new GeometryFactory(precisionModel, epsg);
-
- //check if value is not null due missing stream value
- if ((lng != null) && (lat != null)) {
- //check if lat lng is in typical range
- if (isInWGSCoordinateRange(lng, LONGITUDE_MIN, LONGITUDE_MAX) || isInWGSCoordinateRange(lat, LATITUDE_MIN, LATITUDE_MAX)) {
-
- Coordinate coordinate = new Coordinate(lng, lat);
- point = geomFactory.createPoint(coordinate);
- } else {
- // creates empty point if values are out of Range
- point = geomFactory.createPoint();
- }
- } else {
- // creates empty point if lng lat are null value
- point = geomFactory.createPoint();
+ static final double LONGITUDE_MIN = -180.00;
+ static final double LONGITUDE_MAX = 180.00;
+ static final double LATITUDE_MIN = -90;
+ static final double LATITUDE_MAX = 90;
+
+
+ /**
+ * Creates a {@link org.locationtech.jts.geom.Point} from <code>Latitude</code> and <code> Longitude</code> 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 representing coordinate reference system
+ * @return a {@link org.locationtech.jts.geom.Point}. An empty point geometry is created if Latitude
+ * or Longitude values are out of range or has null values.
+ */
+ public static Point createSPGeom(Double lng, Double lat, Integer epsg) {
+ Point point;
+ PrecisionModel precisionModel = getPrecisionModel(epsg);
+ GeometryFactory geomFactory = new GeometryFactory(precisionModel, epsg);
+
+ //check if value is not null due missing stream value
+ if ((lng != null) && (lat != null)) {
+ //check if lat lng is in typical range
+ if (isInWGSCoordinateRange(lng, LONGITUDE_MIN, LONGITUDE_MAX)
+ || isInWGSCoordinateRange(lat, LATITUDE_MIN, LATITUDE_MAX)) {
+
+ Coordinate coordinate = new Coordinate(lng, lat);
+ point = geomFactory.createPoint(coordinate);
+ } else {
+ // creates empty point if values are out of Range
+ point = geomFactory.createPoint();
+ }
+ } else {
+ // creates empty point if lng lat are null value
+ point = geomFactory.createPoint();
+ }
+
+ return point;
}
- 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 Well-known text representation of the input geometry
+ * @param epsg EPSG Code representing SRID
+ * @return {@link org.locationtech.jts.geom.Geometry}. An empty point geometry
+ * is created if {@link org.locationtech.jts.io.ParseException} due invalid WKT-String
+ */
+ 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;
+ }
- /**
- * 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 Well-known text representation of the input geometry
- * @param epsg EPSG Code representing SRID
- * @return {@link org.locationtech.jts.geom.Geometry}. An empty point geometry is created if {@link org.locationtech.jts.io.ParseException} due invalid WKT-String
- */
- 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();
+ /**
+ * Is in wgs coordinate range boolean.
+ *
+ * @param valueToCheck Any Value
+ * @param min Min value to check
+ * @param max max value to check
+ * @return true if value is in min max range
+ */
+ private static boolean isInWGSCoordinateRange(double valueToCheck, double min, double max) {
+ return valueToCheck > min && valueToCheck < max;
}
- return geom;
- }
-
-
- /**
- * Is in wgs coordinate range boolean.
- *
- * @param valueToCheck Any Value
- * @param min Min value to check
- * @param max max value to check
- * @return true if value is in min max range
- */
- private static boolean isInWGSCoordinateRange(double valueToCheck, double min, double max){
- return valueToCheck > min && valueToCheck < max;
- }
-
-
- /**
- * Creates a {@link org.locationtech.jts.geom.PrecisionModel} with a specific precision.
- * WGS84/WGS84 will be created a {@link org.locationtech.jts.geom.PrecisionModel#FIXED} with 7 decimal positions (scale 1000000).
- * Any other epsg code will create a precision with {@link org.locationtech.jts.geom.PrecisionModel#FLOATING}.
- *
- * @param epsg EPSG Code representing SRID
- * @return {@link org.locationtech.jts.geom.PrecisionModel}
- */
- private static PrecisionModel getPrecisionModel(Integer epsg) {
- PrecisionModel precisionModel;
-
- if (epsg == 4326) {
- // use scale precision with 7 decimal positions like default OSM
- precisionModel = new PrecisionModel(1000000);
- } else {
- // use default constructor
- precisionModel = new PrecisionModel();
- }
- return precisionModel;
- }
+ /**
+ * Creates a {@link org.locationtech.jts.geom.PrecisionModel} with a specific precision.
+ * WGS84/WGS84 will be created a {@link org.locationtech.jts.geom.PrecisionModel#FIXED} with
+ * 7 decimal positions (scale 1000000). Any other epsg code will create a precision
+ * with {@link org.locationtech.jts.geom.PrecisionModel#FLOATING}.
+ *
+ * @param epsg EPSG Code representing SRID
+ * @return {@link org.locationtech.jts.geom.PrecisionModel}
+ */
+ private static PrecisionModel getPrecisionModel(Integer epsg) {
+ PrecisionModel precisionModel;
+ if (epsg == 4326) {
+ // use scale precision with 7 decimal positions like default OSM
+ precisionModel = new PrecisionModel(1000000);
+ } else {
+ // use default constructor
+ precisionModel = new PrecisionModel();
+ }
+ return precisionModel;
+ }
}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpTrajectoryBuilder.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpTrajectoryBuilder.java
index dff143021..4e05a84fe 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpTrajectoryBuilder.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpTrajectoryBuilder.java
@@ -54,10 +54,12 @@ public class SpTrajectoryBuilder {
/**
- * Adds a Point to the trajectory object and also handle removes old point if {link #numberSubPoints} threshold is exceeded.
+ * Adds a Point to the trajectory object and also handle removes old point
+ * if {link #numberSubPoints} threshold is exceeded.
*
* @param point {@link org.locationtech.jts.geom.Point}
- * @param m stores an extra integer to the sub-point of a trajectory {@link org.locationtech.jts.geom.CoordinateXYM#M}
+ * @param m stores an extra double value to the subpoint of a
+ * trajectory {@link org.locationtech.jts.geom.CoordinateXYM#M}
*/
public void addPointToTrajectory(Point point, Double m) {
coordinateList.add(createSingleTrajectoryCoordinate(point, m));
@@ -68,9 +70,10 @@ public class SpTrajectoryBuilder {
/**
- * 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]
+ * 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
@@ -97,11 +100,12 @@ public class SpTrajectoryBuilder {
}
/**
- * Creates a 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
+ * Creates a 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
+ * @param m Double M value, which will be used to store as extra parameter in the trajectory list
+ * for additional calculations
* @return CoordinateXYM coordinate object
*/
private Coordinate createSingleTrajectoryCoordinate(Point geom, Double m) {