public GeoPoint resetFromIndexableField(IndexableField field) { if (field instanceof LatLonPoint) { BytesRef br = field.binaryValue(); byte[] bytes = Arrays.copyOfRange(br.bytes, br.offset, br.length); return this.reset( GeoEncodingUtils.decodeLatitude(bytes, 0), GeoEncodingUtils.decodeLongitude(bytes, Integer.BYTES)); } else if (field instanceof LatLonDocValuesField) { long encoded = (long)(field.numericValue()); return this.reset( GeoEncodingUtils.decodeLatitude((int)(encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int)encoded)); } return resetFromIndexHash(Long.parseLong(field.stringValue())); }
public GeoPoint resetFromString(String value, final boolean ignoreZValue) { if (value.contains(",")) { String[] vals = value.split(","); if (vals.length > 3) { throw new ElasticsearchParseException("failed to parse [{}], expected 2 or 3 coordinates " + "but found: [{}]", vals.length); } final double lat; final double lon; try { lat = Double.parseDouble(vals[0].trim()); } catch (NumberFormatException ex) { throw new ElasticsearchParseException("latitude must be a number"); } try { lon = Double.parseDouble(vals[1].trim()); } catch (NumberFormatException ex) { throw new ElasticsearchParseException("longitude must be a number"); } if (vals.length > 2) { GeoPoint.assertZValue(ignoreZValue, Double.parseDouble(vals[2].trim())); } return reset(lat, lon); } return resetFromGeoHash(value); }
spare.reset(latField.numericValue().doubleValue(), lonField.numericValue().doubleValue()); geohashes.add(stringEncode(spare.getLon(), spare.getLat(), precision));
@Override public GeoPoint nextValue() throws IOException { final long encoded = numericValues.nextValue(); point.reset(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int) encoded)); return point; } };
@Override public GeoPoint get(int docID) { final int ord = singleOrds.getOrd(docID); if (ord >= 0) { return point.resetFromIndexHash(indexedPoints.get(ord)); } return point.reset(Double.NaN, Double.NaN); } };
/** parse a {@link GeoPoint} from a String */ public static GeoPoint parseGeoPoint(String data, GeoPoint point) { int comma = data.indexOf(','); if(comma > 0) { double lat = Double.parseDouble(data.substring(0, comma).trim()); double lon = Double.parseDouble(data.substring(comma + 1).trim()); return point.reset(lat, lon); } else { return point.resetFromGeoHash(data); } }
public GeoPoint resetFromGeoHash(String geohash) { final long hash; try { hash = mortonEncode(geohash); } catch (IllegalArgumentException ex) { throw new ElasticsearchParseException(ex.getMessage(), ex); } return this.reset(GeoHashUtils.decodeLatitude(hash), GeoHashUtils.decodeLongitude(hash)); }
@Override public GeoPoint get(int docID) { if (set == null || set.get(docID)) { return point.resetFromIndexHash(indexedPoint.get(docID)); } return point.reset(Double.NaN, Double.NaN); } };
/** * Normalize the geo {@code Point} for the given coordinates to lie within * their respective normalized ranges. * <p> * You can control which coordinate gets normalized with the two flags. * <p> * Note: A shift of 180° is applied in the longitude if necessary, * in order to normalize properly the latitude. * If normalizing latitude but not longitude, it is assumed that * the longitude is in the form x+k*360, with x in ]-180;180], * and k is meaningful to the application. * Therefore x will be adjusted while keeping k preserved. * * @param point The point to normalize in-place. * @param normLat Whether to normalize latitude or leave it as is. * @param normLon Whether to normalize longitude. */ public static void normalizePoint(GeoPoint point, boolean normLat, boolean normLon) { double[] pt = {point.lon(), point.lat()}; normalizePoint(pt, normLon, normLat); point.reset(pt[1], pt[0]); }
static void parseGeoPoints(XContentParser parser, List<GeoPoint> geoPoints) throws IOException { while (!parser.nextToken().equals(XContentParser.Token.END_ARRAY)) { if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) { // we might get here if the geo point is " number, number] " and the parser already moved over the // opening bracket in this case we cannot use GeoUtils.parseGeoPoint(..) because this expects an opening // bracket double lon = parser.doubleValue(); parser.nextToken(); if (!parser.currentToken().equals(XContentParser.Token.VALUE_NUMBER)) { throw new ElasticsearchParseException( "geo point parsing: expected second number but got [{}] instead", parser.currentToken()); } double lat = parser.doubleValue(); GeoPoint point = new GeoPoint(); point.reset(lat, lon); geoPoints.add(point); } else { GeoPoint point = new GeoPoint(); GeoUtils.parseGeoPoint(parser, point); geoPoints.add(point); } } }
public static void decodeCell(String key, org.elasticsearch.common.geo.GeoPoint northWest, org.elasticsearch.common.geo.GeoPoint southEast) { try { double[] interval = (double[]) decodeCell.invoke(null, key); northWest.reset(interval[1], interval[2]); southEast.reset(interval[0], interval[3]); } catch (Exception e) { throw new VertexiumException("Could not decode cell", e); } } }
/** Decode a geo point from the bits of the encoded latitude and longitudes. */ public GeoPoint decode(long latBits, long lonBits, GeoPoint out) { final double lat = decodeCoordinate(latBits); final double lon = decodeCoordinate(lonBits); return out.reset(lat, lon); }
@Override protected void updateMinMax(org.elasticsearch.common.geo.GeoPoint min, org.elasticsearch.common.geo.GeoPoint max) { minValue.reset(Math.min(min.lat(), minValue.lat()), Math.min(min.lon(), minValue.lon())); maxValue.reset(Math.max(max.lat(), maxValue.lat()), Math.max(max.lon(), maxValue.lon())); }
@Override public GeoPoint nextValue() throws IOException { final long encoded = numericValues.nextValue(); point.reset(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int) encoded)); return point; } };
public GeoPoint resetFromGeoHash(String geohash) { final long hash; try { hash = mortonEncode(geohash); } catch (IllegalArgumentException ex) { throw new ElasticsearchParseException(ex.getMessage(), ex); } return this.reset(GeoHashUtils.decodeLatitude(hash), GeoHashUtils.decodeLongitude(hash)); }
throw new ElasticsearchParseException("[{}] field type does not accept > 3 dimensions", CONTENT_TYPE); parse(context, sparse.reset(lat, lon)); } else { while (token != XContentParser.Token.END_ARRAY) {