From c5b095f2df78f47d9396f278a5e26e8660a7f13d Mon Sep 17 00:00:00 2001
From: alexrodriguez <alejandro.rodriguez@tecnalia.com>
Date: Wed, 7 Dec 2022 12:05:59 +0100
Subject: [PATCH] Fix bug with latitude & longitude, Changing "MultiPolygon"
 for "LineString"

---
 .../urbanite/anonymize/service/AnonymizerService.java  |  6 ++++++
 .../tecnalia/urbanite/anonymize/utils/DataUtils.java   | 10 +++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java b/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java
index 1c194a8..7e14b62 100644
--- a/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java
+++ b/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java
@@ -103,7 +103,13 @@ public class AnonymizerService {
 							puntos.add(DataUtils.getGpsPointFromVehiclePoint(vehiclePoints.getJSONObject(ipoint)));
 						}
 					}
+					if (route == null || route.getNodes().isEmpty()) {
+						continue;
+					}
 					DivideInTraysCover ditc = new DivideInTraysCover(route);
+					if (ditc == null || ditc.doFindingTrays().isEmpty()) {
+						continue;
+					}
 					ArrayList<GPSRoute> rutasAntesdeAnonimizar = ditc.doFindingTrays();
 					int borrados = 0;
 					//int b=0;
diff --git a/src/main/java/com/tecnalia/urbanite/anonymize/utils/DataUtils.java b/src/main/java/com/tecnalia/urbanite/anonymize/utils/DataUtils.java
index a7ea1a8..9719570 100644
--- a/src/main/java/com/tecnalia/urbanite/anonymize/utils/DataUtils.java
+++ b/src/main/java/com/tecnalia/urbanite/anonymize/utils/DataUtils.java
@@ -64,8 +64,8 @@ public class DataUtils {
         	return null;            
         }			
         Long time =    dateTime.toEpochSecond() *1000;         
-    	double lon  = vehicle.getJSONObject("location").getJSONArray("coordinates").getDouble(0);
-        double lat =vehicle.getJSONObject("location").getJSONArray("coordinates").getDouble(1);
+    	double lon  = vehicle.getJSONObject("location").getJSONArray("coordinates").getDouble(1);
+        double lat =vehicle.getJSONObject("location").getJSONArray("coordinates").getDouble(0);
         double speed = vehicle.getDouble("speed");
         GPSPoint p =new GPSPoint(time,lat,lon,speed);
         p.setTime(dateTime.toEpochSecond());
@@ -176,7 +176,7 @@ public class DataUtils {
         trozos.add(poligons);
         coordinates.add(trozos);
         location.set("coordinates",coordinates);
-        location.put("type","MultiPolygon");
+        location.put("type","LineString");
         node.set("location",location);
 		
 		return node;
@@ -228,10 +228,10 @@ public class DataUtils {
 	            return output;
 
 	        } catch (Exception e) {
-	            System.err.println("Error in storeTrafficFlow model= " + model+" "+e.getMessage());// + " \njsonInput " + jsonInput);
+	            System.err.println("Error in storeDataFlow model= " + model+" "+e.getMessage());// + " \njsonInput " + jsonInput);
 	            System.err.println(e.getMessage());
 	            //System.exit(0);
-	            return "Error in storeTrafficFlow model= " + model+" "+e.getMessage();
+	            return "Error in storeDataFlow model= " + model+" "+e.getMessage();
 
 	        }
 	        finally {
-- 
GitLab