Java Code Examples for org.locationtech.spatial4j.distance.DistanceUtils#EARTH_MEAN_RADIUS_KM
The following examples show how to use
org.locationtech.spatial4j.distance.DistanceUtils#EARTH_MEAN_RADIUS_KM .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchDocumentDistance.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public double getDistance() { String geohash = (String) ((ElasticsearchDocument) getDocument()).getSource().get(geoPointField); GeoPoint dstPoint = GeoPoint.fromGeohash(geohash); double unitDist = GeoDistance.ARC.calculate(srcPoint.getLat(), srcPoint.getLon(), dstPoint.getLat(), dstPoint.getLon(), unit); double distance; if (GEOF.UOM_METRE.equals(units)) { distance = unit.toMeters(unitDist); } else if (GEOF.UOM_DEGREE.equals(units)) { distance = unitDist / unit.getDistancePerDegree(); } else if (GEOF.UOM_RADIAN.equals(units)) { distance = DistanceUtils.dist2Radians(unit.convert(unitDist, DistanceUnit.KILOMETERS), DistanceUtils.EARTH_MEAN_RADIUS_KM); } else if (GEOF.UOM_UNITY.equals(units)) { distance = unit.convert(unitDist, DistanceUnit.KILOMETERS) / (Math.PI * DistanceUtils.EARTH_MEAN_RADIUS_KM); } else { throw new UnsupportedOperationException("Unsupported units: " + units); } return distance; }
Example 2
Source File: GeoUnits.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static final double toKilometres(double distance, IRI units) { final double kms; if (GEOF.UOM_METRE.equals(units)) { kms = distance / 1000.0; } else if (GEOF.UOM_DEGREE.equals(units)) { kms = DistanceUtils.degrees2Dist(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM); } else if (GEOF.UOM_RADIAN.equals(units)) { kms = DistanceUtils.radians2Dist(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM); } else if (GEOF.UOM_UNITY.equals(units)) { kms = distance * Math.PI * DistanceUtils.EARTH_MEAN_RADIUS_KM; } else { throw new IllegalArgumentException("Unsupported units: " + units); } return kms; }
Example 3
Source File: GeoUnits.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static final double fromKilometres(double kms, IRI units) { double dist; if (GEOF.UOM_METRE.equals(units)) { dist = kms * 1000.0; } else if (GEOF.UOM_DEGREE.equals(units)) { dist = DistanceUtils.dist2Degrees(kms, DistanceUtils.EARTH_MEAN_RADIUS_KM); } else if (GEOF.UOM_RADIAN.equals(units)) { dist = DistanceUtils.dist2Radians(kms, DistanceUtils.EARTH_MEAN_RADIUS_KM); } else if (GEOF.UOM_UNITY.equals(units)) { dist = kms / (Math.PI * DistanceUtils.EARTH_MEAN_RADIUS_KM); } else { throw new IllegalArgumentException("Unsupported units: " + units); } return dist; }
Example 4
Source File: ElasticsearchIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected Iterable<? extends DocumentDistance> geoQuery(final IRI geoProperty, Point p, final IRI units, double distance, String distanceVar, Var contextVar) throws MalformedQueryException, IOException { double unitDist; final DistanceUnit unit; if (GEOF.UOM_METRE.equals(units)) { unit = DistanceUnit.METERS; unitDist = distance; } else if (GEOF.UOM_DEGREE.equals(units)) { unit = DistanceUnit.KILOMETERS; unitDist = unit.getDistancePerDegree() * distance; } else if (GEOF.UOM_RADIAN.equals(units)) { unit = DistanceUnit.KILOMETERS; unitDist = DistanceUtils.radians2Dist(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM); } else if (GEOF.UOM_UNITY.equals(units)) { unit = DistanceUnit.KILOMETERS; unitDist = distance * Math.PI * DistanceUtils.EARTH_MEAN_RADIUS_KM; } else { throw new MalformedQueryException("Unsupported units: " + units); } double lat = p.getY(); double lon = p.getX(); final String fieldName = toGeoPointFieldName(SearchFields.getPropertyField(geoProperty)); QueryBuilder qb = QueryBuilders.functionScoreQuery( QueryBuilders.geoDistanceQuery(fieldName).point(lat, lon).distance(unitDist, unit), ScoreFunctionBuilders.linearDecayFunction(fieldName, GeohashUtils.encodeLatLon(lat, lon), new DistanceUnit.Distance(unitDist, unit).toString())); if (contextVar != null) { qb = addContextTerm(qb, (Resource) contextVar.getValue()); } SearchRequestBuilder request = client.prepareSearch(); SearchHits hits = search(request, qb); final GeoPoint srcPoint = new GeoPoint(lat, lon); return Iterables.transform(hits, (Function<SearchHit, DocumentDistance>) hit -> { return new ElasticsearchDocumentDistance(hit, geoContextMapper, fieldName, units, srcPoint, unit); }); }
Example 5
Source File: PointType.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public double getSphereRadius() { // This won't likely be used. You should probably be using LatLonType instead if you felt the need for this. // This is here just for backward compatibility reasons. return DistanceUtils.EARTH_MEAN_RADIUS_KM; }
Example 6
Source File: GeoHashField.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public double getSphereRadius() { return DistanceUtils.EARTH_MEAN_RADIUS_KM; }
Example 7
Source File: LatLonType.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public double getSphereRadius() { return DistanceUtils.EARTH_MEAN_RADIUS_KM; }