Search in sources :

Example 66 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class InternalGeoBounds method getProperty.

@Override
public Object getProperty(List<String> path) {
    if (path.isEmpty()) {
        return this;
    } else if (path.size() == 1) {
        BoundingBox boundingBox = resolveBoundingBox();
        String bBoxSide = path.get(0);
        switch(bBoxSide) {
            case "top":
                return boundingBox.topLeft.lat();
            case "left":
                return boundingBox.topLeft.lon();
            case "bottom":
                return boundingBox.bottomRight.lat();
            case "right":
                return boundingBox.bottomRight.lon();
            default:
                throw new IllegalArgumentException("Found unknown path element [" + bBoxSide + "] in [" + getName() + "]");
        }
    } else if (path.size() == 2) {
        BoundingBox boundingBox = resolveBoundingBox();
        GeoPoint cornerPoint = null;
        String cornerString = path.get(0);
        switch(cornerString) {
            case "top_left":
                cornerPoint = boundingBox.topLeft;
                break;
            case "bottom_right":
                cornerPoint = boundingBox.bottomRight;
                break;
            default:
                throw new IllegalArgumentException("Found unknown path element [" + cornerString + "] in [" + getName() + "]");
        }
        String latLonString = path.get(1);
        switch(latLonString) {
            case "lat":
                return cornerPoint.lat();
            case "lon":
                return cornerPoint.lon();
            default:
                throw new IllegalArgumentException("Found unknown path element [" + latLonString + "] in [" + getName() + "]");
        }
    } else {
        throw new IllegalArgumentException("path not supported for [" + getName() + "]: " + path);
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 67 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoCentroidAggregator method buildAggregation.

@Override
public InternalAggregation buildAggregation(long bucket) {
    if (valuesSource == null || bucket >= centroids.size()) {
        return buildEmptyAggregation();
    }
    final long bucketCount = counts.get(bucket);
    final long mortonCode = centroids.get(bucket);
    final GeoPoint bucketCentroid = (bucketCount > 0) ? new GeoPoint(GeoPointField.decodeLatitude(mortonCode), GeoPointField.decodeLongitude(mortonCode)) : null;
    return new InternalGeoCentroid(name, bucketCentroid, bucketCount, pipelineAggregators(), metaData());
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 68 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoPointFieldMapper method parse.

@Override
public Mapper parse(ParseContext context) throws IOException {
    context.path().add(simpleName());
    GeoPoint sparse = context.parseExternalValue(GeoPoint.class);
    if (sparse != null) {
        parse(context, sparse);
    } else {
        sparse = new GeoPoint();
        XContentParser.Token token = context.parser().currentToken();
        if (token == XContentParser.Token.START_ARRAY) {
            token = context.parser().nextToken();
            if (token == XContentParser.Token.START_ARRAY) {
                // its an array of array of lon/lat [ [1.2, 1.3], [1.4, 1.5] ]
                while (token != XContentParser.Token.END_ARRAY) {
                    try {
                        parse(context, GeoUtils.parseGeoPoint(context.parser(), sparse));
                    } catch (ElasticsearchParseException e) {
                        if (ignoreMalformed.value() == false) {
                            throw e;
                        }
                    }
                    token = context.parser().nextToken();
                }
            } else {
                // its an array of other possible values
                if (token == XContentParser.Token.VALUE_NUMBER) {
                    double lon = context.parser().doubleValue();
                    token = context.parser().nextToken();
                    double lat = context.parser().doubleValue();
                    while ((token = context.parser().nextToken()) != XContentParser.Token.END_ARRAY) ;
                    parse(context, sparse.reset(lat, lon));
                } else {
                    while (token != XContentParser.Token.END_ARRAY) {
                        if (token == XContentParser.Token.VALUE_STRING) {
                            parsePointFromString(context, sparse, context.parser().text());
                        } else {
                            try {
                                parse(context, GeoUtils.parseGeoPoint(context.parser(), sparse));
                            } catch (ElasticsearchParseException e) {
                                if (ignoreMalformed.value() == false) {
                                    throw e;
                                }
                            }
                        }
                        token = context.parser().nextToken();
                    }
                }
            }
        } else if (token == XContentParser.Token.VALUE_STRING) {
            parsePointFromString(context, sparse, context.parser().text());
        } else if (token != XContentParser.Token.VALUE_NULL) {
            try {
                parse(context, GeoUtils.parseGeoPoint(context.parser(), sparse));
            } catch (ElasticsearchParseException e) {
                if (ignoreMalformed.value() == false) {
                    throw e;
                }
            }
        }
    }
    context.path().remove();
    return null;
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 69 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoPointDVAtomicFieldData method getGeoPointValues.

@Override
public MultiGeoPointValues getGeoPointValues() {
    return new MultiGeoPointValues() {

        GeoPoint[] points = new GeoPoint[0];

        private int count = 0;

        @Override
        public void setDocument(int docId) {
            values.setDocument(docId);
            count = values.count();
            if (count > points.length) {
                final int previousLength = points.length;
                points = Arrays.copyOf(points, ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                for (int i = previousLength; i < points.length; ++i) {
                    points[i] = new GeoPoint(Double.NaN, Double.NaN);
                }
            }
            for (int i = 0; i < count; ++i) {
                points[i].resetFromIndexHash(values.valueAt(i));
            }
        }

        @Override
        public int count() {
            return count;
        }

        @Override
        public GeoPoint valueAt(int index) {
            return points[index];
        }
    };
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 70 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class LatLonPointDVAtomicFieldData method getGeoPointValues.

@Override
public MultiGeoPointValues getGeoPointValues() {
    return new MultiGeoPointValues() {

        GeoPoint[] points = new GeoPoint[0];

        private int count = 0;

        @Override
        public void setDocument(int docId) {
            values.setDocument(docId);
            count = values.count();
            if (count > points.length) {
                final int previousLength = points.length;
                points = Arrays.copyOf(points, ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                for (int i = previousLength; i < points.length; ++i) {
                    points[i] = new GeoPoint(Double.NaN, Double.NaN);
                }
            }
            long encoded;
            for (int i = 0; i < count; ++i) {
                encoded = values.valueAt(i);
                points[i].reset(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int) encoded));
            }
        }

        @Override
        public int count() {
            return count;
        }

        @Override
        public GeoPoint valueAt(int index) {
            return points[index];
        }
    };
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Aggregations

GeoPoint (org.elasticsearch.common.geo.GeoPoint)122 SearchResponse (org.elasticsearch.action.search.SearchResponse)40 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)27 ArrayList (java.util.ArrayList)20 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)15 XContentParser (org.elasticsearch.common.xcontent.XContentParser)9 GeoBounds (org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds)9 Range (org.elasticsearch.search.aggregations.bucket.range.Range)8 GeoCentroid (org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid)8 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)7 Version (org.elasticsearch.Version)7 Bucket (org.elasticsearch.search.aggregations.bucket.range.Range.Bucket)7 Settings (org.elasticsearch.common.settings.Settings)6 MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)6 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)5 ParsingException (org.elasticsearch.common.ParsingException)5 SearchHit (org.elasticsearch.search.SearchHit)5 Test (org.testng.annotations.Test)5 HashSet (java.util.HashSet)4 DistanceUnit (org.elasticsearch.common.unit.DistanceUnit)4