Java Code Examples for org.locationtech.spatial4j.distance.DistanceUtils#radians2Dist()
The following examples show how to use
org.locationtech.spatial4j.distance.DistanceUtils#radians2Dist() .
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: GeoUnits.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static final double toMiles(double distance, IRI units) { final double miles; if (GEOF.UOM_METRE.equals(units)) { miles = DistanceUtils.KM_TO_MILES * distance / 1000.0; } else if (GEOF.UOM_DEGREE.equals(units)) { miles = DistanceUtils.degrees2Dist(distance, DistanceUtils.EARTH_MEAN_RADIUS_MI); } else if (GEOF.UOM_RADIAN.equals(units)) { miles = DistanceUtils.radians2Dist(distance, DistanceUtils.EARTH_MEAN_RADIUS_MI); } else if (GEOF.UOM_UNITY.equals(units)) { miles = distance * Math.PI * DistanceUtils.EARTH_MEAN_RADIUS_MI; } else { throw new IllegalArgumentException("Unsupported units: " + units); } return miles; }
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: 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); }); }