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:51 UTC

[streampipes] branch STREAMPIPES-642 updated (09f7bda23 -> 4d8422248)

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

micklich pushed a change to branch STREAMPIPES-642
in repository https://gitbox.apache.org/repos/asf/streampipes.git


    from 09f7bda23 Merge remote-tracking branch 'origin/STREAMPIPES-642' into STREAMPIPES-642
     new c19efa058 [STREAMPIPES-642] style check on helper classes
     new f42a1845b [STREAMPIPES-642] change location from DistanceUtil and Rename
     new 8c11fdc87 [STREAMPIPES-642]  stylecheck
     new bcf5f4a2b [STREAMPIPES-642]  1 class for distance calculation. adjust ressources
     new d1736a6aa [STREAMPIPES-642]  distance caclulation delete old controller files
     new d520d8ef1 [STREAMPIPES-642] adjust misc format
     new a24c94cac [STREAMPIPES-642] Add missing icon command
     new 02f901c07 [STREAMPIPES-642] static distance  1 class , change resources
     new b55c6aabe [STREAMPIPES-642] remove old static distance controller
     new 2098a005c [STREAMPIPES-642] 1 class geocoder, change resources
     new 4d8422248 [STREAMPIPES-642] remove old geocoder classes

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../streampipes/processors/geo/jvm/GeoJvmInit.java |  11 +-
 .../geo/jvm/jts/helper/SpGeometryBuilder.java      | 194 +++++++++++----------
 .../geo/jvm/jts/helper/SpTrajectoryBuilder.java    |  20 ++-
 .../jvm/latlong/helper/HaversineDistanceUtil.java  |  42 ++---
 .../DistanceCalculatorProcessor.java               | 110 ++++++++++++
 .../geocoder/GoogleMapsGeocoderProcessor.java      | 121 +++++++++++++
 .../StaticDistanceCalculatorProcessor.java         | 113 ++++++++++++
 .../distancecalculator/DistanceCalculator.java     |  57 ------
 .../DistanceCalculatorController.java              |  81 ---------
 .../DistanceCalculatorParameters.java              |  59 -------
 .../processor/geocoder/GoogleMapsGeocoding.java    |  82 ---------
 .../geocoder/GoogleMapsGeocodingController.java    |  69 --------
 .../geocoder/GoogleMapsGeocodingParameters.java    |  36 ----
 .../geo/jvm/processor/speed/SpeedCalculator.java   |   4 +-
 .../StaticDistanceCalculator.java                  |  60 -------
 .../StaticDistanceCalculatorController.java        |  87 ---------
 .../StaticDistanceCalculatorParameters.java        |  65 -------
 .../geo/jvm/processor/util/DistanceUtil.java       |  34 ----
 .../strings.en                                     |  23 ---
 .../documentation.md                               |   8 +-
 .../icon.png                                       | Bin 0 -> 14322 bytes
 .../strings.en                                     |  17 +-
 .../documentation.md                               |   3 +-
 .../icon.png                                       | Bin 0 -> 13802 bytes
 .../strings.en                                     |  22 +--
 .../documentation.md                               |   9 +-
 .../icon.png                                       | Bin 0 -> 14111 bytes
 .../strings.en                                     |   4 +-
 28 files changed, 507 insertions(+), 824 deletions(-)
 copy streampipes-logging/src/main/java/org/apache/streampipes/logging/model/LogRequest.java => streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java (53%)
 create mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
 create mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/geocoder/GoogleMapsGeocoderProcessor.java
 create mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/staticdistancecalculator/StaticDistanceCalculatorProcessor.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorController.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorParameters.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocoding.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingController.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingParameters.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorController.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorParameters.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/DistanceUtil.java
 delete mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processor.geo.jvm.geocoding/strings.en
 rename streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/{org.apache.streampipes.processors.geo.jvm.processor.distancecalculator => org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator}/documentation.md (91%)
 create mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/icon.png
 rename streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/{org.apache.streampipes.processors.geo.jvm.processor.distancecalculator => org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator}/strings.en (65%)
 rename streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/{org.apache.streampipes.processor.geo.jvm.geocoding => org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder}/documentation.md (93%)
 create mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/icon.png
 copy installer/cli/deploy/standalone/rocketmq/docker-compose.dev.yml => streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/strings.en (68%)
 rename streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/{org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator => org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator}/documentation.md (80%)
 create mode 100644 streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/icon.png
 rename streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/{org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator => org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator}/strings.en (79%)


[streampipes] 10/11: [STREAMPIPES-642] 1 class geocoder, change resources

Posted by mi...@apache.org.
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 2098a005c058951f631f89e031a5a2eda39c5252
Author: micklich <mi...@apache.org>
AuthorDate: Wed Nov 30 12:43:09 2022 +0100

    [STREAMPIPES-642] 1 class geocoder, change resources
---
 .../streampipes/processors/geo/jvm/GeoJvmInit.java |   3 +-
 .../geocoder/GoogleMapsGeocoderProcessor.java      | 121 +++++++++++++++++++++
 .../documentation.md                               |   3 +-
 .../icon.png                                       | Bin 0 -> 13802 bytes
 .../strings.en                                     |   8 +-
 5 files changed, 129 insertions(+), 6 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 2dee325b4..2a3036bd9 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
@@ -33,6 +33,7 @@ import org.apache.streampipes.processors.geo.jvm.jts.processor.epsg.EpsgProcesso
 import org.apache.streampipes.processors.geo.jvm.jts.processor.latlngtojtspoint.LatLngToJtsPointProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory.TrajectoryFromPointsProcessor;
 import org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator.DistanceCalculatorProcessor;
+import org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder.GoogleMapsGeocoderProcessor;
 import org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator.StaticDistanceCalculatorProcessor;
 import org.apache.streampipes.processors.geo.jvm.processor.geocoder.GoogleMapsGeocodingController;
 import org.apache.streampipes.processors.geo.jvm.processor.revgeocoder.ReverseGeocodingController;
@@ -49,7 +50,7 @@ public class GeoJvmInit extends StandaloneModelSubmitter {
             8090)
             .registerPipelineElements(
                     new DistanceCalculatorProcessor(),
-                    new GoogleMapsGeocodingController(),
+                    new GoogleMapsGeocoderProcessor(),
                     new StaticGoogleMapsGeocodingController(),
                     new ReverseGeocodingController(),
                     new EpsgProcessor(),
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/geocoder/GoogleMapsGeocoderProcessor.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/geocoder/GoogleMapsGeocoderProcessor.java
new file mode 100644
index 000000000..23f4bd8a0
--- /dev/null
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/geocoder/GoogleMapsGeocoderProcessor.java
@@ -0,0 +1,121 @@
+/*
+ * 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.latlong.processor.geocoder;
+
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.model.DataProcessorType;
+import org.apache.streampipes.model.graph.DataProcessorDescription;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.model.schema.PropertyScope;
+import org.apache.streampipes.processors.geo.jvm.config.ConfigKeys;
+import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
+import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
+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.OutputStrategies;
+import org.apache.streampipes.sdk.utils.Assets;
+import org.apache.streampipes.vocabulary.Geo;
+import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.wrapper.routing.SpOutputCollector;
+import org.apache.streampipes.wrapper.standalone.ProcessorParams;
+import org.apache.streampipes.wrapper.standalone.StreamPipesDataProcessor;
+
+import com.google.maps.GeoApiContext;
+import com.google.maps.GeocodingApi;
+import com.google.maps.errors.ApiException;
+import com.google.maps.model.GeocodingResult;
+
+import java.io.IOException;
+
+public class GoogleMapsGeocoderProcessor extends StreamPipesDataProcessor {
+    private static final String GEOCODER_REQUEST_KEY = "geocoder-request-key";
+    private static final String LAT_RUNTIME_NAME = "geocoder-latitude";
+    private static final String LONG_RUNTIME_NAME = "geocoder-longitude";
+    private String geocoderRequest;
+    private GeoApiContext apiContext;
+
+    @Override
+    public DataProcessorDescription declareModel() {
+        return ProcessingElementBuilder
+                .create("org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder")
+                .category(DataProcessorType.GEO)
+                .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+                .withLocales(Locales.EN)
+                .requiredStream(StreamRequirementsBuilder
+                        .create()
+                        .requiredPropertyWithUnaryMapping(EpRequirements.stringReq(),
+                                Labels.withId(GEOCODER_REQUEST_KEY),
+                                PropertyScope.NONE)
+                        .build()
+                )
+                .outputStrategy(OutputStrategies.append(
+                        EpProperties.doubleEp(Labels.empty(), LAT_RUNTIME_NAME, Geo.lat),
+                        EpProperties.stringEp(Labels.empty(), LONG_RUNTIME_NAME, Geo.lng))
+                )
+                .build();
+    }
+
+    @Override
+    public void onInvocation(ProcessorParams parameters, SpOutputCollector spOutputCollector,
+                             EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
+
+        this.geocoderRequest = parameters.extractor().mappingPropertyValue(GEOCODER_REQUEST_KEY);
+
+        String googleMapsApiKey = runtimeContext.getConfigStore().getConfig().getString(ConfigKeys.GOOGLE_API_KEY);
+
+        if (googleMapsApiKey == null || googleMapsApiKey.equals("")) {
+            throw new SpRuntimeException("Could not start Geocoder. Did you forget to add a Google Maps API key?");
+        } else {
+            this.apiContext = new GeoApiContext.Builder()
+                    .apiKey(googleMapsApiKey)
+                    .build();
+        }
+        // TODO: RequestDeniedException
+        //  You must enable Billing on the Google Cloud Project at
+        //  https://console.cloud.google.com/project/_/billing/enable
+        //  Learn more at https://developers.google.com/maps/gmp
+    }
+
+    @Override
+    public void onEvent(Event event, SpOutputCollector collector) throws SpRuntimeException {
+        String request = event.getFieldBySelector(geocoderRequest).getAsPrimitive().getAsString();
+
+        try {
+            GeocodingResult[] results =  GeocodingApi.geocode(apiContext, request).await();
+
+            Double latitude = results[0].geometry.location.lat;
+            Double longitude = results[0].geometry.location.lng;
+
+            event.addField(LAT_RUNTIME_NAME, latitude);
+            event.addField(LONG_RUNTIME_NAME, longitude);
+
+            collector.collect(event);
+
+        } catch (ApiException | InterruptedException | IOException e) {
+            e.printStackTrace();
+            throw new SpRuntimeException("Could not fetch geocoding result");
+        }
+    }
+
+    @Override
+    public void onDetach() throws SpRuntimeException {
+
+    }
+}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processor.geo.jvm.geocoding/documentation.md b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/documentation.md
similarity index 93%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processor.geo.jvm.geocoding/documentation.md
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/documentation.md
index 6e844091c..3e929897a 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processor.geo.jvm.geocoding/documentation.md
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/documentation.md
@@ -18,7 +18,8 @@
 
 ## Google Maps Geocoding
 
-<p align="center"> 
+<p align="center">
+    <img src="icon.png" width="150px;" class="pe-image-documentation"/>
 </p>
 
 ***
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/icon.png b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/icon.png
new file mode 100644
index 000000000..46ff0e035
Binary files /dev/null and b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/icon.png differ
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processor.geo.jvm.geocoding/strings.en b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/strings.en
similarity index 67%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processor.geo.jvm.geocoding/strings.en
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/strings.en
index 980aa6090..fe677d224 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processor.geo.jvm.geocoding/strings.en
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder/strings.en
@@ -16,8 +16,8 @@
 #
 
 
-org.apache.streampipes.processor.geo.jvm.geocoding.title=Google Maps Geocoder
-org.apache.streampipes.processor.geo.jvm.geocoding.description=Geocodes a placename to a latitude/longitude combination
+org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder.title=Google Maps Geocoder
+org.apache.streampipes.processors.geo.jvm.latlong.processor.geocoder.description=Geocodes a place-name to a latitude/longitude combination
 
-place-mapping.title=Place
-place-mapping.description=The field of the input event that should be used to compute the lat/lng values.
\ No newline at end of file
+geocoder-request-key.title=Address
+geocoder-request-key.description=The field of the input event that should be used to compute the lat/lng values.
\ No newline at end of file


[streampipes] 04/11: [STREAMPIPES-642] 1 class for distance calculation. adjust ressources

Posted by mi...@apache.org.
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 bcf5f4a2bc186c51cb964f2595a608a1c68265bf
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 16:17:06 2022 +0100

    [STREAMPIPES-642]  1 class for distance calculation. adjust ressources
---
 .../streampipes/processors/geo/jvm/GeoJvmInit.java |   4 +-
 .../DistanceCalculatorProcessor.java               | 104 +++++++++++++++++++++
 .../documentation.md                               |   8 +-
 .../icon.png                                       | Bin 0 -> 14322 bytes
 .../strings.en                                     |  17 ++--
 5 files changed, 119 insertions(+), 14 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 815ada965..55f990827 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
@@ -32,7 +32,7 @@ import org.apache.streampipes.processors.geo.jvm.config.ConfigKeys;
 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.trajectory.TrajectoryFromPointsProcessor;
-import org.apache.streampipes.processors.geo.jvm.processor.distancecalculator.DistanceCalculatorController;
+import org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator.DistanceCalculatorProcessor;
 import org.apache.streampipes.processors.geo.jvm.processor.geocoder.GoogleMapsGeocodingController;
 import org.apache.streampipes.processors.geo.jvm.processor.revgeocoder.ReverseGeocodingController;
 import org.apache.streampipes.processors.geo.jvm.processor.speed.SpeedCalculatorController;
@@ -48,7 +48,7 @@ public class GeoJvmInit extends StandaloneModelSubmitter {
             "",
             8090)
             .registerPipelineElements(
-                    new DistanceCalculatorController(),
+                    new DistanceCalculatorProcessor(),
                     new GoogleMapsGeocodingController(),
                     new StaticGoogleMapsGeocodingController(),
                     new ReverseGeocodingController(),
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
new file mode 100644
index 000000000..0b5e8e73b
--- /dev/null
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
@@ -0,0 +1,104 @@
+/*
+ * 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.latlong.processor.distancecalculator;
+
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.model.DataProcessorType;
+import org.apache.streampipes.model.graph.DataProcessorDescription;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.model.schema.PropertyScope;
+import org.apache.streampipes.processors.geo.jvm.latlong.helper.HaversineDistanceUtil;
+import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
+import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
+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.OutputStrategies;
+import org.apache.streampipes.sdk.utils.Assets;
+import org.apache.streampipes.vocabulary.Geo;
+import org.apache.streampipes.vocabulary.SO;
+import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.wrapper.routing.SpOutputCollector;
+import org.apache.streampipes.wrapper.standalone.ProcessorParams;
+import org.apache.streampipes.wrapper.standalone.StreamPipesDataProcessor;
+
+public class DistanceCalculatorProcessor extends StreamPipesDataProcessor {
+    private static final String LAT_1_KEY = "lat1";
+    private static final String LONG_1_KEY = "long1";
+    private static final String LAT_2_KEY = "lat2";
+    private static final String LONG_2_KEY = "long2";
+    private static final String CALCULATED_DISTANCE_KEY = "calculatedDistance";
+    String lat1FieldMapper;
+    String long1FieldMapper;
+    String lat2FieldMapper;
+    String long2FieldMapper;
+
+    @Override
+    public DataProcessorDescription declareModel() {
+        return ProcessingElementBuilder.create(
+                        "org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator")
+                .category(DataProcessorType.GEO)
+                .withAssets(Assets.DOCUMENTATION)
+                .withLocales(Locales.EN)
+                .requiredStream(StreamRequirementsBuilder
+                        .create()
+                        .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lat),
+                                Labels.withId(LAT_1_KEY), PropertyScope.MEASUREMENT_PROPERTY)
+                        .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lng),
+                                Labels.withId(LONG_1_KEY), PropertyScope.MEASUREMENT_PROPERTY)
+                        .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lat),
+                                Labels.withId(LAT_2_KEY), PropertyScope.MEASUREMENT_PROPERTY)
+                        .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lng),
+                                Labels.withId(LONG_2_KEY), PropertyScope.MEASUREMENT_PROPERTY).build()).outputStrategy(
+                        OutputStrategies.append(
+                                EpProperties.numberEp(Labels.withId(CALCULATED_DISTANCE_KEY), "distance", SO.Number)))
+                .build();
+    }
+
+    @Override
+    public void onInvocation(ProcessorParams parameters, SpOutputCollector spOutputCollector,
+                             EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
+
+        this.lat1FieldMapper = parameters.extractor().mappingPropertyValue(LAT_1_KEY);
+        this.long1FieldMapper = parameters.extractor().mappingPropertyValue(LONG_1_KEY);
+        this.lat2FieldMapper = parameters.extractor().mappingPropertyValue(LAT_2_KEY);
+        this.long2FieldMapper = parameters.extractor().mappingPropertyValue(LONG_2_KEY);
+
+    }
+
+    @Override
+    public void onEvent(Event event, SpOutputCollector collector) throws SpRuntimeException {
+
+        float lat1 = event.getFieldBySelector(lat1FieldMapper).getAsPrimitive().getAsFloat();
+        float long1 = event.getFieldBySelector(long1FieldMapper).getAsPrimitive().getAsFloat();
+        float lat2 = event.getFieldBySelector(lat2FieldMapper).getAsPrimitive().getAsFloat();
+        float long2 = event.getFieldBySelector(long2FieldMapper).getAsPrimitive().getAsFloat();
+
+        double resultDist = HaversineDistanceUtil.dist(lat1, long1, lat2, long2);
+
+        event.addField("distance", resultDist);
+
+        collector.collect(event);
+    }
+
+    @Override
+    public void onDetach() throws SpRuntimeException {
+
+    }
+}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.distancecalculator/documentation.md b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/documentation.md
similarity index 91%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.distancecalculator/documentation.md
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/documentation.md
index 5821bbfb4..ae7382554 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.distancecalculator/documentation.md
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/documentation.md
@@ -16,7 +16,7 @@
   ~
   -->
 
-## Distance Calculator
+## Haversine Distance Calculator
 
 <p align="center"> 
     <img src="icon.png" width="150px;" class="pe-image-documentation"/>
@@ -25,7 +25,11 @@
 ***
 
 ## Description
-Calculates the distance between two latitude/longitude pairs in a single event.
+Calculates the distance between two latitude/longitude pairs in a single event with the
+<a href="https://en.wikipedia.org/wiki/Haversine_formula" target="_blank">Haversine formula</a>.
+ 
+
+
 
 ***
 
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/icon.png b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/icon.png
new file mode 100644
index 000000000..3876342d8
Binary files /dev/null and b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/icon.png differ
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.distancecalculator/strings.en b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/strings.en
similarity index 65%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.distancecalculator/strings.en
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/strings.en
index c39ad9687..a94f6f895 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.distancecalculator/strings.en
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator/strings.en
@@ -16,20 +16,17 @@
 #
 
 
-org.apache.streampipes.processors.geo.jvm.processor.distancecalculator.title=Distance Calculator
-org.apache.streampipes.processors.geo.jvm.processor.distancecalculator.description=Calculates the distance between two geo points
+org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator.title=Haversine Distance Calculator
+org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator.description=Calculates the distance between two geo points with the Haversine formula
 
-lat1.title=First Latitude
+lat1.title=First Latitude Position 1
 lat1.description=
 
-long1.title=First Longitude
+long1.title=First Longitude Position 1
 long1.description=
 
-lat2.title=Second Latitude
+lat2.title=Second Latitude Position 2
 lat2.description=
 
-long2.title=Second Longitude
-long2.description=
-
-calculatedDistance.title=Distance Field
-startingCell.description=
\ No newline at end of file
+long2.title=Second Longitude Position 2
+long2.description=
\ No newline at end of file


[streampipes] 09/11: [STREAMPIPES-642] remove old static distance controller

Posted by mi...@apache.org.
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 b55c6aabe1bc066d7c2a1a6b6ffcb7c17f01edad
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 21:55:39 2022 +0100

    [STREAMPIPES-642] remove old static distance controller
---
 .../StaticDistanceCalculator.java                  | 60 ---------------
 .../StaticDistanceCalculatorController.java        | 87 ----------------------
 .../StaticDistanceCalculatorParameters.java        | 65 ----------------
 3 files changed, 212 deletions(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
deleted file mode 100644
index 9fc79946e..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *   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.processor.staticdistancecalculator;
-
-import org.apache.streampipes.commons.exceptions.SpRuntimeException;
-import org.apache.streampipes.model.runtime.Event;
-import org.apache.streampipes.processors.geo.jvm.latlong.helper.HaversineDistanceUtil;
-import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
-import org.apache.streampipes.wrapper.routing.SpOutputCollector;
-import org.apache.streampipes.wrapper.runtime.EventProcessor;
-
-public class StaticDistanceCalculator implements EventProcessor<StaticDistanceCalculatorParameters> {
-
-  private String latitudeFieldName;
-  private String longitudeFieldName;
-
-  private Float selectedLocationLatitude;
-  private Float selectedLocationLongitude;
-
-  @Override
-  public void onInvocation(StaticDistanceCalculatorParameters parameters, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
-    this.latitudeFieldName = parameters.getLatitudeFieldName();
-    this.longitudeFieldName = parameters.getLongitudeFieldName();
-
-    this.selectedLocationLatitude = parameters.getSelectedLatitude();
-    this.selectedLocationLongitude = parameters.getSelectedLongitude();
-  }
-
-  @Override
-  public void onEvent(Event event, SpOutputCollector collector) throws SpRuntimeException {
-    Float latitude = event.getFieldBySelector(latitudeFieldName).getAsPrimitive().getAsFloat();
-    Float longitude = event.getFieldBySelector(longitudeFieldName).getAsPrimitive().getAsFloat();
-
-    Float distance = HaversineDistanceUtil.dist(latitude, longitude, selectedLocationLatitude,
-            selectedLocationLongitude);
-
-    event.addField("distance", distance);
-
-    collector.collect(event);
-  }
-
-  @Override
-  public void onDetach() throws SpRuntimeException {
-
-  }
-}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorController.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorController.java
deleted file mode 100644
index 1885e1112..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorController.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- *   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.processor.staticdistancecalculator;
-
-import org.apache.streampipes.model.DataProcessorType;
-import org.apache.streampipes.model.graph.DataProcessorDescription;
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import org.apache.streampipes.model.schema.PropertyScope;
-import org.apache.streampipes.sdk.builder.PrimitivePropertyBuilder;
-import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
-import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
-import org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
-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.OutputStrategies;
-import org.apache.streampipes.sdk.utils.Assets;
-import org.apache.streampipes.sdk.utils.Datatypes;
-import org.apache.streampipes.vocabulary.Geo;
-import org.apache.streampipes.vocabulary.SO;
-import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
-import org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
-
-import java.net.URI;
-
-public class StaticDistanceCalculatorController extends StandaloneEventProcessingDeclarer<StaticDistanceCalculatorParameters> {
-
-  private static final String LATITUDE_KEY = "latitude-key";
-  private static final String LONGITUDE_KEY = "longitude-key" ;
-  private static final String SELECTED_LATITUDE_KEY = "selected-latitude-key";
-  private static final String SELECTED_LONGITUDE_KEY = "selected-longitude-key";
-
-  @Override
-  public DataProcessorDescription declareModel() {
-    return ProcessingElementBuilder.create("org.apache.streampipes.processors.geo.jvm.processor" +
-            ".staticdistancecalculator")
-            .category(DataProcessorType.GEO)
-            .withAssets(Assets.DOCUMENTATION)
-            .withLocales(Locales.EN)
-            .requiredStream(StreamRequirementsBuilder
-                    .create()
-                    .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lat)
-                            , Labels.withId(LATITUDE_KEY), PropertyScope.MEASUREMENT_PROPERTY)
-                    .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lng)
-                            , Labels.withId(LONGITUDE_KEY), PropertyScope.MEASUREMENT_PROPERTY)
-                    .build())
-            .requiredFloatParameter(Labels.withId(SELECTED_LATITUDE_KEY))
-            .requiredFloatParameter(Labels.withId(SELECTED_LONGITUDE_KEY))
-            .outputStrategy(
-                    OutputStrategies.append(PrimitivePropertyBuilder
-                            .create(Datatypes.Float,"distance")
-                            .domainProperty(SO.Number)
-                            .measurementUnit(URI.create("http://qudt.org/vocab/unit#Kilometer"))
-                            .build())
-            )
-            .build();
-
-  }
-
-  @Override
-  public ConfiguredEventProcessor<StaticDistanceCalculatorParameters> onInvocation(DataProcessorInvocation graph,
-                                                  ProcessingElementParameterExtractor extractor) {
-    String latitudeFieldName = extractor.mappingPropertyValue(LATITUDE_KEY);
-    String longitudeFieldName = extractor.mappingPropertyValue(LONGITUDE_KEY);
-    Float selectedLatitude = extractor.singleValueParameter(SELECTED_LATITUDE_KEY, Float.class);
-    Float selectedLongitude = extractor.singleValueParameter(SELECTED_LONGITUDE_KEY, Float.class);
-
-    StaticDistanceCalculatorParameters staticParam = new StaticDistanceCalculatorParameters(graph,
-            latitudeFieldName, longitudeFieldName, selectedLatitude, selectedLongitude);
-
-    return new ConfiguredEventProcessor<>(staticParam, StaticDistanceCalculator::new);
-  }
-}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorParameters.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorParameters.java
deleted file mode 100644
index 0d7e34773..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculatorParameters.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *   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.processor.staticdistancecalculator;
-
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import org.apache.streampipes.wrapper.params.binding.EventProcessorBindingParams;
-
-public class StaticDistanceCalculatorParameters extends EventProcessorBindingParams {
-
-  private String latitudeFieldName;
-  private String longitudeFieldName;
-
-  private Float selectedLatitude;
-  private Float selectedLongitude;
-
-  public StaticDistanceCalculatorParameters(DataProcessorInvocation graph,
-                                            String latitudeFieldName,
-                                            String longitudeFieldName,
-                                            Float selectedLatitude,
-                                            Float selectedLongitude) {
-    super(graph);
-    this.latitudeFieldName = latitudeFieldName;
-    this.longitudeFieldName = longitudeFieldName;
-    this.selectedLatitude = selectedLatitude;
-    this.selectedLongitude = selectedLongitude;
-  }
-
-  public String getLatitudeFieldName() {
-    return latitudeFieldName;
-  }
-
-  public String getLongitudeFieldName() {
-    return longitudeFieldName;
-  }
-
-  public Float getSelectedLatitude() {
-    return selectedLatitude;
-  }
-
-  public void setSelectedLatitude(Float selectedLatitude) {
-    this.selectedLatitude = selectedLatitude;
-  }
-
-  public Float getSelectedLongitude() {
-    return selectedLongitude;
-  }
-
-  public void setSelectedLongitude(Float selectedLongitude) {
-    this.selectedLongitude = selectedLongitude;
-  }
-}


[streampipes] 07/11: [STREAMPIPES-642] Add missing icon command

Posted by mi...@apache.org.
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 a24c94cac3165a4a312f05d3237c583c987c2d5f
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 16:39:07 2022 +0100

    [STREAMPIPES-642] Add missing icon command
---
 .../processor/distancecalculator/DistanceCalculatorProcessor.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
index b3424cb53..a27deb8df 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
@@ -54,7 +54,7 @@ public class DistanceCalculatorProcessor extends StreamPipesDataProcessor {
         return ProcessingElementBuilder.create(
                         "org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator")
                 .category(DataProcessorType.GEO)
-                .withAssets(Assets.DOCUMENTATION)
+                .withAssets(Assets.DOCUMENTATION, Assets.ICON)
                 .withLocales(Locales.EN)
                 .requiredStream(StreamRequirementsBuilder
                         .create()


[streampipes] 01/11: [STREAMPIPES-642] style check on helper classes

Posted by mi...@apache.org.
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 &lt; Longitude &gt; 180
-   * @param lat  Latitude value in the range -90 &lt; LATITUDE &gt; 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 &lt; Longitude &gt; 180
+     * @param lat  Latitude value in the range -90 &lt; LATITUDE &gt; 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) {


[streampipes] 02/11: [STREAMPIPES-642] change location from DistanceUtil and Rename

Posted by mi...@apache.org.
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 f42a1845b51a0c2aaff399b23449a99d3c6a52f0
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 10:15:57 2022 +0100

    [STREAMPIPES-642] change location from DistanceUtil and Rename
---
 .../jvm/latlong/helper/HaversineDistanceUtil.java  | 34 ++++++++++++++++++++++
 .../distancecalculator/DistanceCalculator.java     |  4 +--
 .../geo/jvm/processor/speed/SpeedCalculator.java   |  4 +--
 .../StaticDistanceCalculator.java                  |  4 +--
 .../geo/jvm/processor/util/DistanceUtil.java       | 34 ----------------------
 5 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java
new file mode 100644
index 000000000..e7848c9ac
--- /dev/null
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java
@@ -0,0 +1,34 @@
+/*
+ * 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.latlong.helper;
+
+public class HaversineDistanceUtil {
+
+  public static float dist(float lat1, float lng1, float lat2, float lng2) {
+    double earthRadius = 6371000; //meters
+    double dLat = Math.toRadians(lat2-lat1);
+    double dLng = Math.toRadians(lng2-lng1);
+    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
+            Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
+                    Math.sin(dLng/2) * Math.sin(dLng/2);
+    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+    float dist = (float) (earthRadius * c);
+
+    return dist / 1000;
+  }
+
+}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
index d310f1b48..ec07a84c9 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
@@ -19,7 +19,7 @@
 package org.apache.streampipes.processors.geo.jvm.processor.distancecalculator;
 
 import org.apache.streampipes.model.runtime.Event;
-import org.apache.streampipes.processors.geo.jvm.processor.util.DistanceUtil;
+import org.apache.streampipes.processors.geo.jvm.latlong.helper.HaversineDistanceUtil;
 import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
 import org.apache.streampipes.wrapper.routing.SpOutputCollector;
 import org.apache.streampipes.wrapper.runtime.EventProcessor;
@@ -42,7 +42,7 @@ public class DistanceCalculator implements EventProcessor<DistanceCalculatorPara
     float lat2 = event.getFieldBySelector(this.params.getLat2PropertyName()).getAsPrimitive().getAsFloat();
     float long2 = event.getFieldBySelector(this.params.getLong2PropertyName()).getAsPrimitive().getAsFloat();
 
-    double resultDist = DistanceUtil.dist(lat1, long1, lat2, long2);
+    double resultDist = HaversineDistanceUtil.dist(lat1, long1, lat2, long2);
 
     event.addField("distance", resultDist);
 
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/speed/SpeedCalculator.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/speed/SpeedCalculator.java
index 307c00aba..04849e0d4 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/speed/SpeedCalculator.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/speed/SpeedCalculator.java
@@ -19,7 +19,7 @@ package org.apache.streampipes.processors.geo.jvm.processor.speed;
 import org.apache.commons.collections.buffer.CircularFifoBuffer;
 import org.apache.streampipes.commons.exceptions.SpRuntimeException;
 import org.apache.streampipes.model.runtime.Event;
-import org.apache.streampipes.processors.geo.jvm.processor.util.DistanceUtil;
+import org.apache.streampipes.processors.geo.jvm.latlong.helper.HaversineDistanceUtil;
 import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
 import org.apache.streampipes.wrapper.routing.SpOutputCollector;
 import org.apache.streampipes.wrapper.runtime.EventProcessor;
@@ -60,7 +60,7 @@ public class SpeedCalculator implements EventProcessor<SpeedCalculatorParameters
     Float currentLongitude = getFloat(currentEvent, longitudeFieldName);
     Long currentTimestamp = getLong(currentEvent, timestampFieldName);
 
-    Float distanceInKm = DistanceUtil.dist(firstLatitude, firstLongitude, currentLatitude,
+    Float distanceInKm = HaversineDistanceUtil.dist(firstLatitude, firstLongitude, currentLatitude,
             currentLongitude);
 
     Long durationInSeconds = (currentTimestamp - firstTimestamp) / 1000;
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
index 2889388e9..9fc79946e 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
@@ -18,7 +18,7 @@ package org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalcul
 
 import org.apache.streampipes.commons.exceptions.SpRuntimeException;
 import org.apache.streampipes.model.runtime.Event;
-import org.apache.streampipes.processors.geo.jvm.processor.util.DistanceUtil;
+import org.apache.streampipes.processors.geo.jvm.latlong.helper.HaversineDistanceUtil;
 import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
 import org.apache.streampipes.wrapper.routing.SpOutputCollector;
 import org.apache.streampipes.wrapper.runtime.EventProcessor;
@@ -45,7 +45,7 @@ public class StaticDistanceCalculator implements EventProcessor<StaticDistanceCa
     Float latitude = event.getFieldBySelector(latitudeFieldName).getAsPrimitive().getAsFloat();
     Float longitude = event.getFieldBySelector(longitudeFieldName).getAsPrimitive().getAsFloat();
 
-    Float distance = DistanceUtil.dist(latitude, longitude, selectedLocationLatitude,
+    Float distance = HaversineDistanceUtil.dist(latitude, longitude, selectedLocationLatitude,
             selectedLocationLongitude);
 
     event.addField("distance", distance);
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/DistanceUtil.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/DistanceUtil.java
deleted file mode 100644
index 136eecdaf..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/DistanceUtil.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- *   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.processor.util;
-
-public class DistanceUtil {
-
-  public static float dist(float lat1, float lng1, float lat2, float lng2) {
-    double earthRadius = 6371000; //meters
-    double dLat = Math.toRadians(lat2-lat1);
-    double dLng = Math.toRadians(lng2-lng1);
-    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
-            Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
-                    Math.sin(dLng/2) * Math.sin(dLng/2);
-    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
-    float dist = (float) (earthRadius * c);
-
-    return dist / 1000;
-  }
-
-}


[streampipes] 08/11: [STREAMPIPES-642] static distance 1 class , change resources

Posted by mi...@apache.org.
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 02f901c077199fd33b69c44c34c39f087da62391
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 21:54:45 2022 +0100

    [STREAMPIPES-642] static distance  1 class , change resources
---
 .../streampipes/processors/geo/jvm/GeoJvmInit.java |   4 +-
 .../StaticDistanceCalculatorProcessor.java         | 113 +++++++++++++++++++++
 .../documentation.md                               |   9 +-
 .../icon.png                                       | Bin 0 -> 14111 bytes
 .../strings.en                                     |   4 +-
 5 files changed, 124 insertions(+), 6 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 55f990827..2dee325b4 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
@@ -33,10 +33,10 @@ import org.apache.streampipes.processors.geo.jvm.jts.processor.epsg.EpsgProcesso
 import org.apache.streampipes.processors.geo.jvm.jts.processor.latlngtojtspoint.LatLngToJtsPointProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory.TrajectoryFromPointsProcessor;
 import org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator.DistanceCalculatorProcessor;
+import org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator.StaticDistanceCalculatorProcessor;
 import org.apache.streampipes.processors.geo.jvm.processor.geocoder.GoogleMapsGeocodingController;
 import org.apache.streampipes.processors.geo.jvm.processor.revgeocoder.ReverseGeocodingController;
 import org.apache.streampipes.processors.geo.jvm.processor.speed.SpeedCalculatorController;
-import org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator.StaticDistanceCalculatorController;
 import org.apache.streampipes.processors.geo.jvm.processor.staticgeocoder.StaticGoogleMapsGeocodingController;
 
 public class GeoJvmInit extends StandaloneModelSubmitter {
@@ -56,7 +56,7 @@ public class GeoJvmInit extends StandaloneModelSubmitter {
                     new LatLngToJtsPointProcessor(),
                     new TrajectoryFromPointsProcessor(),
                     new SpeedCalculatorController(),
-                    new StaticDistanceCalculatorController())
+                    new StaticDistanceCalculatorProcessor())
             .registerMessagingFormats(
                     new JsonDataFormatFactory(),
                     new CborDataFormatFactory(),
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/staticdistancecalculator/StaticDistanceCalculatorProcessor.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/staticdistancecalculator/StaticDistanceCalculatorProcessor.java
new file mode 100644
index 000000000..71fd584ef
--- /dev/null
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/staticdistancecalculator/StaticDistanceCalculatorProcessor.java
@@ -0,0 +1,113 @@
+/*
+ * 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.latlong.processor.staticdistancecalculator;
+
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.model.DataProcessorType;
+import org.apache.streampipes.model.graph.DataProcessorDescription;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.model.schema.PropertyScope;
+import org.apache.streampipes.processors.geo.jvm.latlong.helper.HaversineDistanceUtil;
+import org.apache.streampipes.sdk.builder.PrimitivePropertyBuilder;
+import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
+import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
+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.OutputStrategies;
+import org.apache.streampipes.sdk.utils.Assets;
+import org.apache.streampipes.sdk.utils.Datatypes;
+import org.apache.streampipes.vocabulary.Geo;
+import org.apache.streampipes.vocabulary.SO;
+import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.wrapper.routing.SpOutputCollector;
+import org.apache.streampipes.wrapper.standalone.ProcessorParams;
+import org.apache.streampipes.wrapper.standalone.StreamPipesDataProcessor;
+
+import java.net.URI;
+
+
+public class StaticDistanceCalculatorProcessor extends StreamPipesDataProcessor {
+
+    private static final String LATITUDE_KEY = "latitude-key";
+    private static final String LONGITUDE_KEY = "longitude-key";
+    private static final String SELECTED_LATITUDE_KEY = "selected-latitude-key";
+    private static final String SELECTED_LONGITUDE_KEY = "selected-longitude-key";
+
+    String latitudeFieldMapper;
+    String longitudeFieldMapper;
+    Float selectedLatitude;
+    Float selectedLongitude;
+
+    @Override
+    public DataProcessorDescription declareModel() {
+        return ProcessingElementBuilder.create(
+                        "org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator")
+                .category(DataProcessorType.GEO)
+                .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+                .withLocales(Locales.EN)
+                .requiredStream(StreamRequirementsBuilder
+                        .create()
+                        .requiredPropertyWithUnaryMapping(
+                                EpRequirements.domainPropertyReq(Geo.lat),
+                                Labels.withId(LATITUDE_KEY),
+                                PropertyScope.MEASUREMENT_PROPERTY)
+                        .requiredPropertyWithUnaryMapping(
+                                EpRequirements.domainPropertyReq(Geo.lng),
+                                Labels.withId(LONGITUDE_KEY),
+                                PropertyScope.MEASUREMENT_PROPERTY)
+                        .build()
+                )
+                .requiredFloatParameter(Labels.withId(SELECTED_LATITUDE_KEY))
+                .requiredFloatParameter(Labels.withId(SELECTED_LONGITUDE_KEY))
+                .outputStrategy(OutputStrategies.append(PrimitivePropertyBuilder
+                        .create(Datatypes.Float, "distance")
+                        .domainProperty(SO.Number)
+                        .measurementUnit(URI.create("http://qudt.org/vocab/unit#Kilometer"))
+                        .build())
+                )
+                .build();
+    }
+
+    @Override
+    public void onInvocation(ProcessorParams parameters, SpOutputCollector spOutputCollector,
+                             EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
+        this.latitudeFieldMapper = parameters.extractor().mappingPropertyValue(LATITUDE_KEY);
+        this.longitudeFieldMapper = parameters.extractor().mappingPropertyValue(LONGITUDE_KEY);
+        this.selectedLatitude = parameters.extractor().singleValueParameter(SELECTED_LATITUDE_KEY, Float.class);
+        this.selectedLongitude = parameters.extractor().singleValueParameter(SELECTED_LONGITUDE_KEY, Float.class);
+    }
+
+    @Override
+    public void onEvent(Event event, SpOutputCollector collector) throws SpRuntimeException {
+        Float latitude = event.getFieldBySelector(latitudeFieldMapper).getAsPrimitive().getAsFloat();
+        Float longitude = event.getFieldBySelector(longitudeFieldMapper).getAsPrimitive().getAsFloat();
+
+        Float distance = HaversineDistanceUtil.dist(latitude, longitude, selectedLatitude, selectedLongitude);
+
+        event.addField("distance", distance);
+
+        collector.collect(event);
+
+    }
+
+    @Override
+    public void onDetach() throws SpRuntimeException {
+
+    }
+}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator/documentation.md b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/documentation.md
similarity index 80%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator/documentation.md
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/documentation.md
index e32dd92ba..5cb7d978a 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator/documentation.md
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/documentation.md
@@ -18,16 +18,21 @@
 
 ## Static Distance Calculator
 
+<p align="center"> 
+    <img src="icon.png" width="150px;" class="pe-image-documentation"/>
+</p>
+
 ***
 
 ## Description
 
-Calculates the distance (in km) between a fixed location (e.g., a place) and a latitude/longitude pair of an input
+Calculates the distance with the <a href="https://en.wikipedia.org/wiki/Haversine_formula" target="_blank">Haversine formula</a> between a fixed location (e.g., a place) and a latitude/longitude pair of an input
  event.
 
+
 ***
 
-## Required input
+## Required Inputs
 
 Requires a data stream that provides latitude and longitude values.
 
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/icon.png b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/icon.png
new file mode 100644
index 000000000..c5f80c7f0
Binary files /dev/null and b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/icon.png differ
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator/strings.en b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/strings.en
similarity index 79%
rename from streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator/strings.en
rename to streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/strings.en
index 0186b43d0..916a94f90 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator/strings.en
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/resources/org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator/strings.en
@@ -16,8 +16,8 @@
 #
 
 
-org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator.title=Static Distance Calculator
-org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator.description=Calculates the distance between a fixed location and a moving location
+org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator.title=Static Distance Calculator
+org.apache.streampipes.processors.geo.jvm.latlong.processor.staticdistancecalculator.description=Calculates the distance between a fixed location and a moving location
 
 latitude-key.title=Latitude field
 latitude-key.description=


[streampipes] 05/11: [STREAMPIPES-642] distance caclulation delete old controller files

Posted by mi...@apache.org.
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 d1736a6aa2330864cd96118b1323ecb5181046db
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 16:17:58 2022 +0100

    [STREAMPIPES-642]  distance caclulation delete old controller files
---
 .../distancecalculator/DistanceCalculator.java     | 57 ---------------
 .../DistanceCalculatorController.java              | 81 ----------------------
 .../DistanceCalculatorParameters.java              | 59 ----------------
 3 files changed, 197 deletions(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
deleted file mode 100644
index ec07a84c9..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.processor.distancecalculator;
-
-import org.apache.streampipes.model.runtime.Event;
-import org.apache.streampipes.processors.geo.jvm.latlong.helper.HaversineDistanceUtil;
-import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
-import org.apache.streampipes.wrapper.routing.SpOutputCollector;
-import org.apache.streampipes.wrapper.runtime.EventProcessor;
-
-public class DistanceCalculator implements EventProcessor<DistanceCalculatorParameters> {
-
-  private DistanceCalculatorParameters params;
-
-  @Override
-  public void onInvocation(DistanceCalculatorParameters numericalFilterParameters, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext
-          runtimeContext) {
-    this.params = numericalFilterParameters;
-  }
-
-  @Override
-  public void onEvent(Event event, SpOutputCollector out) {
-
-    float lat1 = event.getFieldBySelector(this.params.getLat1PropertyName()).getAsPrimitive().getAsFloat();
-    float long1 = event.getFieldBySelector(this.params.getLong1PropertyName()).getAsPrimitive().getAsFloat();
-    float lat2 = event.getFieldBySelector(this.params.getLat2PropertyName()).getAsPrimitive().getAsFloat();
-    float long2 = event.getFieldBySelector(this.params.getLong2PropertyName()).getAsPrimitive().getAsFloat();
-
-    double resultDist = HaversineDistanceUtil.dist(lat1, long1, lat2, long2);
-
-    event.addField("distance", resultDist);
-
-    out.collect(event);
-  }
-
-  @Override
-  public void onDetach() {
-
-  }
-
-}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorController.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorController.java
deleted file mode 100644
index ddf9945b7..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorController.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.processor.distancecalculator;
-
-import org.apache.streampipes.model.DataProcessorType;
-import org.apache.streampipes.model.graph.DataProcessorDescription;
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import org.apache.streampipes.model.schema.PropertyScope;
-import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
-import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
-import org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
-import org.apache.streampipes.sdk.helpers.*;
-import org.apache.streampipes.sdk.utils.Assets;
-import org.apache.streampipes.vocabulary.Geo;
-import org.apache.streampipes.vocabulary.SO;
-import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
-import org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
-
-public class DistanceCalculatorController extends StandaloneEventProcessingDeclarer<DistanceCalculatorParameters> {
-
-  private static final String LAT_1_KEY = "lat1";
-  private static final String LONG_1_KEY = "long1";
-  private static final String LAT_2_KEY = "lat2";
-  private static final String LONG_2_KEY = "long2";
-  private static final String CALCULATED_DISTANCE_KEY = "calculatedDistance";
-
-
-  @Override
-  public DataProcessorDescription declareModel() {
-    return ProcessingElementBuilder.create("org.apache.streampipes.processors.geo.jvm.processor.distancecalculator")
-            .category(DataProcessorType.GEO)
-            .withAssets(Assets.DOCUMENTATION)
-            .withLocales(Locales.EN)
-            .requiredStream(StreamRequirementsBuilder
-                    .create()
-                    .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lat)
-                            , Labels.withId(LAT_1_KEY), PropertyScope.MEASUREMENT_PROPERTY)
-                    .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lng)
-                            , Labels.withId(LONG_1_KEY), PropertyScope.MEASUREMENT_PROPERTY)
-                    .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lat)
-                            , Labels.withId(LAT_2_KEY), PropertyScope.MEASUREMENT_PROPERTY)
-                    .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lng)
-                            , Labels.withId(LONG_2_KEY), PropertyScope.MEASUREMENT_PROPERTY)
-                    .build())
-            .outputStrategy(
-                    OutputStrategies.append(EpProperties.numberEp(Labels.withId(CALCULATED_DISTANCE_KEY), "distance", SO.Number))
-            )
-            .build();
-
-  }
-
-  @Override
-  public ConfiguredEventProcessor<DistanceCalculatorParameters> onInvocation
-          (DataProcessorInvocation sepa, ProcessingElementParameterExtractor extractor) {
-
-    String lat1PropertyName = extractor.mappingPropertyValue(LAT_1_KEY);
-    String long11PropertyName = extractor.mappingPropertyValue(LONG_1_KEY);
-    String lat2PropertyName = extractor.mappingPropertyValue(LAT_2_KEY);
-    String long2PropertyName = extractor.mappingPropertyValue(LONG_2_KEY);
-
-    DistanceCalculatorParameters staticParam = new DistanceCalculatorParameters(sepa, lat1PropertyName, long11PropertyName, lat2PropertyName, long2PropertyName);
-
-    return new ConfiguredEventProcessor<>(staticParam, DistanceCalculator::new);
-  }
-}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorParameters.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorParameters.java
deleted file mode 100644
index a4ecdd485..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculatorParameters.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.processor.distancecalculator;
-
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import org.apache.streampipes.wrapper.params.binding.EventProcessorBindingParams;
-
-public class DistanceCalculatorParameters extends EventProcessorBindingParams {
-
-  public String lat1PropertyName;
-  public String long1PropertyName;
-  public String lat2PropertyName;
-  public String long2PropertyName;
-
-  public DistanceCalculatorParameters(DataProcessorInvocation graph) {
-    super(graph);
-  }
-
-  public DistanceCalculatorParameters(DataProcessorInvocation graph, String lat1PropertyName, String long1PropertyName, String lat2PropertyName, String long2PropertyName) {
-    super(graph);
-    this.lat1PropertyName = lat1PropertyName;
-    this.long1PropertyName = long1PropertyName;
-    this.lat2PropertyName = lat2PropertyName;
-    this.long2PropertyName = long2PropertyName;
-  }
-
-
-  public String getLat1PropertyName() {
-    return lat1PropertyName;
-  }
-
-  public String getLong1PropertyName() {
-    return long1PropertyName;
-  }
-
-  public String getLat2PropertyName() {
-    return lat2PropertyName;
-  }
-
-  public String getLong2PropertyName() {
-    return long2PropertyName;
-  }
-}


[streampipes] 11/11: [STREAMPIPES-642] remove old geocoder classes

Posted by mi...@apache.org.
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 4d8422248cb9724649e7d8d8b081f0d5eb0f5653
Author: micklich <mi...@apache.org>
AuthorDate: Wed Nov 30 12:44:11 2022 +0100

    [STREAMPIPES-642] remove old geocoder classes
---
 .../processor/geocoder/GoogleMapsGeocoding.java    | 82 ----------------------
 .../geocoder/GoogleMapsGeocodingController.java    | 69 ------------------
 .../geocoder/GoogleMapsGeocodingParameters.java    | 36 ----------
 3 files changed, 187 deletions(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocoding.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocoding.java
deleted file mode 100644
index 5ff4cabf1..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocoding.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.processor.geocoder;
-
-import com.google.maps.GeoApiContext;
-import com.google.maps.GeocodingApi;
-import com.google.maps.errors.ApiException;
-import com.google.maps.model.GeocodingResult;
-import org.apache.streampipes.commons.exceptions.SpRuntimeException;
-import org.apache.streampipes.model.runtime.Event;
-import org.apache.streampipes.processors.geo.jvm.config.ConfigKeys;
-import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
-import org.apache.streampipes.wrapper.routing.SpOutputCollector;
-import org.apache.streampipes.wrapper.runtime.EventProcessor;
-
-import java.io.IOException;
-
-public class GoogleMapsGeocoding implements EventProcessor<GoogleMapsGeocodingParameters> {
-
-  private GeoApiContext context;
-  private String placeField;
-
-  @Override
-  public void onInvocation(GoogleMapsGeocodingParameters parameters, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
-    this.placeField = parameters.getPlaceField();
-    String googleMapsApiKey = runtimeContext.getConfigStore().getConfig().getString(ConfigKeys.GOOGLE_API_KEY);
-
-    if (googleMapsApiKey == null || googleMapsApiKey.equals("")) {
-      throw new SpRuntimeException("Could not start Geocoder. Did you forget to add a Google Maps" +
-              " API key?");
-    }
-
-    this.context = new GeoApiContext.Builder()
-            .apiKey(googleMapsApiKey)
-            .build();
-  }
-
-  @Override
-  public void onEvent(Event event, SpOutputCollector collector) throws SpRuntimeException {
-    String placename = event.getFieldBySelector(placeField).getAsPrimitive().getAsString();
-
-    try {
-      GeocodingResult[] results =  GeocodingApi.geocode(context,
-              placename).await();
-
-      Double latitude = results[0].geometry.location.lat;
-      Double longitude = results[0].geometry.location.lng;
-
-      event.addField("latitude", latitude);
-      event.addField("longitude", longitude);
-
-      collector.collect(event);
-
-    } catch (ApiException | InterruptedException | IOException e) {
-      e.printStackTrace();
-      throw new SpRuntimeException("Could not fetch geocoding result");
-    }
-
-
-
-  }
-
-  @Override
-  public void onDetach() throws SpRuntimeException {
-
-  }
-}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingController.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingController.java
deleted file mode 100644
index dd50c77d9..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingController.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.processor.geocoder;
-
-import org.apache.streampipes.model.DataProcessorType;
-import org.apache.streampipes.model.graph.DataProcessorDescription;
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import org.apache.streampipes.model.schema.PropertyScope;
-import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
-import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
-import org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
-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.OutputStrategies;
-import org.apache.streampipes.sdk.utils.Assets;
-import org.apache.streampipes.vocabulary.Geo;
-import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
-import org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
-
-public class GoogleMapsGeocodingController extends StandaloneEventProcessingDeclarer<GoogleMapsGeocodingParameters> {
-
-  private static final String PLACE_MAPPING = "place-mapping";
-
-  @Override
-  public DataProcessorDescription declareModel() {
-    return ProcessingElementBuilder.create("org.apache.streampipes.processor.geo.jvm.geocoding")
-            .category(DataProcessorType.GEO)
-            .withAssets(Assets.DOCUMENTATION)
-            .withLocales(Locales.EN)
-            .requiredStream(StreamRequirementsBuilder
-                    .create()
-                    .requiredPropertyWithUnaryMapping(EpRequirements.stringReq(),
-                            Labels.withId(PLACE_MAPPING),
-                            PropertyScope.NONE)
-                    .build())
-            .outputStrategy(OutputStrategies.append(
-                    EpProperties.doubleEp(Labels.empty(), "latitude", Geo.lat),
-                    EpProperties.stringEp(Labels.empty(), "longitude", Geo.lng)
-            ))
-            .build();
-  }
-
-  @Override
-  public ConfiguredEventProcessor<GoogleMapsGeocodingParameters> onInvocation(DataProcessorInvocation graph,
-                                                                              ProcessingElementParameterExtractor extractor) {
-    String placeField = extractor.mappingPropertyValue(PLACE_MAPPING);
-
-    GoogleMapsGeocodingParameters params = new GoogleMapsGeocodingParameters(graph, placeField);
-
-    return new ConfiguredEventProcessor<>(params, GoogleMapsGeocoding::new);
-  }
-}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingParameters.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingParameters.java
deleted file mode 100644
index 8ad424999..000000000
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/geocoder/GoogleMapsGeocodingParameters.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.processor.geocoder;
-
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import org.apache.streampipes.wrapper.params.binding.EventProcessorBindingParams;
-
-public class GoogleMapsGeocodingParameters extends EventProcessorBindingParams {
-
-  private String placeField;
-
-  public GoogleMapsGeocodingParameters(DataProcessorInvocation graph,
-                                       String placeField) {
-    super(graph);
-    this.placeField = placeField;
-  }
-
-  public String getPlaceField() {
-    return placeField;
-  }
-}


[streampipes] 03/11: [STREAMPIPES-642] stylecheck

Posted by mi...@apache.org.
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 8c11fdc876a914911980e4dde18e084f4471b294
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 10:26:51 2022 +0100

    [STREAMPIPES-642]  stylecheck
---
 .../jvm/latlong/helper/HaversineDistanceUtil.java  | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java
index e7848c9ac..2bc07291d 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/helper/HaversineDistanceUtil.java
@@ -18,17 +18,17 @@ package org.apache.streampipes.processors.geo.jvm.latlong.helper;
 
 public class HaversineDistanceUtil {
 
-  public static float dist(float lat1, float lng1, float lat2, float lng2) {
-    double earthRadius = 6371000; //meters
-    double dLat = Math.toRadians(lat2-lat1);
-    double dLng = Math.toRadians(lng2-lng1);
-    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
-            Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
-                    Math.sin(dLng/2) * Math.sin(dLng/2);
-    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
-    float dist = (float) (earthRadius * c);
+    public static float dist(float lat1, float lng1, float lat2, float lng2) {
+        double earthRadius = 6371000; //meters
+        double dLat = Math.toRadians(lat2 - lat1);
+        double dLng = Math.toRadians(lng2 - lng1);
+        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+                + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2)
+                * Math.sin(dLng / 2);
+        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
+        float dist = (float) (earthRadius * c);
 
-    return dist / 1000;
-  }
+        return dist / 1000;
+    }
 
 }


[streampipes] 06/11: [STREAMPIPES-642] adjust misc format

Posted by mi...@apache.org.
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 d520d8ef15c0ca3cdffbaf36f29b526a009e4e9c
Author: micklich <mi...@apache.org>
AuthorDate: Tue Nov 29 16:32:39 2022 +0100

    [STREAMPIPES-642] adjust misc format
---
 .../distancecalculator/DistanceCalculatorProcessor.java      | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
index 0b5e8e73b..b3424cb53 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/latlong/processor/distancecalculator/DistanceCalculatorProcessor.java
@@ -65,9 +65,15 @@ public class DistanceCalculatorProcessor extends StreamPipesDataProcessor {
                         .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lat),
                                 Labels.withId(LAT_2_KEY), PropertyScope.MEASUREMENT_PROPERTY)
                         .requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq(Geo.lng),
-                                Labels.withId(LONG_2_KEY), PropertyScope.MEASUREMENT_PROPERTY).build()).outputStrategy(
-                        OutputStrategies.append(
-                                EpProperties.numberEp(Labels.withId(CALCULATED_DISTANCE_KEY), "distance", SO.Number)))
+                                Labels.withId(LONG_2_KEY), PropertyScope.MEASUREMENT_PROPERTY)
+                        .build()
+                )
+                .outputStrategy(OutputStrategies
+                        .append(EpProperties.numberEp(
+                                Labels.withId(CALCULATED_DISTANCE_KEY),
+                                "distance",
+                                SO.Number))
+                )
                 .build();
     }