summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/distance/distancefunction/geo/LngLatDistanceFunction.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/distance/distancefunction/geo/LngLatDistanceFunction.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/geo/LngLatDistanceFunction.java66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/geo/LngLatDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/geo/LngLatDistanceFunction.java
index 98a219dd..e8d2623d 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/geo/LngLatDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/geo/LngLatDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.geo;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -26,8 +26,8 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.geo;
import de.lmu.ifi.dbs.elki.data.NumberVector;
import de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable;
import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation;
-import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractSpatialDoubleDistanceFunction;
+import de.lmu.ifi.dbs.elki.data.type.TypeUtil;
+import de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractSpatialDistanceFunction;
import de.lmu.ifi.dbs.elki.math.geodesy.EarthModel;
import de.lmu.ifi.dbs.elki.math.geodesy.SphericalVincentyEarthModel;
import de.lmu.ifi.dbs.elki.utilities.documentation.Reference;
@@ -39,9 +39,23 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ObjectParameter;
/**
* Distance function for 2D vectors in Longitude, Latitude form.
*
+ * The input data must be in degrees (not radians), and the output distance will
+ * be in meters (see {@link EarthModel#distanceDeg}).
+ *
+ * This implementation allows index accelerated queries using R*-trees (by
+ * providing a point-to-rectangle minimum distance), as published in:
+ * <p>
+ * Erich Schubert, Arthur Zimek and Hans-Peter Kriegel<br />
+ * Geodetic Distance Queries on R-Trees for Indexing Geographic Data<br />
+ * Advances in Spatial and Temporal Databases - 13th International Symposium,
+ * SSTD 2013, Munich, Germany
+ * </p>
+ *
* @author Erich Schubert
+ *
+ * @apiviz.composedOf EarthModel
*/
-public class LngLatDistanceFunction extends AbstractSpatialDoubleDistanceFunction {
+public class LngLatDistanceFunction extends AbstractSpatialDistanceFunction {
/**
* Earth model to use.
*/
@@ -56,33 +70,36 @@ public class LngLatDistanceFunction extends AbstractSpatialDoubleDistanceFunctio
}
@Override
- public double doubleDistance(NumberVector<?> o1, NumberVector<?> o2) {
+ public double distance(NumberVector o1, NumberVector o2) {
return model.distanceDeg(o1.doubleValue(1), o1.doubleValue(0), o2.doubleValue(1), o2.doubleValue(0));
}
@Override
@Reference(authors = "Erich Schubert, Arthur Zimek and Hans-Peter Kriegel", title = "Geodetic Distance Queries on R-Trees for Indexing Geographic Data", booktitle = "Advances in Spatial and Temporal Databases - 13th International Symposium, SSTD 2013, Munich, Germany")
- public double doubleMinDist(SpatialComparable mbr1, SpatialComparable mbr2) {
- if (mbr1 instanceof NumberVector) {
- if (mbr2 instanceof NumberVector) {
- return doubleDistance((NumberVector<?>) mbr1, (NumberVector<?>) mbr2);
- } else {
- NumberVector<?> o1 = (NumberVector<?>) mbr1;
+ public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
+ if(mbr1 instanceof NumberVector) {
+ if(mbr2 instanceof NumberVector) {
+ return distance((NumberVector) mbr1, (NumberVector) mbr2);
+ }
+ else {
+ NumberVector o1 = (NumberVector) mbr1;
return model.minDistDeg(o1.doubleValue(1), o1.doubleValue(0), mbr2.getMin(1), mbr2.getMin(0), mbr2.getMax(1), mbr2.getMax(0));
}
- } else {
- if (mbr2 instanceof NumberVector) {
- NumberVector<?> o2 = (NumberVector<?>) mbr2;
+ }
+ else {
+ if(mbr2 instanceof NumberVector) {
+ NumberVector o2 = (NumberVector) mbr2;
return model.minDistDeg(o2.doubleValue(1), o2.doubleValue(0), mbr1.getMin(1), mbr1.getMin(0), mbr1.getMax(1), mbr1.getMax(0));
- } else {
+ }
+ else {
throw new NotImplementedException("This distance function cannot - yet - be used with this algorithm, as the lower bound rectangle to rectangle distances have not yet been formalized for geodetic data.");
}
}
}
@Override
- public SimpleTypeInformation<? super NumberVector<?>> getInputTypeRestriction() {
- return new VectorFieldTypeInformation<>(NumberVector.class, 2);
+ public SimpleTypeInformation<? super NumberVector> getInputTypeRestriction() {
+ return TypeUtil.NUMBER_VECTOR_FIELD_2D;
}
@Override
@@ -95,21 +112,22 @@ public class LngLatDistanceFunction extends AbstractSpatialDoubleDistanceFunctio
@Override
public boolean equals(Object obj) {
- if (this == obj) {
+ if(this == obj) {
return true;
}
- if (obj == null) {
+ if(obj == null) {
return false;
}
- if (getClass() != obj.getClass()) {
+ if(getClass() != obj.getClass()) {
return false;
}
LngLatDistanceFunction other = (LngLatDistanceFunction) obj;
- if (model == null) {
- if (other.model != null) {
+ if(model == null) {
+ if(other.model != null) {
return false;
}
- } else if (!model.equals(other.model)) {
+ }
+ else if(!model.equals(other.model)) {
return false;
}
return true;
@@ -137,7 +155,7 @@ public class LngLatDistanceFunction extends AbstractSpatialDoubleDistanceFunctio
protected void makeOptions(Parameterization config) {
super.makeOptions(config);
ObjectParameter<EarthModel> modelP = new ObjectParameter<>(EarthModel.MODEL_ID, EarthModel.class, SphericalVincentyEarthModel.class);
- if (config.grab(modelP)) {
+ if(config.grab(modelP)) {
model = modelP.instantiateClass(config);
}
}