This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit e4c75280980321b0a9e7981cc4fe7bf9f95ac828 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Aug 1 17:15:45 2016 +0200 Revue du code relatif au gps et suppression du code en double (entités vs service model) --- .../swing/decoration/DecoratorService.java | 6 +- .../ActivitySimpleSpeedDtoValidator.java | 9 +- .../validators/ActivitySpeedDtoValidator.java | 9 +- .../observe/ObserveSwingApplicationContext.java | 7 +- observe-entities-migration/pom.xml | 4 + observe-entities/pom.xml | 4 - .../observe/entities}/gps/CoordinateHelper.java | 2 +- .../java/fr/ird/observe/entities/gps/GPSPoint.java | 120 ------- .../fr/ird/observe/entities/gps/GPSPointImpl.java | 79 ----- .../ird/observe/entities/gps/GPSPointInterval.java | 155 --------- .../observe/entities/gps/GPSPointIntervalImpl.java | 84 ----- .../java/fr/ird/observe/entities/gps/GPSRoute.java | 276 ---------------- .../fr/ird/observe/entities/gps/GPSRouteImpl.java | 144 --------- .../fr/ird/observe/entities/gps/GpsPoints.java | 177 ---------- .../entities/longline/ActivityLonglineImpl.java | 2 +- .../observe/entities/longline/SetLonglineImpl.java | 2 +- .../observe/entities/referentiel/HarbourImpl.java | 2 +- .../observe/entities/seine/ActivitySeineImpl.java | 2 +- .../main/java/fr/ird/type/CoordinateHelper.java | 55 ---- .../util/{gps/GpsPoints.java => GPSPoint.java} | 137 +++++--- .../main/java/fr/ird/observe/util/gps/GPSAble.java | 59 ---- .../fr/ird/observe/util/gps/GPSFileReader.java | 356 --------------------- .../java/fr/ird/observe/util/gps/GPSPoint.java | 118 ------- .../java/fr/ird/observe/util/gps/GPSPointImpl.java | 76 ----- .../fr/ird/observe/util/gps/GPSPointInterval.java | 155 --------- .../ird/observe/util/gps/GPSPointIntervalImpl.java | 86 ----- .../java/fr/ird/observe/util/gps/GPSRoute.java | 276 ---------------- .../java/fr/ird/observe/util/gps/GPSRouteImpl.java | 144 --------- .../java/fr/ird/observe/util/gps/GPSService.java | 115 ------- observe-services-topia-validation/pom.xml | 5 + .../validators/ActivitySimpleSpeedValidator.java | 9 +- .../validators/ActivitySpeedValidator.java | 9 +- .../longline/ActivityLonglineServiceTopia.java | 2 +- .../service/seine/ActivitySeineServiceTopia.java | 2 +- 34 files changed, 128 insertions(+), 2560 deletions(-) diff --git a/observe-application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java b/observe-application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java index 0e4c0a6..a349c6c 100644 --- a/observe-application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java +++ b/observe-application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java @@ -121,8 +121,7 @@ import fr.ird.observe.services.dto.seine.SetSeineDto; import fr.ird.observe.services.dto.seine.TargetLengthDto; import fr.ird.observe.services.dto.seine.TransmittingBuoyDto; import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.util.gps.GPSPoint; -import fr.ird.observe.util.gps.GPSPointInterval; +import fr.ird.observe.util.GPSPoint; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -584,9 +583,6 @@ public class DecoratorService extends DecoratorProvider { registerObserveDecorator("gpsPoint-gps", GPSPoint.class, t("observe.common.gps.gpsPoint")); - registerObserveDecorator(GPSPointInterval.class, - "gpsPointInterval-gps", - t("observe.common.gps.gpsPointInterval")); registerObserveDecorator(GPSPoint.class, "${time}$td/%1$tm/%1$tY %1$tH:%1$tM##${latitude}$s##${longitude}$s", diff --git a/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySimpleSpeedDtoValidator.java b/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySimpleSpeedDtoValidator.java index 4b6367d..73c8aee 100644 --- a/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySimpleSpeedDtoValidator.java +++ b/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySimpleSpeedDtoValidator.java @@ -28,8 +28,7 @@ import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.services.dto.seine.ActivitySeineDto; import fr.ird.observe.services.dto.seine.ActivitySeineStubDto; import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.util.gps.GPSPoint; -import fr.ird.observe.util.gps.GpsPoints; +import fr.ird.observe.util.GPSPoint; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -140,10 +139,10 @@ public class ActivitySimpleSpeedDtoValidator extends FieldValidatorSupport { return; } - GPSPoint currentPoint = GpsPoints.newPoint(route, activity); - GPSPoint previousPoint = GpsPoints.newPoint(route, previousActivity); + GPSPoint currentPoint = GPSPoint.newPoint(route, activity); + GPSPoint previousPoint = GPSPoint.newPoint(route, previousActivity); - float computedSpeed = GpsPoints.getSpeed(previousPoint, currentPoint); + float computedSpeed = previousPoint.getSpeed(currentPoint); if (log.isDebugEnabled()) { log.debug("Speed computed between previous activity point " + decorate(previousPoint) + " to current activity point " + decorate(currentPoint) + ", speed is : " + computedSpeed); diff --git a/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySpeedDtoValidator.java b/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySpeedDtoValidator.java index 0864aaa..269ab28 100644 --- a/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySpeedDtoValidator.java +++ b/observe-application-swing-validation/src/main/java/fr/ird/observe/application/swing/validation/validators/ActivitySpeedDtoValidator.java @@ -27,8 +27,7 @@ import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.services.dto.seine.ActivitySeineStubDto; import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.util.gps.GPSPoint; -import fr.ird.observe.util.gps.GpsPoints; +import fr.ird.observe.util.GPSPoint; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.xwork2.field.CollectionFieldExpressionValidator; @@ -137,10 +136,10 @@ public class ActivitySpeedDtoValidator extends FieldValidatorSupport { return true; } - GPSPoint previousPoint = GpsPoints.newPoint(route, previousActivity); - GPSPoint currentPoint = GpsPoints.newPoint(route, currentActivity); + GPSPoint previousPoint = GPSPoint.newPoint(route, previousActivity); + GPSPoint currentPoint = GPSPoint.newPoint(route, currentActivity); - float computedSpeed = GpsPoints.getSpeed(previousPoint, currentPoint); + float computedSpeed = previousPoint.getSpeed(currentPoint); if (LOG.isDebugEnabled()) { LOG.debug("Speed computed between previous activity point " + decorate(previousPoint) + " to current activity point " + decorate(currentPoint) + ", speed is : " + computedSpeed); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java b/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java index daad9ff..739a591 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java @@ -24,6 +24,7 @@ package fr.ird.observe; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.ObserveSwingDataSource; @@ -55,7 +56,6 @@ import fr.ird.observe.services.service.seine.FloatingObjectService; import fr.ird.observe.services.service.seine.RouteService; import fr.ird.observe.services.service.seine.SetSeineService; import fr.ird.observe.services.service.seine.TripSeineService; -import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.ObserveMainUIHandler; import fr.ird.observe.ui.ObserveUIMode; @@ -81,7 +81,6 @@ import fr.ird.observe.ui.actions.shared.SelectNodeUIAction; import fr.ird.observe.ui.actions.shared.SelectOpenNodeUIAction; import fr.ird.observe.ui.content.ContentUI; import fr.ird.observe.ui.tree.ObserveTreeHelper; -import fr.ird.observe.util.gps.GPSService; import fr.ird.observe.validation.ObserveSwingValidator; import fr.ird.observe.validation.ValidationContext; import jaxx.runtime.JAXXUtil; @@ -166,10 +165,6 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im public static final JAXXContextEntryDef<ObserveSwingBinderService> BINDER_SERVICE_ENTRY_DEF = JAXXUtil.newContextEntryDef(ObserveSwingBinderService.class); - /** the jaxx context entry to store the gps service */ - public static final JAXXContextEntryDef<GPSService> GPS_SERVICE_ENTRY_DEF = - JAXXUtil.newContextEntryDef(GPSService.class); - /** the jaxx context entry to store the data service */ public static final JAXXContextEntryDef<DataContext> DATA_CONTEXT_ENTRY_DEF = JAXXUtil.newContextEntryDef(DataContext.class); diff --git a/observe-entities-migration/pom.xml b/observe-entities-migration/pom.xml index 503330d..6bf68d1 100644 --- a/observe-entities-migration/pom.xml +++ b/observe-entities-migration/pom.xml @@ -61,6 +61,10 @@ <artifactId>commons-logging</artifactId> </dependency> <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> diff --git a/observe-entities/pom.xml b/observe-entities/pom.xml index c0eefb2..37514f9 100644 --- a/observe-entities/pom.xml +++ b/observe-entities/pom.xml @@ -69,10 +69,6 @@ <artifactId>commons-logging</artifactId> </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/CoordinateHelper.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/CoordinateHelper.java similarity index 97% rename from observe-services-model/src/main/java/fr/ird/observe/util/gps/CoordinateHelper.java rename to observe-entities/src/main/java/fr/ird/observe/entities/gps/CoordinateHelper.java index 10be892..7bd7c46 100644 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/CoordinateHelper.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/gps/CoordinateHelper.java @@ -19,7 +19,7 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -package fr.ird.observe.util.gps; +package fr.ird.observe.entities.gps; /** * Helper to deal with coordinates. diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPoint.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPoint.java deleted file mode 100644 index 47cd525..0000000 --- a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPoint.java +++ /dev/null @@ -1,120 +0,0 @@ -package fr.ird.observe.entities.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.entities.GPSAble; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.Date; - -public abstract class GPSPoint implements GPSAble, Serializable { - - private static final long serialVersionUID = 3761972876361753443L; - - public static final String PROPERTY_LATITUDE = "latitude"; - - public static final String PROPERTY_LONGITUDE = "longitude"; - - public static final String PROPERTY_VITESSE = "vitesse"; - - public static final String PROPERTY_TIME = "time"; - - protected Float latitude; - - protected Float longitude; - - protected Float vitesse; - - protected Date time; - - protected final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public Float getLatitude() { - return latitude; - } - - public void setLatitude(Float latitude) { - Float oldValue = getLatitude(); - this.latitude = latitude; - firePropertyChange(PROPERTY_LATITUDE, oldValue, latitude); - } - - public Float getLongitude() { - return longitude; - } - - public void setLongitude(Float longitude) { - Float oldValue = getLongitude(); - this.longitude = longitude; - firePropertyChange(PROPERTY_LONGITUDE, oldValue, longitude); - } - - public Float getVitesse() { - return vitesse; - } - - public void setVitesse(Float vitesse) { - Float oldValue = getVitesse(); - this.vitesse = vitesse; - firePropertyChange(PROPERTY_VITESSE, oldValue, vitesse); - } - - public Date getTime() { - return time; - } - - public void setTime(Date time) { - Date oldValue = getTime(); - this.time = time; - firePropertyChange(PROPERTY_TIME, oldValue, time); - } - - public abstract boolean isSameLocation(GPSPoint point); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - - protected void firePropertyChange(String propertyName, Object newValue) { - firePropertyChange(propertyName, null, newValue); - } - -} //GPSPoint diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointImpl.java deleted file mode 100644 index 1bd45a4..0000000 --- a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.entities.gps; - -import fr.ird.observe.entities.GPSAble; -import fr.ird.type.CoordinateHelper; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.0 - */ -public class GPSPointImpl extends GPSPoint { - - private static final long serialVersionUID = 1L; - - public GPSPointImpl() { - } - - public GPSPointImpl(GPSAble activity) { - setLongitude(activity.getLongitude()); - setLatitude(activity.getLatitude()); - setTime(activity.getTime()); - } - - @Override - public Integer getQuadrant() { - Integer result = CoordinateHelper.getQuadrant(longitude, latitude); - return result; -// if (latitude == null || longitude == null) { -// return null; -// } -// int result; -// -// if (latitude > 0) { -// result = longitude > 0 ? 1 : 4; -//// result = longitude > 0 ? 1 : 3; -// } else { -// result = longitude > 0 ? 2 : 3; -//// result = longitude > 0 ? 1 : 3; -// } -// return result; - } - - @Override - public void setQuadrant(Integer quadrant) { - // non utilisé - } - - @Override - public boolean isSameLocation(GPSPoint point) { - float latitude = getLatitude() == null ? 0f : getLatitude(); - float longitude = getLongitude() == null ? 0f : getLongitude(); - - float latitude1 = point.getLatitude() == null ? 0f : point.getLatitude(); - float longitude1 = point.getLongitude() == null ? 0f : point.getLongitude(); - - return latitude == latitude1 && longitude == longitude1; - } - -} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointInterval.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointInterval.java deleted file mode 100644 index e6e6529..0000000 --- a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointInterval.java +++ /dev/null @@ -1,155 +0,0 @@ -package fr.ird.observe.entities.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - -public abstract class GPSPointInterval implements Serializable { - - private static final long serialVersionUID = 7377852988997002340L; - - public static final String PROPERTY_POINT = "point"; - - protected List<GPSPoint> point; - - protected final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public GPSPoint getPoint(int index) { - GPSPoint o = getChild(point, index); - return o; - } - - public boolean isPointEmpty() { - return point == null || point.isEmpty(); - } - - public int sizePoint() { - return point == null ? 0 : point.size(); - } - - public void addPoint(GPSPoint point) { - getPoint().add(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public void addAllPoint(Collection<GPSPoint> point) { - getPoint().addAll(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public boolean removePoint(GPSPoint point) { - boolean removed = getPoint().remove(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean removeAllPoint(Collection<GPSPoint> point) { - boolean removed = getPoint().removeAll(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean containsPoint(GPSPoint point) { - boolean contains = getPoint().contains(point); - return contains; - } - - public boolean containsAllPoint(Collection<GPSPoint> point) { - boolean contains = getPoint().containsAll(point); - return contains; - } - - public List<GPSPoint> getPoint() { - return point; - } - - public void setPoint(List<GPSPoint> point) { - List<GPSPoint> oldValue = getPoint(); - this.point = point; - firePropertyChange(PROPERTY_POINT, oldValue, point); - } - - public abstract GPSPoint getFirstPoint(); - - public abstract GPSPoint getLastPoint(); - - public abstract long getDateMin(); - - public abstract long getDateMax(); - - public abstract int getPointSize(); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - - protected void firePropertyChange(String propertyName, Object newValue) { - firePropertyChange(propertyName, null, newValue); - } - - protected <T> T getChild(Collection<T> childs, int index) { - T result = null; - if (childs != null) { - if (childs instanceof List) { - if (index < childs.size()) { - result = ((List<T>) childs).get(index); - } - } else { - int i = 0; - for (T o : childs) { - if (index == i) { - result = o; - break; - } - i++; - } - } - } - return result; - } - -} //GPSPointInterval diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointIntervalImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointIntervalImpl.java deleted file mode 100644 index ed3790f..0000000 --- a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSPointIntervalImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.entities.gps; - -import java.util.Date; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.0 - */ -public class GPSPointIntervalImpl extends GPSPointInterval { - - private static final long serialVersionUID = 1L; - - @Override - public GPSPoint getFirstPoint() { - if (getPoint() == null) { - return null; - } - GPSPoint p = getPoint(0); - return p; - } - - @Override - public GPSPoint getLastPoint() { - if (getPoint() == null) { - return null; - } - GPSPoint p = getPoint(getPoint().size() - 1); - return p; - } - - @Override - public long getDateMin() { - GPSPoint p = getFirstPoint(); - if (p == null) { - throw new NullPointerException("Pas de premier point definie dans l'intervalle " + this); - } - return p.getTime().getTime(); - } - - @Override - public long getDateMax() { - GPSPoint p = getLastPoint(); - if (p == null) { - throw new NullPointerException("Pas de dernier point definie dans l'intervalle " + this); - } - return p.getTime().getTime(); - } - - @Override - public int getPointSize() { - return point == null ? 0 : point.size(); - } - - @Override - public String toString() { - String l; -// if (getPoint() == null || getFirstPoint() == null || getLastPoint() == null) { -// l = super.toString(); -// } - l = String.format("Intervalle %1$td/%1$tm/%1$tY %1$tH\\:%1$tM\\:%1$tS - %2$td/%2$tm/%2$tY %2$tH\\:%2$tM\\:%2$tM ( nombre de point(s) \\: %3$s )", new Date(getDateMin()), new Date(getDateMax()), getPoint().size()); - return l; - } -} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSRoute.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSRoute.java deleted file mode 100644 index 11aace9..0000000 --- a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSRoute.java +++ /dev/null @@ -1,276 +0,0 @@ -package fr.ird.observe.entities.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.Collection; -import java.util.Date; -import java.util.List; - -public abstract class GPSRoute implements Serializable { - - private static final long serialVersionUID = 3702862907863819874L; - - public static final String PROPERTY_POINT = "point"; - - public static final String PROPERTY_ACCEPTED_INTERVAL = "acceptedInterval"; - - public static final String PROPERTY_REJECTED_INTERVAL = "rejectedInterval"; - - protected List<GPSPoint> point; - - protected List<GPSPointInterval> acceptedInterval; - - protected List<GPSPointInterval> rejectedInterval; - - protected final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public GPSPoint getPoint(int index) { - GPSPoint o = getChild(point, index); - return o; - } - - public boolean isPointEmpty() { - return point == null || point.isEmpty(); - } - - public int sizePoint() { - return point == null ? 0 : point.size(); - } - - public void addPoint(GPSPoint point) { - getPoint().add(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public void addAllPoint(Collection<GPSPoint> point) { - getPoint().addAll(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public boolean removePoint(GPSPoint point) { - boolean removed = getPoint().remove(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean removeAllPoint(Collection<GPSPoint> point) { - boolean removed = getPoint().removeAll(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean containsPoint(GPSPoint point) { - boolean contains = getPoint().contains(point); - return contains; - } - - public boolean containsAllPoint(Collection<GPSPoint> point) { - boolean contains = getPoint().containsAll(point); - return contains; - } - - public List<GPSPoint> getPoint() { - return point; - } - - public void setPoint(List<GPSPoint> point) { - List<GPSPoint> oldValue = getPoint(); - this.point = point; - firePropertyChange(PROPERTY_POINT, oldValue, point); - } - - public GPSPointInterval getAcceptedInterval(int index) { - GPSPointInterval o = getChild(acceptedInterval, index); - return o; - } - - public boolean isAcceptedIntervalEmpty() { - return acceptedInterval == null || acceptedInterval.isEmpty(); - } - - public int sizeAcceptedInterval() { - return acceptedInterval == null ? 0 : acceptedInterval.size(); - } - - public void addAcceptedInterval(GPSPointInterval acceptedInterval) { - getAcceptedInterval().add(acceptedInterval); - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, null, acceptedInterval); - } - - public void addAllAcceptedInterval(Collection<GPSPointInterval> acceptedInterval) { - getAcceptedInterval().addAll(acceptedInterval); - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, null, acceptedInterval); - } - - public boolean removeAcceptedInterval(GPSPointInterval acceptedInterval) { - boolean removed = getAcceptedInterval().remove(acceptedInterval); - if (removed) { - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, acceptedInterval, null); - } - return removed; - } - - public boolean removeAllAcceptedInterval(Collection<GPSPointInterval> acceptedInterval) { - boolean removed = getAcceptedInterval().removeAll(acceptedInterval); - if (removed) { - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, acceptedInterval, null); - } - return removed; - } - - public boolean containsAcceptedInterval(GPSPointInterval acceptedInterval) { - boolean contains = getAcceptedInterval().contains(acceptedInterval); - return contains; - } - - public boolean containsAllAcceptedInterval(Collection<GPSPointInterval> acceptedInterval) { - boolean contains = getAcceptedInterval().containsAll(acceptedInterval); - return contains; - } - - public List<GPSPointInterval> getAcceptedInterval() { - return acceptedInterval; - } - - public void setAcceptedInterval(List<GPSPointInterval> acceptedInterval) { - List<GPSPointInterval> oldValue = getAcceptedInterval(); - this.acceptedInterval = acceptedInterval; - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, oldValue, acceptedInterval); - } - - public GPSPointInterval getRejectedInterval(int index) { - GPSPointInterval o = getChild(rejectedInterval, index); - return o; - } - - public boolean isRejectedIntervalEmpty() { - return rejectedInterval == null || rejectedInterval.isEmpty(); - } - - public int sizeRejectedInterval() { - return rejectedInterval == null ? 0 : rejectedInterval.size(); - } - - public void addRejectedInterval(GPSPointInterval rejectedInterval) { - getRejectedInterval().add(rejectedInterval); - firePropertyChange(PROPERTY_REJECTED_INTERVAL, null, rejectedInterval); - } - - public void addAllRejectedInterval(Collection<GPSPointInterval> rejectedInterval) { - getRejectedInterval().addAll(rejectedInterval); - firePropertyChange(PROPERTY_REJECTED_INTERVAL, null, rejectedInterval); - } - - public boolean removeRejectedInterval(GPSPointInterval rejectedInterval) { - boolean removed = getRejectedInterval().remove(rejectedInterval); - if (removed) { - firePropertyChange(PROPERTY_REJECTED_INTERVAL, rejectedInterval, null); - } - return removed; - } - - public boolean removeAllRejectedInterval(Collection<GPSPointInterval> rejectedInterval) { - boolean removed = getRejectedInterval().removeAll(rejectedInterval); - if (removed) { - firePropertyChange(PROPERTY_REJECTED_INTERVAL, rejectedInterval, null); - } - return removed; - } - - public boolean containsRejectedInterval(GPSPointInterval rejectedInterval) { - boolean contains = getRejectedInterval().contains(rejectedInterval); - return contains; - } - - public boolean containsAllRejectedInterval(Collection<GPSPointInterval> rejectedInterval) { - boolean contains = getRejectedInterval().containsAll(rejectedInterval); - return contains; - } - - public List<GPSPointInterval> getRejectedInterval() { - return rejectedInterval; - } - - public void setRejectedInterval(List<GPSPointInterval> rejectedInterval) { - List<GPSPointInterval> oldValue = getRejectedInterval(); - this.rejectedInterval = rejectedInterval; - firePropertyChange(PROPERTY_REJECTED_INTERVAL, oldValue, rejectedInterval); - } - - public abstract GPSPoint getPoint(Date date); - - public abstract int getBeforePointIndex(GPSPointInterval intervalle, long date); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - - protected void firePropertyChange(String propertyName, Object newValue) { - firePropertyChange(propertyName, null, newValue); - } - - protected <T> T getChild(Collection<T> childs, int index) { - T result = null; - if (childs != null) { - if (childs instanceof List) { - if (index < childs.size()) { - result = ((List<T>) childs).get(index); - } - } else { - int i = 0; - for (T o : childs) { - if (index == i) { - result = o; - break; - } - i++; - } - } - } - return result; - } - -} //GPSRoute diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSRouteImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSRouteImpl.java deleted file mode 100644 index 73bd435..0000000 --- a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GPSRouteImpl.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.entities.gps; - -import java.util.Date; -import java.util.List; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.0 - */ -public class GPSRouteImpl extends GPSRoute { - - private static final long serialVersionUID = 1L; - - /** - * Permet de construire un point pour une date donnée. - * - * On recherche parmis les intervalles acceptables les deux points entourant - * la date donnée. - * - * Si on a réussi à trouver deux points adéquates, alors on construit un - * nouveau point en utilisant la formule d'interpolation pour calculer les - * coordonnées du point. - * - * @param date la date du point à construire - * @return le nouveau point construit ou {@code null} si on a pas - * trouvé un intervalle de points acdeptables pour la date donnée. - */ - @Override - public GPSPoint getPoint(Date date) { - if (date == null) { - throw new NullPointerException("la date ne peut pas être nulle!"); - } - long tx = date.getTime(); - GPSPoint newPoint = null; - List<GPSPointInterval> intervalles = getAcceptedInterval(); - if (intervalles != null && !intervalles.isEmpty()) { - for (GPSPointInterval intervalle : intervalles) { - int index = getBeforePointIndex(intervalle, tx); - if (index == -1) { - // l'intervalle n'accepte pas la date donnée - continue; - } - // l'intervalle courant est acceptable pour la date donnée - GPSPoint p0 = intervalle.getPoint(index); - GPSPoint p1 = intervalle.getPoint(index + 1); - - //FIXME on devrait peut-être arrondir aux secondes ? - if (p0.getTime().getTime() == tx) { - newPoint = p0; - break; - } - //FIXME on devrait peut-être arrondir aux secondes ? - if (p1.getTime().getTime() == tx) { - newPoint = p1; - break; - } - // on calcule la position du nouveau point - // via la formule d'interpolation - newPoint = newPoint(p0, p1, date); - // on quitte car le point a été trouvé - break; - } - } - return newPoint; - - } - - /** - * Trouve l'index du point juste avant la date donnée (et donc le point - * suivant est après la date donnée). - * - * @param intervalle l'intervalle de points à parcourir - * @param date la date donnée - * @return l'index du point trouvé ou {@code -1} si pas de point - * adéquate trouvé. - */ - @Override - public int getBeforePointIndex(GPSPointInterval intervalle, long date) { - - int result = -1; - long min = intervalle.getDateMin(); - long max = intervalle.getDateMax(); - if (min <= date || date <= max) { - // cet intervalle est pas acceptable pour la date donnée - if (date == min) { - return 0; - } - if (date == max) { - return intervalle.getPoint().size() - 1; - } - List<GPSPoint> points = intervalle.getPoint(); - for (int i = 0, j = points.size(); i < j; i++) { - GPSPoint beforePoint = points.get(i); - long d = beforePoint.getTime().getTime(); - if (d > date) { - // on a trouvé le premier point juste après la date donnée - // on peut s'arreter là - result = i - 1; - break; - } - } - } - return result; - } - - protected GPSPoint newPoint(GPSPoint p0, GPSPoint p1, Date d) { - GPSPoint p = new GPSPointImpl(); - p.setTime(d); - long tx = d.getTime(); - long t0 = p0.getTime().getTime(); - long t1 = p1.getTime().getTime(); - float latitudeX = getInterpolation(t0, t1, tx, p0.getLatitude(), p1.getLatitude()); - float longitudeX = getInterpolation(t0, t1, tx, p0.getLongitude(), p1.getLongitude()); - p.setLongitude(longitudeX); - p.setLatitude(latitudeX); - return p; - } - - protected float getInterpolation(long t0, long t1, long tx, float x0, float x1) { - float result = (tx - t0 - (t1 - t0)) * (x1 - x0) + x0; - return result; - } -} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GpsPoints.java b/observe-entities/src/main/java/fr/ird/observe/entities/gps/GpsPoints.java deleted file mode 100644 index cca4455..0000000 --- a/observe-entities/src/main/java/fr/ird/observe/entities/gps/GpsPoints.java +++ /dev/null @@ -1,177 +0,0 @@ -package fr.ird.observe.entities.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.Route; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.DateUtil; - -import java.util.Date; - -/** - * Created on 8/25/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.7 - */ -public class GpsPoints { - - /** Logger. */ - private static final Log log = LogFactory.getLog(GpsPoints.class); - - public static final double MILE_TO_KM = 1.852; - - public static final double EARTH_RADIUS = 3958.75; - - /** le rayon de la terre en kilomètres */ - public static final int R = 6378; - - - /** - * Construit un point à partir de l'entité donnée. - * - * @param route la route qui contient le jour - * @param activity l'activite qui contient l'heure et la position géographique - * @return le nouveau point instancié - * @since 3.8 - */ - public static GPSPoint newPoint(Route route, ActivitySeine activity) { - - Date currentTime = DateUtil.getDateAndTime(route.getDate(), activity.getTime(), false, false); - - GPSPoint gpsPoint = new GPSPointImpl(); - gpsPoint.setTime(currentTime); - gpsPoint.setLatitude(activity.getLatitude()); - gpsPoint.setLongitude(activity.getLongitude()); - - return gpsPoint; - - } - - - /** - * Calcule la distance entre deux points (en kilometres). - * - * Il s'agit d'une approxiation utilisant la méthode d'orthodromie. - * - * http://fr.wikipedia.org/wiki/Orthodromie - * - * d = R * arccos(cos(lat1) * cos(lat2) *cos(long2 - long1) + sin(lat1) - * *sin(lat2)) - * - * @param p0 le premier point - * @param p1 le second point - * @return la distance calculée entre les deux points en kilometres. - */ - public static double getDistanceInKm(GPSPoint p0, GPSPoint p1) { - double d = getDistanceInMile(p0, p1) * MILE_TO_KM; - return d; - } - - /** - * Calcule la distance entre deux points (en miles nautique). - * - * Il s'agit d'une approxiation utilisant la méthode d'orthodromie. - * - * http://fr.wikipedia.org/wiki/Orthodromie - * - * d = R * arccos(cos(lat1) * cos(lat2) *cos(long2 - long1) + sin(lat1) - * *sin(lat2)) - * - * @param p0 le premier point - * @param p1 le second point - * @return la distance calculée entre les deux points en noeud. - */ - - public static double getDistanceInMile(GPSPoint p0, GPSPoint p1) { - double d; - if (p0.isSameLocation(p1)) { - - // same location : so distance is null for sure - // We use this limit case, otherwise in next computation, tmp - // value can be more than 1 (1.00000000002) and Math.acos(tmp) - // then is NaN - d = 0d; - } else { - double lat1 = p0.getLatitude(); - double lng1 = p0.getLongitude(); - - double lat2 = p1.getLatitude(); - double lng2 = p1.getLongitude(); - -// double earthRadius = 3958.75; - double dLat = Math.toRadians(lat2 - lat1); - double dLng = Math.toRadians(lng2 - lng1); - double sindLat = Math.sin(dLat / 2); - double sindLng = Math.sin(dLng / 2); - double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) - * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); - double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - d = EARTH_RADIUS * c; - } - return d; - } - - /** - * Calcule la vitesse entre deux points (en noeud). - * - * @param p0 le premier point - * @param p1 le second point - * @return la vitesse calculée entre les deux points en noeud. - */ - public static float getSpeed(GPSPoint p0, GPSPoint p1) { - - if (p0.getTime().after(p1.getTime())) { - - if (log.isWarnEnabled()) { - log.warn("Le point " + p0 + " est chronologiquement après le point " + p1 + " impossible de calculer une vitesse."); - } - return 0; - - } - - // la distance en miles nautique - double d = getDistanceInMile(p0, p1); - // le temps en heure - float delay = (float) getDelay(p0, p1) / (1000 * 60 * 60); - // la vitesse en noeud - double speed = d / delay; - return (float) speed; - } - - /** - * Calcule le temps écoulé entre deux points (en millisecondes). - * - * @param p0 le premier point - * @param p1 le second point - * @return le temps écoulé entre les deux points en millisecondes. - */ - public static long getDelay(GPSPoint p0, GPSPoint p1) { - long d0 = p0.getTime().getTime(); - long d1 = p1.getTime().getTime(); - long delta = d1 - d0; - return delta; - } -} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineImpl.java index 8666fcf..15e7851 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineImpl.java @@ -25,7 +25,7 @@ package fr.ird.observe.entities.longline; import com.google.common.base.MoreObjects; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.longline.VesselActivityLongline; -import fr.ird.type.CoordinateHelper; +import fr.ird.observe.entities.gps.CoordinateHelper; import org.nuiton.util.DateUtil; import java.util.Date; diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/SetLonglineImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/SetLonglineImpl.java index 006448c..a1cc0e9 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/longline/SetLonglineImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/SetLonglineImpl.java @@ -24,7 +24,7 @@ package fr.ird.observe.entities.longline; import com.google.common.base.MoreObjects; import fr.ird.observe.entities.Entities; -import fr.ird.type.CoordinateHelper; +import fr.ird.observe.entities.gps.CoordinateHelper; import org.nuiton.util.DateUtil; import java.util.Date; diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/HarbourImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/HarbourImpl.java index b744d16..9029bbf 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/HarbourImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/HarbourImpl.java @@ -22,7 +22,7 @@ package fr.ird.observe.entities.referentiel; * #L% */ -import fr.ird.type.CoordinateHelper; +import fr.ird.observe.entities.gps.CoordinateHelper; public class HarbourImpl extends HarbourAbstract { diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java index 5a771ab..dc2cfde 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java @@ -25,7 +25,7 @@ import com.google.common.base.MoreObjects; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.constants.seine.SchoolTypePersist; import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; -import fr.ird.type.CoordinateHelper; +import fr.ird.observe.entities.gps.CoordinateHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.NumberUtil; diff --git a/observe-entities/src/main/java/fr/ird/type/CoordinateHelper.java b/observe-entities/src/main/java/fr/ird/type/CoordinateHelper.java deleted file mode 100644 index 5a519ab..0000000 --- a/observe-entities/src/main/java/fr/ird/type/CoordinateHelper.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.type; - -/** - * Helper to deal with coordinates. - * - * @author tchemit - chemit@codelutin.com - * @since 1.2 - */ -public class CoordinateHelper { - - /** - * Calcule le quadrant à partir d'une {@code longitude} et {@code latitude}. - * - * @param longitude la longitude décimale - * @param latitude la latitude décimale - * @return la valeur du quadrant ou {@code null} si l'une des deux - * coordonnées est {@code null}. - * @since 1.2 - */ - public static Integer getQuadrant(Float longitude, Float latitude) { - if (longitude == null || latitude == null) { - return null; - } - int result; - - if (latitude > 0) { - result = longitude > 0 ? 1 : 4; - } else { - result = longitude > 0 ? 2 : 3; - } - return result; - } - -} diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GpsPoints.java b/observe-services-model/src/main/java/fr/ird/observe/util/GPSPoint.java similarity index 60% rename from observe-services-model/src/main/java/fr/ird/observe/util/gps/GpsPoints.java rename to observe-services-model/src/main/java/fr/ird/observe/util/GPSPoint.java index a1133c4..f78a01e 100644 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GpsPoints.java +++ b/observe-services-model/src/main/java/fr/ird/observe/util/GPSPoint.java @@ -1,4 +1,4 @@ -package fr.ird.observe.util.gps; +package fr.ird.observe.util; /* * #%L @@ -29,18 +29,15 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.DateUtil; +import java.io.Serializable; import java.util.Date; -/** - * Created on 8/25/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.7 - */ -public class GpsPoints { +public class GPSPoint implements Serializable { + + private static final long serialVersionUID = 1L; /** Logger. */ - private static final Log log = LogFactory.getLog(GpsPoints.class); + private static final Log log = LogFactory.getLog(GPSPoint.class); public static final double MILE_TO_KM = 1.852; @@ -49,6 +46,26 @@ public class GpsPoints { /** le rayon de la terre en kilomètres */ public static final int R = 6378; + protected Float latitude; + + protected Float longitude; + + protected Float vitesse; + + protected Date time; + + public static GPSPoint newPoint(Date routeDay, Date activityTime, float activityLatitude, float activityLongitude) { + + Date currentTime = DateUtil.getDateAndTime(routeDay, activityTime, false, false); + + GPSPoint gpsPoint = new GPSPoint(); + gpsPoint.setTime(currentTime); + gpsPoint.setLatitude(activityLatitude); + gpsPoint.setLongitude(activityLongitude); + + return gpsPoint; + + } /** * Construit un point à partir de l'entité donnée. @@ -59,16 +76,7 @@ public class GpsPoints { * @since 3.8 */ public static GPSPoint newPoint(RouteDto route, ActivitySeineDto activity) { - - Date currentTime = DateUtil.getDateAndTime(route.getDate(), activity.getTime(), false, false); - - GPSPoint gpsPoint = new GPSPointImpl(); - gpsPoint.setTime(currentTime); - gpsPoint.setLatitude(activity.getLatitude()); - gpsPoint.setLongitude(activity.getLongitude()); - - return gpsPoint; - + return newPoint(route.getDate(), activity.getTime(), activity.getLatitude(), activity.getLongitude()); } /** @@ -80,18 +88,64 @@ public class GpsPoints { * @since 3.8 */ public static GPSPoint newPoint(RouteDto route, ActivitySeineStubDto activity) { + return newPoint(route.getDate(), activity.getTime(), activity.getLatitude(), activity.getLongitude()); + } - Date currentTime = DateUtil.getDateAndTime(route.getDate(), activity.getTime(), false, false); + public Integer getQuadrant() { + if (longitude == null || latitude == null) { + return null; + } + int result; - GPSPoint gpsPoint = new GPSPointImpl(); - gpsPoint.setTime(currentTime); - gpsPoint.setLatitude(activity.getLatitude()); - gpsPoint.setLongitude(activity.getLongitude()); + if (latitude > 0) { + result = longitude > 0 ? 1 : 4; + } else { + result = longitude > 0 ? 2 : 3; + } + return result; + } - return gpsPoint; + public boolean isSameLocation(GPSPoint point) { + float latitude = getLatitude() == null ? 0f : getLatitude(); + float longitude = getLongitude() == null ? 0f : getLongitude(); + + float latitude1 = point.getLatitude() == null ? 0f : point.getLatitude(); + float longitude1 = point.getLongitude() == null ? 0f : point.getLongitude(); + return latitude == latitude1 && longitude == longitude1; } + public Float getLatitude() { + return latitude; + } + + public void setLatitude(Float latitude) { + this.latitude = latitude; + } + + public Float getLongitude() { + return longitude; + } + + public void setLongitude(Float longitude) { + this.longitude = longitude; + } + + public Float getVitesse() { + return vitesse; + } + + public void setVitesse(Float vitesse) { + this.vitesse = vitesse; + } + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } /** * Calcule la distance entre deux points (en kilometres). @@ -103,12 +157,11 @@ public class GpsPoints { * d = R * arccos(cos(lat1) * cos(lat2) *cos(long2 - long1) + sin(lat1) * *sin(lat2)) * - * @param p0 le premier point * @param p1 le second point * @return la distance calculée entre les deux points en kilometres. */ - public static double getDistanceInKm(GPSPoint p0, GPSPoint p1) { - double d = getDistanceInMile(p0, p1) * MILE_TO_KM; + public double getDistanceInKm(GPSPoint p1) { + double d = getDistanceInMile(p1) * MILE_TO_KM; return d; } @@ -122,14 +175,13 @@ public class GpsPoints { * d = R * arccos(cos(lat1) * cos(lat2) *cos(long2 - long1) + sin(lat1) * *sin(lat2)) * - * @param p0 le premier point * @param p1 le second point * @return la distance calculée entre les deux points en noeud. */ - public static double getDistanceInMile(GPSPoint p0, GPSPoint p1) { + public double getDistanceInMile(GPSPoint p1) { double d; - if (p0.isSameLocation(p1)) { + if (isSameLocation(p1)) { // same location : so distance is null for sure // We use this limit case, otherwise in next computation, tmp @@ -137,8 +189,8 @@ public class GpsPoints { // then is NaN d = 0d; } else { - double lat1 = p0.getLatitude(); - double lng1 = p0.getLongitude(); + double lat1 = latitude; + double lng1 = longitude; double lat2 = p1.getLatitude(); double lng2 = p1.getLongitude(); @@ -149,7 +201,7 @@ public class GpsPoints { double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) - * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); + * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); d = EARTH_RADIUS * c; } @@ -159,25 +211,24 @@ public class GpsPoints { /** * Calcule la vitesse entre deux points (en noeud). * - * @param p0 le premier point * @param p1 le second point * @return la vitesse calculée entre les deux points en noeud. */ - public static float getSpeed(GPSPoint p0, GPSPoint p1) { + public float getSpeed(GPSPoint p1) { - if (p0.getTime().after(p1.getTime())) { + if (time.after(p1.getTime())) { if (log.isWarnEnabled()) { - log.warn("Le point " + p0 + " est chronologiquement après le point " + p1 + " impossible de calculer une vitesse."); + log.warn("Le point " + this + " est chronologiquement après le point " + p1 + " impossible de calculer une vitesse."); } return 0; } // la distance en miles nautique - double d = getDistanceInMile(p0, p1); + double d = getDistanceInMile(p1); // le temps en heure - float delay = (float) getDelay(p0, p1) / (1000 * 60 * 60); + float delay = (float) getDelay(p1) / (1000 * 60 * 60); // la vitesse en noeud double speed = d / delay; return (float) speed; @@ -186,14 +237,14 @@ public class GpsPoints { /** * Calcule le temps écoulé entre deux points (en millisecondes). * - * @param p0 le premier point * @param p1 le second point * @return le temps écoulé entre les deux points en millisecondes. */ - public static long getDelay(GPSPoint p0, GPSPoint p1) { - long d0 = p0.getTime().getTime(); + public long getDelay(GPSPoint p1) { + long d0 = getTime().getTime(); long d1 = p1.getTime().getTime(); long delta = d1 - d0; return delta; } + } diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSAble.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSAble.java deleted file mode 100644 index 8428f28..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSAble.java +++ /dev/null @@ -1,59 +0,0 @@ -package fr.ird.observe.util.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import java.util.Date; - -public interface GPSAble { - -// String PROPERTY_QUADRANT = "quadrant"; - - String PROPERTY_LATITUDE = "latitude"; - - String PROPERTY_LONGITUDE = "longitude"; - - String PROPERTY_VITESSE = "vitesse"; - - String PROPERTY_TIME = "time"; - - Integer getQuadrant(); - - void setQuadrant(Integer quadrant); - - Float getLatitude(); - - void setLatitude(Float latitude); - - Float getLongitude(); - - void setLongitude(Float longitude); - - Float getVitesse(); - - void setVitesse(Float vitesse); - - Date getTime(); - - void setTime(Date time); - -} //GPSAble diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSFileReader.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSFileReader.java deleted file mode 100644 index 3e43297..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSFileReader.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.util.gps; - -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParserFactory; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * Classe responsable de la construction du modèle {@link GPSRoute} à partir - * d'un fichier de traces GPS au format {@code GPX}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.0 - */ -public class GPSFileReader { - - /** log */ - private static final Log log = LogFactory.getLog(GPSFileReader.class); - - public static final String ROUTE_TAG = "trk"; - - public static final String SEGMENT_TAG = "trkseg"; - - public static final String POINT_TAG = "trkpt"; - - public static final String TIME_TAG = "time"; - - public static final String SPEED_TAG = "speed"; - - public static final String LATITUDE_ATTR = "lat"; - - public static final String LONGITUDE_ATTR = "lon"; - - /** le fichier à importer */ - protected final File source; - - /** le délai en minutes acceptable entre deux points */ - protected final int maxDelay; - - /** la vitesse maximum autorisée entre 2 points en noeud */ - protected final float maxSpeed; - - protected final GPSService service; - - public GPSFileReader(GPSService service, - File source, - int maxDelay, - float maxSpeed) { - this.service = service; - this.source = source; - this.maxDelay = maxDelay; - this.maxSpeed = maxSpeed; - } - - public GPSRoute read() throws Exception { - if (source == null) { - throw new NullPointerException("la source ne doit pas être nulle"); - } - if (!source.exists() || !source.isFile()) { - throw new IllegalArgumentException("le fichier source '" + source + "' n'existe pas ou n'est pas un fichier"); - } - - GPSRoute model = new GPSRouteImpl(); - - XmlPullParserFactory factory = XmlPullParserFactory.newInstance( - System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); - factory.setNamespaceAware(true); - XmlPullParser xpp = factory.newPullParser(); - FileReader fileReader = new FileReader(source); - - try { - xpp.setInput(fileReader); - - parseFile(xpp, model); - } finally { - fileReader.close(); - } - - return model; - } - - /** - * Détecte sur l'ensemble des points de la route ceux qui sont acceptables, - * c'est à dire que l'on accepte uniquement les points dont les intervalles - * de temps ne dépassent pas {@link #maxDelay}. - * - * Les intervalles de poinbts acceptables seront contenus dans {@link - * GPSRoute#acceptedInterval}, les intervalles rejetés seront sauvés dans - * {@link GPSRoute#rejectedInterval} - * - * @param route la route à traiter - */ - public void detectIntervals(GPSRoute route) { - if (log.isInfoEnabled()) { - log.info("starting... for " + this); - } - List<GPSPointInterval> acceptedList = new ArrayList<>(); - List<GPSPointInterval> rejectedList = new ArrayList<>(); - GPSPointInterval currentAccepted = null; - GPSPointInterval currentRejected = null; - GPSPoint previous = null; - // le delai acceptable entre deux points en millisecondes - long delay = getMaxSpeedAsMilliSecondes(); - - for (GPSPoint p : route.getPoint()) { - if (log.isTraceEnabled()) { - log.trace("test point " + p); - } - if (previous == null) { - // premeir point rencontré, rien à faire - previous = p; - continue; - } - long delta = service.getDelay(previous, p); - if (delta <= delay) { - // le point courant est acceptable - // on l'enregistre dans l'intervalle accepté - if (log.isDebugEnabled()) { - log.debug("accepted point: " + p + ", delta: " + delta); - } - - if (currentRejected != null) { - // on etait sur un intervalle de rejet - // il faut le fermer et l'enregister dans le modèle - rejectedList.add(currentRejected); - currentRejected = null; - } - if (currentAccepted == null) { - currentAccepted = new GPSPointIntervalImpl(); - currentAccepted.setPoint(new ArrayList<>()); - currentAccepted.addPoint(previous); - } - currentAccepted.addPoint(p); - previous = p; - continue; - } - - // le point courant n'est pas acceptable - // on l'enregistre dans l'intervalle courant de rejet - - if (log.isDebugEnabled()) { - log.debug("rejected point: " + p + ", delta: " + delta); - } - if (currentAccepted != null) { - // on était sur un intervall accepté, on doit le fermer - // et l'enregistre dans le modèle - acceptedList.add(currentAccepted); - currentAccepted = null; - } - if (currentRejected == null) { - // nouvelle intervalle de rejet - currentRejected = new GPSPointIntervalImpl(); - currentRejected.setPoint(new ArrayList<>()); - currentRejected.addPoint(previous); - } - currentRejected.addPoint(p); - previous = p; - } - - if (currentAccepted != null) { - // ajout de l'intervalle accepté - acceptedList.add(currentAccepted); - } - - if (currentRejected != null) { - // ajout de l'intervalle rejeté - rejectedList.add(currentRejected); - } - - // on enregistre les intervalles dans le modèle - if (!acceptedList.isEmpty()) { - route.setAcceptedInterval(acceptedList); - } - if (!rejectedList.isEmpty()) { - route.setRejectedInterval(rejectedList); - } - - } - - @Override - public String toString() { - String result = new ToStringBuilder(this).append("source", source). - append("maxDelay (ms)", getMaxSpeedAsMilliSecondes()). - append("maxSpeed (nd)", maxSpeed). - toString(); - return result; - } - - protected long getMaxSpeedAsMilliSecondes() { - return maxDelay * 60 * 1000; - } - - /** - * Parse le fichier xml donné et construit le modèle. - * - * Pour le moment on se limite à traiter le premier segment - * ({@code trkseg}) de la première route ({@code trk}). - * - * Lors de la découverte des points, on ne retient pas les points dont la - * vitesse par rapport au précédent point dépasse {@link - * #getMaxSpeedAsMilliSecondes()}. - * - * @param xpp le parser xml - * @param model le model à remplir - * @throws IOException - * @throws XmlPullParserException - * @throws ParseException - */ - protected void parseFile(XmlPullParser xpp, - GPSRoute model) throws IOException, XmlPullParserException, ParseException { - List<GPSPoint> points = new ArrayList<>(); - GPSPoint previousPoint = null; - GPSPoint currentPoint = null; - boolean findRoute = false; - boolean findSegment = false; - int elementType; - - String localName; - - if (xpp.getEventType() == XmlPullParser.START_DOCUMENT) { - xpp.next(); - } - - // recherche du premier segment de la première route - while (xpp.next() != XmlPullParser.END_DOCUMENT) { - // nouveau tag - localName = xpp.getName(); - if (ROUTE_TAG.equals(localName)) { - findRoute = true; - break; - } - } - if (!findRoute) { - // aucune route trouvée - return; - } - while ((elementType = xpp.next()) != XmlPullParser.END_DOCUMENT) { - // nouveau tag - localName = xpp.getName(); - if (SEGMENT_TAG.equals(localName)) { - findSegment = true; - break; - } - } - if (!findSegment) { - // aucun segment trouvé - return; - } - - String content; - - //format de type : 2007-11-09T04:54:27.000Z - DateFormat df = new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSSS'Z'"); - - Float f; - while ((elementType = xpp.next()) != XmlPullParser.END_DOCUMENT) { - localName = xpp.getName(); - if (elementType == XmlPullParser.START_TAG) { - // debut d'un tag - if (POINT_TAG.equals(localName)) { - // debut d'un point - currentPoint = new GPSPointImpl(); - content = xpp.getAttributeValue(null, LATITUDE_ATTR); - f = Float.valueOf(content); - currentPoint.setLatitude(f); - content = xpp.getAttributeValue(null, LONGITUDE_ATTR); - f = Float.valueOf(content); - currentPoint.setLongitude(f); - continue; - } - if (TIME_TAG.equals(localName)) { - // tag de time - content = xpp.nextText(); - - Date d = df.parse(content); - currentPoint.setTime(d); - continue; - } - if (SPEED_TAG.equals(localName)) { - // tag de vitesse - content = xpp.nextText(); - f = Float.valueOf(content); - currentPoint.setVitesse(f); - continue; - } - - // les autres tags en ouverture ne sont pas traités pour le moment - continue; - } - if (elementType == XmlPullParser.END_TAG) { - // fin d'un tag - if (POINT_TAG.equals(localName)) { - // fin d'un point - boolean canAccept = true; - if (previousPoint != null) { - // on vérifie que la vitesse entrez les deux points - // est acceptable - float speed = service.getSpeed(previousPoint, currentPoint); - if (speed > maxSpeed) { - // on ne peut pas accepter ce point - canAccept = false; - } - } - if (canAccept) { - // le point est acceptable, on le conserve - points.add(currentPoint); - // et il passe en nouveau point de reference - previousPoint = currentPoint; - } - currentPoint = null; - continue; - } - if (SEGMENT_TAG.equals(localName)) { - // fin du segment - // on a terminé la lecture du premier segment - // on peut quitter le parsing - break; - } - } - } - model.setPoint(points); - } -} diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPoint.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPoint.java deleted file mode 100644 index 7891366..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPoint.java +++ /dev/null @@ -1,118 +0,0 @@ -package fr.ird.observe.util.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.Date; - -public abstract class GPSPoint implements GPSAble, Serializable { - - private static final long serialVersionUID = 3761972876361753443L; - - public static final String PROPERTY_LATITUDE = "latitude"; - - public static final String PROPERTY_LONGITUDE = "longitude"; - - public static final String PROPERTY_VITESSE = "vitesse"; - - public static final String PROPERTY_TIME = "time"; - - protected Float latitude; - - protected Float longitude; - - protected Float vitesse; - - protected Date time; - - protected final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public Float getLatitude() { - return latitude; - } - - public void setLatitude(Float latitude) { - Float oldValue = getLatitude(); - this.latitude = latitude; - firePropertyChange(PROPERTY_LATITUDE, oldValue, latitude); - } - - public Float getLongitude() { - return longitude; - } - - public void setLongitude(Float longitude) { - Float oldValue = getLongitude(); - this.longitude = longitude; - firePropertyChange(PROPERTY_LONGITUDE, oldValue, longitude); - } - - public Float getVitesse() { - return vitesse; - } - - public void setVitesse(Float vitesse) { - Float oldValue = getVitesse(); - this.vitesse = vitesse; - firePropertyChange(PROPERTY_VITESSE, oldValue, vitesse); - } - - public Date getTime() { - return time; - } - - public void setTime(Date time) { - Date oldValue = getTime(); - this.time = time; - firePropertyChange(PROPERTY_TIME, oldValue, time); - } - - public abstract boolean isSameLocation(GPSPoint point); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - - protected void firePropertyChange(String propertyName, Object newValue) { - firePropertyChange(propertyName, null, newValue); - } - -} //GPSPoint diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointImpl.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointImpl.java deleted file mode 100644 index a9714c6..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.util.gps; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.0 - */ -public class GPSPointImpl extends GPSPoint { - - private static final long serialVersionUID = 1L; - - public GPSPointImpl() { - } - - public GPSPointImpl(GPSAble activity) { - setLongitude(activity.getLongitude()); - setLatitude(activity.getLatitude()); - setTime(activity.getTime()); - } - - @Override - public Integer getQuadrant() { - Integer result = CoordinateHelper.getQuadrant(longitude, latitude); - return result; -// if (latitude == null || longitude == null) { -// return null; -// } -// int result; -// -// if (latitude > 0) { -// result = longitude > 0 ? 1 : 4; -//// result = longitude > 0 ? 1 : 3; -// } else { -// result = longitude > 0 ? 2 : 3; -//// result = longitude > 0 ? 1 : 3; -// } -// return result; - } - - @Override - public void setQuadrant(Integer quadrant) { - // non utilisé - } - - @Override - public boolean isSameLocation(GPSPoint point) { - float latitude = getLatitude() == null ? 0f : getLatitude(); - float longitude = getLongitude() == null ? 0f : getLongitude(); - - float latitude1 = point.getLatitude() == null ? 0f : point.getLatitude(); - float longitude1 = point.getLongitude() == null ? 0f : point.getLongitude(); - - return latitude == latitude1 && longitude == longitude1; - } - -} diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointInterval.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointInterval.java deleted file mode 100644 index 40ff7f1..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointInterval.java +++ /dev/null @@ -1,155 +0,0 @@ -package fr.ird.observe.util.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - -public abstract class GPSPointInterval implements Serializable { - - private static final long serialVersionUID = 7377852988997002340L; - - public static final String PROPERTY_POINT = "point"; - - protected List<GPSPoint> point; - - protected final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public GPSPoint getPoint(int index) { - GPSPoint o = getChild(point, index); - return o; - } - - public boolean isPointEmpty() { - return point == null || point.isEmpty(); - } - - public int sizePoint() { - return point == null ? 0 : point.size(); - } - - public void addPoint(GPSPoint point) { - getPoint().add(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public void addAllPoint(Collection<GPSPoint> point) { - getPoint().addAll(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public boolean removePoint(GPSPoint point) { - boolean removed = getPoint().remove(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean removeAllPoint(Collection<GPSPoint> point) { - boolean removed = getPoint().removeAll(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean containsPoint(GPSPoint point) { - boolean contains = getPoint().contains(point); - return contains; - } - - public boolean containsAllPoint(Collection<GPSPoint> point) { - boolean contains = getPoint().containsAll(point); - return contains; - } - - public List<GPSPoint> getPoint() { - return point; - } - - public void setPoint(List<GPSPoint> point) { - List<GPSPoint> oldValue = getPoint(); - this.point = point; - firePropertyChange(PROPERTY_POINT, oldValue, point); - } - - public abstract GPSPoint getFirstPoint(); - - public abstract GPSPoint getLastPoint(); - - public abstract long getDateMin(); - - public abstract long getDateMax(); - - public abstract int getPointSize(); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - - protected void firePropertyChange(String propertyName, Object newValue) { - firePropertyChange(propertyName, null, newValue); - } - - protected <T> T getChild(Collection<T> childs, int index) { - T result = null; - if (childs != null) { - if (childs instanceof List) { - if (index < childs.size()) { - result = ((List<T>) childs).get(index); - } - } else { - int i = 0; - for (T o : childs) { - if (index == i) { - result = o; - break; - } - i++; - } - } - } - return result; - } - -} //GPSPointInterval diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointIntervalImpl.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointIntervalImpl.java deleted file mode 100644 index 363af69..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSPointIntervalImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.util.gps; - -import java.util.Date; - -import static org.nuiton.i18n.I18n.t; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.0 - */ -public class GPSPointIntervalImpl extends GPSPointInterval { - - private static final long serialVersionUID = 1L; - - @Override - public GPSPoint getFirstPoint() { - if (getPoint() == null) { - return null; - } - GPSPoint p = getPoint(0); - return p; - } - - @Override - public GPSPoint getLastPoint() { - if (getPoint() == null) { - return null; - } - GPSPoint p = getPoint(getPoint().size() - 1); - return p; - } - - @Override - public long getDateMin() { - GPSPoint p = getFirstPoint(); - if (p == null) { - throw new NullPointerException("Pas de premier point definie dans l'intervalle " + this); - } - return p.getTime().getTime(); - } - - @Override - public long getDateMax() { - GPSPoint p = getLastPoint(); - if (p == null) { - throw new NullPointerException("Pas de dernier point definie dans l'intervalle " + this); - } - return p.getTime().getTime(); - } - - @Override - public int getPointSize() { - return point == null ? 0 : point.size(); - } - - @Override - public String toString() { - String l; -// if (getPoint() == null || getFirstPoint() == null || getLastPoint() == null) { -// l = super.toString(); -// } - l = t("observe.common.gpsPointInterval", new Date(getDateMin()), new Date(getDateMax()), getPoint().size()); - return l; - } -} diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSRoute.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSRoute.java deleted file mode 100644 index 4590179..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSRoute.java +++ /dev/null @@ -1,276 +0,0 @@ -package fr.ird.observe.util.gps; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.Collection; -import java.util.Date; -import java.util.List; - -public abstract class GPSRoute implements Serializable { - - private static final long serialVersionUID = 3702862907863819874L; - - public static final String PROPERTY_POINT = "point"; - - public static final String PROPERTY_ACCEPTED_INTERVAL = "acceptedInterval"; - - public static final String PROPERTY_REJECTED_INTERVAL = "rejectedInterval"; - - protected List<GPSPoint> point; - - protected List<GPSPointInterval> acceptedInterval; - - protected List<GPSPointInterval> rejectedInterval; - - protected final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public GPSPoint getPoint(int index) { - GPSPoint o = getChild(point, index); - return o; - } - - public boolean isPointEmpty() { - return point == null || point.isEmpty(); - } - - public int sizePoint() { - return point == null ? 0 : point.size(); - } - - public void addPoint(GPSPoint point) { - getPoint().add(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public void addAllPoint(Collection<GPSPoint> point) { - getPoint().addAll(point); - firePropertyChange(PROPERTY_POINT, null, point); - } - - public boolean removePoint(GPSPoint point) { - boolean removed = getPoint().remove(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean removeAllPoint(Collection<GPSPoint> point) { - boolean removed = getPoint().removeAll(point); - if (removed) { - firePropertyChange(PROPERTY_POINT, point, null); - } - return removed; - } - - public boolean containsPoint(GPSPoint point) { - boolean contains = getPoint().contains(point); - return contains; - } - - public boolean containsAllPoint(Collection<GPSPoint> point) { - boolean contains = getPoint().containsAll(point); - return contains; - } - - public List<GPSPoint> getPoint() { - return point; - } - - public void setPoint(List<GPSPoint> point) { - List<GPSPoint> oldValue = getPoint(); - this.point = point; - firePropertyChange(PROPERTY_POINT, oldValue, point); - } - - public GPSPointInterval getAcceptedInterval(int index) { - GPSPointInterval o = getChild(acceptedInterval, index); - return o; - } - - public boolean isAcceptedIntervalEmpty() { - return acceptedInterval == null || acceptedInterval.isEmpty(); - } - - public int sizeAcceptedInterval() { - return acceptedInterval == null ? 0 : acceptedInterval.size(); - } - - public void addAcceptedInterval(GPSPointInterval acceptedInterval) { - getAcceptedInterval().add(acceptedInterval); - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, null, acceptedInterval); - } - - public void addAllAcceptedInterval(Collection<GPSPointInterval> acceptedInterval) { - getAcceptedInterval().addAll(acceptedInterval); - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, null, acceptedInterval); - } - - public boolean removeAcceptedInterval(GPSPointInterval acceptedInterval) { - boolean removed = getAcceptedInterval().remove(acceptedInterval); - if (removed) { - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, acceptedInterval, null); - } - return removed; - } - - public boolean removeAllAcceptedInterval(Collection<GPSPointInterval> acceptedInterval) { - boolean removed = getAcceptedInterval().removeAll(acceptedInterval); - if (removed) { - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, acceptedInterval, null); - } - return removed; - } - - public boolean containsAcceptedInterval(GPSPointInterval acceptedInterval) { - boolean contains = getAcceptedInterval().contains(acceptedInterval); - return contains; - } - - public boolean containsAllAcceptedInterval(Collection<GPSPointInterval> acceptedInterval) { - boolean contains = getAcceptedInterval().containsAll(acceptedInterval); - return contains; - } - - public List<GPSPointInterval> getAcceptedInterval() { - return acceptedInterval; - } - - public void setAcceptedInterval(List<GPSPointInterval> acceptedInterval) { - List<GPSPointInterval> oldValue = getAcceptedInterval(); - this.acceptedInterval = acceptedInterval; - firePropertyChange(PROPERTY_ACCEPTED_INTERVAL, oldValue, acceptedInterval); - } - - public GPSPointInterval getRejectedInterval(int index) { - GPSPointInterval o = getChild(rejectedInterval, index); - return o; - } - - public boolean isRejectedIntervalEmpty() { - return rejectedInterval == null || rejectedInterval.isEmpty(); - } - - public int sizeRejectedInterval() { - return rejectedInterval == null ? 0 : rejectedInterval.size(); - } - - public void addRejectedInterval(GPSPointInterval rejectedInterval) { - getRejectedInterval().add(rejectedInterval); - firePropertyChange(PROPERTY_REJECTED_INTERVAL, null, rejectedInterval); - } - - public void addAllRejectedInterval(Collection<GPSPointInterval> rejectedInterval) { - getRejectedInterval().addAll(rejectedInterval); - firePropertyChange(PROPERTY_REJECTED_INTERVAL, null, rejectedInterval); - } - - public boolean removeRejectedInterval(GPSPointInterval rejectedInterval) { - boolean removed = getRejectedInterval().remove(rejectedInterval); - if (removed) { - firePropertyChange(PROPERTY_REJECTED_INTERVAL, rejectedInterval, null); - } - return removed; - } - - public boolean removeAllRejectedInterval(Collection<GPSPointInterval> rejectedInterval) { - boolean removed = getRejectedInterval().removeAll(rejectedInterval); - if (removed) { - firePropertyChange(PROPERTY_REJECTED_INTERVAL, rejectedInterval, null); - } - return removed; - } - - public boolean containsRejectedInterval(GPSPointInterval rejectedInterval) { - boolean contains = getRejectedInterval().contains(rejectedInterval); - return contains; - } - - public boolean containsAllRejectedInterval(Collection<GPSPointInterval> rejectedInterval) { - boolean contains = getRejectedInterval().containsAll(rejectedInterval); - return contains; - } - - public List<GPSPointInterval> getRejectedInterval() { - return rejectedInterval; - } - - public void setRejectedInterval(List<GPSPointInterval> rejectedInterval) { - List<GPSPointInterval> oldValue = getRejectedInterval(); - this.rejectedInterval = rejectedInterval; - firePropertyChange(PROPERTY_REJECTED_INTERVAL, oldValue, rejectedInterval); - } - - public abstract GPSPoint getPoint(Date date); - - public abstract int getBeforePointIndex(GPSPointInterval intervalle, long date); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - - protected void firePropertyChange(String propertyName, Object newValue) { - firePropertyChange(propertyName, null, newValue); - } - - protected <T> T getChild(Collection<T> childs, int index) { - T result = null; - if (childs != null) { - if (childs instanceof List) { - if (index < childs.size()) { - result = ((List<T>) childs).get(index); - } - } else { - int i = 0; - for (T o : childs) { - if (index == i) { - result = o; - break; - } - i++; - } - } - } - return result; - } - -} //GPSRoute diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSRouteImpl.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSRouteImpl.java deleted file mode 100644 index ae0b615..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSRouteImpl.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.util.gps; - -import java.util.Date; -import java.util.List; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.0 - */ -public class GPSRouteImpl extends GPSRoute { - - private static final long serialVersionUID = 1L; - - /** - * Permet de construire un point pour une date donnée. - * - * On recherche parmis les intervalles acceptables les deux points entourant - * la date donnée. - * - * Si on a réussi à trouver deux points adéquates, alors on construit un - * nouveau point en utilisant la formule d'interpolation pour calculer les - * coordonnées du point. - * - * @param date la date du point à construire - * @return le nouveau point construit ou {@code null} si on a pas - * trouvé un intervalle de points acdeptables pour la date donnée. - */ - @Override - public GPSPoint getPoint(Date date) { - if (date == null) { - throw new NullPointerException("la date ne peut pas être nulle!"); - } - long tx = date.getTime(); - GPSPoint newPoint = null; - List<GPSPointInterval> intervalles = getAcceptedInterval(); - if (intervalles != null && !intervalles.isEmpty()) { - for (GPSPointInterval intervalle : intervalles) { - int index = getBeforePointIndex(intervalle, tx); - if (index == -1) { - // l'intervalle n'accepte pas la date donnée - continue; - } - // l'intervalle courant est acceptable pour la date donnée - GPSPoint p0 = intervalle.getPoint(index); - GPSPoint p1 = intervalle.getPoint(index + 1); - - //FIXME on devrait peut-être arrondir aux secondes ? - if (p0.getTime().getTime() == tx) { - newPoint = p0; - break; - } - //FIXME on devrait peut-être arrondir aux secondes ? - if (p1.getTime().getTime() == tx) { - newPoint = p1; - break; - } - // on calcule la position du nouveau point - // via la formule d'interpolation - newPoint = newPoint(p0, p1, date); - // on quitte car le point a été trouvé - break; - } - } - return newPoint; - - } - - /** - * Trouve l'index du point juste avant la date donnée (et donc le point - * suivant est après la date donnée). - * - * @param intervalle l'intervalle de points à parcourir - * @param date la date donnée - * @return l'index du point trouvé ou {@code -1} si pas de point - * adéquate trouvé. - */ - @Override - public int getBeforePointIndex(GPSPointInterval intervalle, long date) { - - int result = -1; - long min = intervalle.getDateMin(); - long max = intervalle.getDateMax(); - if (min <= date || date <= max) { - // cet intervalle est pas acceptable pour la date donnée - if (date == min) { - return 0; - } - if (date == max) { - return intervalle.getPoint().size() - 1; - } - List<GPSPoint> points = intervalle.getPoint(); - for (int i = 0, j = points.size(); i < j; i++) { - GPSPoint beforePoint = points.get(i); - long d = beforePoint.getTime().getTime(); - if (d > date) { - // on a trouvé le premier point juste après la date donnée - // on peut s'arreter là - result = i - 1; - break; - } - } - } - return result; - } - - protected GPSPoint newPoint(GPSPoint p0, GPSPoint p1, Date d) { - GPSPoint p = new GPSPointImpl(); - p.setTime(d); - long tx = d.getTime(); - long t0 = p0.getTime().getTime(); - long t1 = p1.getTime().getTime(); - float latitudeX = getInterpolation(t0, t1, tx, p0.getLatitude(), p1.getLatitude()); - float longitudeX = getInterpolation(t0, t1, tx, p0.getLongitude(), p1.getLongitude()); - p.setLongitude(longitudeX); - p.setLatitude(latitudeX); - return p; - } - - protected float getInterpolation(long t0, long t1, long tx, float x0, float x1) { - float result = (tx - t0 - (t1 - t0)) * (x1 - x0) + x0; - return result; - } -} diff --git a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSService.java b/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSService.java deleted file mode 100644 index f6e6496..0000000 --- a/observe-services-model/src/main/java/fr/ird/observe/util/gps/GPSService.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.util.gps; - -import java.io.File; - -/** - * Service de manipulation GPS. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 - */ -public class GPSService { - - /** - * Construit la route gps à partir d'un fichier gps donnée et des deux - * indicateurs {@code maxDelay} et {@code maxSpeed} et la retourne. - * - * @param file le fichier contenant les données gps - * @param maxDelay le maximum de temps entre 2 points - * @param maxSpeed le vitesse maximale en 2 points - * @return la route gps calculée - * @throws Exception pour tout probleme lors la construction de la route - */ - public GPSRoute buildRoute(File file, - int maxDelay, - float maxSpeed) throws Exception { - GPSFileReader reader = new GPSFileReader(this, file, maxDelay, maxSpeed); - GPSRoute r = reader.read(); - reader.detectIntervals(r); - return r; - } - - /** - * Calcule la distance entre deux points (en kilometres). - * - * Il s'agit d'une approxiation utilisant la méthode d'orthodromie. - * - * http://fr.wikipedia.org/wiki/Orthodromie - * - * d = R * arccos(cos(lat1) * cos(lat2) *cos(long2 - long1) + sin(lat1) - * *sin(lat2)) - * - * @param p0 le premier point - * @param p1 le second point - * @return la distance calculée entre les deux points en kilometres. - */ - public double getDistanceInKm(GPSPoint p0, GPSPoint p1) { - double d = GpsPoints.getDistanceInKm(p0, p1); - return d; - } - - /** - * Calcule la distance entre deux points (en miles nautique). - * - * Il s'agit d'une approxiation utilisant la méthode d'orthodromie. - * - * http://fr.wikipedia.org/wiki/Orthodromie - * - * d = R * arccos(cos(lat1) * cos(lat2) *cos(long2 - long1) + sin(lat1) - * *sin(lat2)) - * - * @param p0 le premier point - * @param p1 le second point - * @return la distance calculée entre les deux points en noeud. - */ - public double getDistanceInMile(GPSPoint p0, GPSPoint p1) { - double d = GpsPoints.getDistanceInMile(p0, p1); - return d; - } - - /** - * Calcule la vitesse entre deux points (en noeud). - * - * @param p0 le premier point - * @param p1 le second point - * @return la vitesse calculée entre les deux points en noeud. - */ - public float getSpeed(GPSPoint p0, GPSPoint p1) { - float d = GpsPoints.getSpeed(p0, p1); - return d; - - } - - /** - * Calcule le temps écoulé entre deux points (en millisecondes). - * - * @param p0 le premier point - * @param p1 le second point - * @return le temps écoulé entre les deux points en millisecondes. - */ - public long getDelay(GPSPoint p0, GPSPoint p1) { - return GpsPoints.getDelay(p0, p1); - } - -} diff --git a/observe-services-topia-validation/pom.xml b/observe-services-topia-validation/pom.xml index d611eb8..ec535c3 100644 --- a/observe-services-topia-validation/pom.xml +++ b/observe-services-topia-validation/pom.xml @@ -46,6 +46,11 @@ <artifactId>observe-entities</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>observe-services-model</artifactId> + <version>${project.version}</version> + </dependency> <!-- Nuiton --> <dependency> diff --git a/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySimpleSpeedValidator.java b/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySimpleSpeedValidator.java index 341f782..85fb69d 100644 --- a/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySimpleSpeedValidator.java +++ b/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySimpleSpeedValidator.java @@ -25,11 +25,10 @@ package fr.ird.observe.services.topia.validation.validators; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.validator.ValidationException; import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import fr.ird.observe.entities.gps.GPSPoint; -import fr.ird.observe.entities.gps.GpsPoints; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeines; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.util.GPSPoint; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -146,10 +145,10 @@ public class ActivitySimpleSpeedValidator extends FieldValidatorSupport { return; } - GPSPoint currentPoint = GpsPoints.newPoint(route, activity); - GPSPoint previousPoint = GpsPoints.newPoint(route, previousActivity); + GPSPoint currentPoint = GPSPoint.newPoint(route.getDate(), activity.getTime(), activity.getLatitude(), activity.getLongitude()); + GPSPoint previousPoint = GPSPoint.newPoint(route.getDate(), previousActivity.getTime(), previousActivity.getLatitude(), previousActivity.getLongitude()); - float computedSpeed = GpsPoints.getSpeed(previousPoint, currentPoint); + float computedSpeed = previousPoint.getSpeed(currentPoint); if (log.isDebugEnabled()) { log.debug("Speed computed between previous activity point " + decorate(previousPoint) + " to current activity point " + decorate(currentPoint) + ", speed is : " + computedSpeed); diff --git a/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySpeedValidator.java b/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySpeedValidator.java index 2bddf91..3f5ff34 100644 --- a/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySpeedValidator.java +++ b/observe-services-topia-validation/src/main/java/fr/ird/observe/services/topia/validation/validators/ActivitySpeedValidator.java @@ -25,10 +25,9 @@ package fr.ird.observe.services.topia.validation.validators; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.validator.ValidationException; import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import fr.ird.observe.entities.gps.GPSPoint; -import fr.ird.observe.entities.gps.GpsPoints; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.util.GPSPoint; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.xwork2.field.CollectionFieldExpressionValidator; @@ -143,10 +142,10 @@ public class ActivitySpeedValidator extends FieldValidatorSupport { return true; } - GPSPoint previousPoint = GpsPoints.newPoint(route, previousActivity); - GPSPoint currentPoint = GpsPoints.newPoint(route, currentActivity); + GPSPoint previousPoint = GPSPoint.newPoint(route.getDate(), previousActivity.getTime(), previousActivity.getLatitude(), previousActivity.getLongitude()); + GPSPoint currentPoint = GPSPoint.newPoint(route.getDate(), currentActivity.getTime(), currentActivity.getLatitude(), currentActivity.getLongitude()); - float computedSpeed = GpsPoints.getSpeed(previousPoint, currentPoint); + float computedSpeed = previousPoint.getSpeed(currentPoint); if (LOG.isDebugEnabled()) { LOG.debug("Speed computed between previous activity point " + decorate(previousPoint) + " to current activity point " + decorate(currentPoint) + ", speed is : " + computedSpeed); diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/ActivityLonglineServiceTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/ActivityLonglineServiceTopia.java index fa454fa..d73dcee 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/ActivityLonglineServiceTopia.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/ActivityLonglineServiceTopia.java @@ -40,7 +40,7 @@ import fr.ird.observe.services.dto.result.SaveResultDto; import fr.ird.observe.services.dto.result.TripChildSaveResultDto; import fr.ird.observe.services.dto.result.TripChildSaveResultDtos; import fr.ird.observe.services.service.DataNotFoundException; -import fr.ird.type.CoordinateHelper; +import fr.ird.observe.entities.gps.CoordinateHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/service/seine/ActivitySeineServiceTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/service/seine/ActivitySeineServiceTopia.java index 7071335..91c3303 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/service/seine/ActivitySeineServiceTopia.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/service/seine/ActivitySeineServiceTopia.java @@ -39,7 +39,7 @@ import fr.ird.observe.services.dto.result.SaveResultDto; import fr.ird.observe.services.dto.seine.ActivitySeineDto; import fr.ird.observe.services.dto.seine.RouteDto; import fr.ird.observe.services.service.DataNotFoundException; -import fr.ird.type.CoordinateHelper; +import fr.ird.observe.entities.gps.CoordinateHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.DateUtil; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.