Package org.elasticsearch.common.geo

Examples of org.elasticsearch.common.geo.GeoPoint


        @Override
        public MultiGeoPointValues getGeoPointValues() {
            final RandomAccessOrds ords = ordinals.ordinals();
            final SortedDocValues singleOrds = DocValues.unwrapSingleton(ords);
            if (singleOrds != null) {
                final GeoPoint point = new GeoPoint();
                final GeoPointValues values = new GeoPointValues() {
                    @Override
                    public GeoPoint get(int docID) {
                        final int ord = singleOrds.getOrd(docID);
                        if (ord >= 0) {
                            encoding.decode(lat.get(ord), lon.get(ord), point);
                        } else {
                            point.reset(0, 0);
                        }
                        return point;
                    }
                };
                return FieldData.singleton(values, DocValues.docsWithValue(singleOrds, maxDoc));
            } else {
                final GeoPoint point = new GeoPoint();
                return new MultiGeoPointValues() {

                    @Override
                    public GeoPoint valueAt(int index) {
                        final long ord = ords.ordAt(index);
View Full Code Here


            return Collections.unmodifiableList(resources);
        }

        @Override
        public MultiGeoPointValues getGeoPointValues() {
            final GeoPoint point = new GeoPoint();
            final GeoPointValues values = new GeoPointValues() {
                @Override
                public GeoPoint get(int docID) {
                    encoding.decode(lat.get(docID), lon.get(docID), point);
                    return point;
View Full Code Here

                if ("nested_filter".equals(currentName) || "nestedFilter".equals(currentName)) {
                    ParsedFilter parsedFilter = context.queryParserService().parseInnerFilter(parser);
                    nestedFilter = parsedFilter == null ? null : parsedFilter.filter();
                } else {
                    fieldName = currentName;
                    GeoPoint point = new GeoPoint();
                    GeoUtils.parseGeoPoint(parser, point);
                    geoPoints.add(point);
                }
            } else if (token.isValue()) {
                if ("reverse".equals(currentName)) {
                    reverse = parser.booleanValue();
                } else if ("order".equals(currentName)) {
                    reverse = "desc".equals(parser.text());
                } else if (currentName.equals("unit")) {
                    unit = DistanceUnit.fromString(parser.text());
                } else if (currentName.equals("distance_type") || currentName.equals("distanceType")) {
                    geoDistance = GeoDistance.fromString(parser.text());
                } else if ("normalize".equals(currentName)) {
                    normalizeLat = parser.booleanValue();
                    normalizeLon = parser.booleanValue();
                } else if ("sort_mode".equals(currentName) || "sortMode".equals(currentName) || "mode".equals(currentName)) {
                    sortMode = MultiValueMode.fromString(parser.text());
                } else if ("nested_path".equals(currentName) || "nestedPath".equals(currentName)) {
                    nestedPath = parser.text();
                } else {
                    GeoPoint point = new GeoPoint();
                    point.resetFromString(parser.text());
                    geoPoints.add(point);
                    fieldName = currentName;
                }
            }
        }
View Full Code Here

                parser.nextToken();
                if (!parser.currentToken().equals(XContentParser.Token.VALUE_NUMBER)) {
                    throw new ElasticsearchParseException("geo point parsing: expected second number but got" + 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);
            }

        }
View Full Code Here

    @Override
    public GeoQuery parseQuery(String name, XContentParser parser) throws IOException, ElasticsearchParseException {
        if (parser.currentToken() == Token.START_OBJECT) {
            double lat = Double.NaN;
            double lon = Double.NaN;
            GeoPoint point = null;
            int[] precision = null;
           
            while (parser.nextToken() != Token.END_OBJECT) {
                final String fieldName = parser.text();
                if("lat".equals(fieldName)) {
                    if(point == null) {
                        parser.nextToken();
                        switch (parser.currentToken()) {
                            case VALUE_NUMBER:
                            case VALUE_STRING:
                                lat = parser.doubleValue(true);
                                break;
                            default:
                                throw new ElasticsearchParseException("latitude must be a number");
                        }
                    } else {
                        throw new ElasticsearchParseException("only lat/lon or [" + FIELD_VALUE + "] is allowed");
                    }
                } else if ("lon".equals(fieldName)) {
                    if(point == null) {
                        parser.nextToken();
                        switch (parser.currentToken()) {
                            case VALUE_NUMBER:
                            case VALUE_STRING:
                                lon = parser.doubleValue(true);
                                break;
                            default:
                                throw new ElasticsearchParseException("longitude must be a number");
                        }
                    } else {
                        throw new ElasticsearchParseException("only lat/lon or [" + FIELD_VALUE + "] is allowed");
                    }
                } else if (FIELD_PRECISION.equals(fieldName)) {
                    if(parser.nextToken() == Token.START_ARRAY) {
                        IntOpenHashSet precisions = new IntOpenHashSet();
                        while(parser.nextToken() != Token.END_ARRAY) {
                            precisions.add(parsePrecision(parser));
                        }
                        precision = precisions.toArray();
                    } else {
                        precision = new int[] { parsePrecision(parser) };
                    }
                } else if (FIELD_VALUE.equals(fieldName)) {
                    if(Double.isNaN(lon) && Double.isNaN(lat)) {
                        parser.nextToken();
                        point = GeoUtils.parseGeoPoint(parser);
                    } else {
                        throw new ElasticsearchParseException("only lat/lon or [" + FIELD_VALUE + "] is allowed");
                    }
                } else {
                    throw new ElasticsearchParseException("unexpected fieldname [" + fieldName + "]");
                }
            }

            if (point == null) {
                if (Double.isNaN(lat) || Double.isNaN(lon)) {
                    throw new ElasticsearchParseException("location is missing");
                } else {
                    point = new GeoPoint(lat, lon);
                }
            }

            if (precision == null || precision.length == 0) {
                precision = this.precision;
            }

            return new GeoQuery(name, point.geohash(), precision);
        } else {
            return new GeoQuery(name, GeoUtils.parseGeoPoint(parser).getGeohash(), precision);
        }
    }
View Full Code Here

                    if(fields.length == 0) {
                        IndexableField[] lonFields = doc.getFields(mapping.fieldName + ".lon");
                        IndexableField[] latFields = doc.getFields(mapping.fieldName + ".lat");
                        if (lonFields.length > 0 && latFields.length > 0) {
                            geohashes = new ArrayList<>(fields.length);
                            GeoPoint spare = new GeoPoint();
                            for (int i = 0 ; i < lonFields.length ; i++) {
                                IndexableField lonField = lonFields[i];
                                IndexableField latField = latFields[i];
                                assert lonField.fieldType().docValueType() == latField.fieldType().docValueType();
                                // we write doc values fields differently: one field for all values, so we need to only care about indexed fields
                                if (lonField.fieldType().docValueType() == DocValuesType.NONE) {
                                    spare.reset(latField.numericValue().doubleValue(), lonField.numericValue().doubleValue());
                                    geohashes.add(spare.geohash());
                                }
                            }
                        } else {
                            geohashes = mapping.defaultLocations;
                        }
                    } else {
                        geohashes = new ArrayList<>(fields.length);
                        GeoPoint spare = new GeoPoint();
                        for (IndexableField field : fields) {
                            spare.resetFromString(field.stringValue());
                            geohashes.add(spare.geohash());
                        }
                    }
                } else {
                    geohashes = mapping.defaultLocations;
                }
View Full Code Here

     *
     * @param lat latitude.
     * @param lon longitude.
     */
    public GeoDistanceSortBuilder point(double lat, double lon) {
        points.add(new GeoPoint(lat, lon));
        return this;
    }
View Full Code Here

    public void testGeoGetLatLon() {
        final double lat1 = randomLat();
        final double lat2 = randomLat();
        final double lon1 = randomLon();
        final double lon2 = randomLon();
        final MultiGeoPointValues values = wrap(new GeoPoint(lat1, lon1), new GeoPoint(lat2, lon2));
        final ScriptDocValues.GeoPoints script = new ScriptDocValues.GeoPoints(values);
        script.setNextDocId(1);
        assertEquals(true, script.isEmpty());
        script.setNextDocId(0);
        assertEquals(false, script.isEmpty());
        assertEquals(new GeoPoint(lat1, lon1), script.getValue());
        assertEquals(Arrays.asList(new GeoPoint(lat1, lon1), new GeoPoint(lat2, lon2)), script.getValues());
        assertEquals(lat1, script.getLat(), 0);
        assertEquals(lon1, script.getLon(), 0);
        assertTrue(Arrays.equals(new double[] {lat1, lat2}, script.getLats()));
        assertTrue(Arrays.equals(new double[] {lon1, lon2}, script.getLons()));
    }
View Full Code Here

    }

    public void testGeoDistance() {
        final double lat = randomLat();
        final double lon = randomLon();
        final MultiGeoPointValues values = wrap(new GeoPoint(lat, lon));
        final ScriptDocValues.GeoPoints script = new ScriptDocValues.GeoPoints(values);
        script.setNextDocId(0);

        final ScriptDocValues.GeoPoints emptyScript = new ScriptDocValues.GeoPoints(wrap());
        emptyScript.setNextDocId(0);
View Full Code Here

            final double lat = randomDouble() * 180 - 90;
            final double lon = randomDouble() * 360 - 180;
            final Distance precision = new Distance(1+(randomDouble() * 9), randomFrom(Arrays.asList(DistanceUnit.MILLIMETERS, DistanceUnit.METERS, DistanceUnit.KILOMETERS)));
            final GeoPointFieldMapper.Encoding encoding = GeoPointFieldMapper.Encoding.of(precision);
            assertThat(encoding.precision().convert(DistanceUnit.METERS).value, lessThanOrEqualTo(precision.convert(DistanceUnit.METERS).value));
            final GeoPoint geoPoint = encoding.decode(encoding.encodeCoordinate(lat), encoding.encodeCoordinate(lon), new GeoPoint());
            final double error = GeoDistance.PLANE.calculate(lat, lon, geoPoint.lat(), geoPoint.lon(), DistanceUnit.METERS);
            assertThat(error, lessThanOrEqualTo(precision.convert(DistanceUnit.METERS).value));
        }
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.geo.GeoPoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.