/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
@Override public boolean eval(Condition condition, Item item, Map<String, Object> context, ConditionEvaluatorDispatcher dispatcher) { try { String type = (String) condition.getParameter("type"); Double latitudeProperty = Double.parseDouble(BeanUtils.getProperty(item, "properties.location.lat")); Double longitudeProperty = Double.parseDouble(BeanUtils.getProperty(item, "properties.location.lon")); if("circle".equals(type)) { Double circleLatitude = (Double) condition.getParameter("circleLatitude"); Double circleLongitude = (Double) condition.getParameter("circleLongitude"); DistanceUnit.Distance distance = DistanceUnit.Distance.parseDistance(condition.getParameter("distance").toString()); double d = GeoDistance.PLANE.calculate(circleLatitude, circleLongitude, latitudeProperty, longitudeProperty, distance.unit); return d < distance.value; } else if("rectangle".equals(type)) { Double rectLatitudeNE = (Double) condition.getParameter("rectLatitudeNE"); Double rectLongitudeNE = (Double) condition.getParameter("rectLongitudeNE"); Double rectLatitudeSW = (Double) condition.getParameter("rectLatitudeSW"); Double rectLongitudeSW = (Double) condition.getParameter("rectLongitudeSW"); if(rectLatitudeNE != null && rectLongitudeNE != null && rectLatitudeSW != null && rectLongitudeSW != null) { return latitudeProperty < Math.max(rectLatitudeNE, rectLatitudeSW) && latitudeProperty > Math.min(rectLatitudeNE, rectLatitudeSW) && longitudeProperty < Math.max(rectLongitudeNE, rectLongitudeSW) && longitudeProperty > Math.min(rectLongitudeNE, rectLongitudeSW); } } } catch (Exception e) { logger.debug("Cannot get properties", e); } return false; }
radius = DistanceUnit.Distance.parseDistance(parser.text()); } else if (ShapeParser.FIELD_ORIENTATION.match(fieldName, parser.getDeprecationHandler())) { if (shapeType != null
radius = DistanceUnit.Distance.parseDistance(parser.text()); } else if (ShapeParser.FIELD_ORIENTATION.match(fieldName, parser.getDeprecationHandler())) { if (shapeType != null
} else if (CircleBuilder.FIELD_RADIUS.equals(fieldName)) { parser.nextToken(); radius = Distance.parseDistance(parser.text()); } else if (FIELD_ORIENTATION.equals(fieldName)) { parser.nextToken();
} else if (CircleBuilder.FIELD_RADIUS.equals(fieldName)) { parser.nextToken(); radius = Distance.parseDistance(parser.text()); } else if (FIELD_ORIENTATION.equals(fieldName)) { parser.nextToken();
QueryBuilders.geoDistanceQuery(fieldName).point(lat, lon).distance(unitDist, unit), ScoreFunctionBuilders.linearDecayFunction(fieldName, GeohashUtils.encodeLatLon(lat, lon), new DistanceUnit.Distance(unitDist, unit))); if (contextVar != null) { qb = addContextTerm(qb, (Resource)contextVar.getValue());
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
private Encoding(int numBytes) { assert numBytes >= 1 && numBytes <= MAX_NUM_BYTES; assert (numBytes & 1) == 0; // we don't support odd numBytes for the moment this.numBytes = numBytes; this.numBytesPerCoordinate = numBytes / 2; this.factor = Math.pow(2, - numBytesPerCoordinate * 8 + 9); assert (1L << (numBytesPerCoordinate * 8 - 1)) * factor > 180 && (1L << (numBytesPerCoordinate * 8 - 2)) * factor < 180 : numBytesPerCoordinate + " " + factor; if (numBytes == MAX_NUM_BYTES) { // no precision loss compared to a double precision = new DistanceUnit.Distance(0, DistanceUnit.DEFAULT); } else { // factor/2 because we use Math.round instead of a cast to convert the double to a long precision = new DistanceUnit.Distance( GeoDistance.PLANE.calculate(0, 0, factor / 2, factor / 2, DistanceUnit.DEFAULT), DistanceUnit.DEFAULT); } }
private Encoding(int numBytes) { assert numBytes >= 1 && numBytes <= MAX_NUM_BYTES; assert (numBytes & 1) == 0; // we don't support odd numBytes for the moment this.numBytes = numBytes; this.numBytesPerCoordinate = numBytes / 2; this.factor = Math.pow(2, - numBytesPerCoordinate * 8 + 9); assert (1L << (numBytesPerCoordinate * 8 - 1)) * factor > 180 && (1L << (numBytesPerCoordinate * 8 - 2)) * factor < 180 : numBytesPerCoordinate + " " + factor; if (numBytes == MAX_NUM_BYTES) { // no precision loss compared to a double precision = new DistanceUnit.Distance(0, DistanceUnit.DEFAULT); } else { precision = new DistanceUnit.Distance( GeoDistance.PLANE.calculate(0, 0, factor / 2, factor / 2, DistanceUnit.DEFAULT), // factor/2 because we use Math.round instead of a cast to convert the double to a long DistanceUnit.DEFAULT); } }
/** * Converts a {@link Distance} value given in a specific {@link DistanceUnit} into * a value equal to the specified value but in a other {@link DistanceUnit}. * * @param unit unit of the result * @return converted distance */ public Distance convert(DistanceUnit unit) { if(this.unit == unit) { return this; } else { return new Distance(DistanceUnit.convert(value, this.unit, unit), unit); } }
/** Get an instance based on the expected precision. Here are examples of the number of required bytes per value * depending on the * expected precision:<ul> * <li>1km: 4 bytes</li> * <li>3m: 6 bytes</li> * <li>1m: 8 bytes</li> * <li>1cm: 8 bytes</li> * <li>1mm: 10 bytes</li></ul> */ public static Encoding of(DistanceUnit.Distance precision) { for (Encoding encoding : INSTANCES) { if (encoding != null && encoding.precision().compareTo(precision) <= 0) { return encoding; } } return INSTANCES[MAX_NUM_BYTES]; }
/** Get an instance based on the expected precision. Here are examples of the number of required bytes per value depending on the * expected precision:<ul> * <li>1km: 4 bytes</li> * <li>3m: 6 bytes</li> * <li>1m: 8 bytes</li> * <li>1cm: 8 bytes</li> * <li>1mm: 10 bytes</li></ul> */ public static final Encoding of(DistanceUnit.Distance precision) { for (Encoding encoding : INSTANCES) { if (encoding != null && encoding.precision().compareTo(precision) <= 0) { return encoding; } } return INSTANCES[MAX_NUM_BYTES]; }
/** * Converts a {@link Distance} value given in a specific {@link DistanceUnit} into * a value equal to the specified value but in a other {@link DistanceUnit}. * * @param unit unit of the result * @return converted distance */ public Distance convert(DistanceUnit unit) { if(this.unit == unit) { return this; } else { return new Distance(DistanceUnit.convert(value, this.unit, unit), unit); } }
/** * Parse a {@link Distance} from a given String. If no unit is given * <code>DistanceUnit.DEFAULT</code> will be used * * @param distance String defining a {@link Distance} * @return parsed {@link Distance} */ public static Distance parseDistance(String distance) { return parseDistance(distance, DEFAULT); }
/** * Set the radius of the circle. The String value will be parsed by {@link DistanceUnit} * @param radius Value and unit of the circle combined in a string * @return this */ public CircleBuilder radius(String radius) { return radius(DistanceUnit.Distance.parseDistance(radius)); }
/** * Set the radius of the circle. The String value will be parsed by {@link DistanceUnit} * @param radius Value and unit of the circle combined in a string * @return this */ public CircleBuilder radius(String radius) { return radius(DistanceUnit.Distance.parseDistance(radius)); }
/** * Converts a {@link Distance} value given in a specific {@link DistanceUnit} into * a value equal to the specified value but in a other {@link DistanceUnit}. * * @param unit unit of the result * @return converted distance */ public Distance convert(DistanceUnit unit) { if(this.unit == unit) { return this; } else { return new Distance(DistanceUnit.convert(value, this.unit, unit), unit); } }