Java Code Examples for org.elasticsearch.common.geo.GeoPoint#lat()

The following examples show how to use org.elasticsearch.common.geo.GeoPoint#lat() . These examples are extracted from open source projects. 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
@Override
protected void parse(ParseContext context, GeoPoint point, String geoHash) throws IOException {
    if (ignoreMalformed.value() == false) {
        if (point.lat() > 90.0 || point.lat() < -90.0) {
            throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name());
        }
        if (point.lon() > 180.0 || point.lon() < -180) {
            throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name());
        }
    } else {
        // LUCENE WATCH: This will be folded back into Lucene's GeoPointField
        GeoUtils.normalizePoint(point);
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        context.doc().add(new GeoPointField(fieldType().names().indexName(), point.lon(), point.lat(), fieldType() ));
    }
    super.parse(context, point, geoHash);
}
 
Example 2
@Override
public Double[] value() {
    switch (values.count()) {
        case 0:
            return null;
        case 1:
            GeoPoint gp = values.valueAt(0);
            return new Double[] { gp.lon(), gp.lat() };
        default:
            throw new GroupByOnArrayUnsupportedException(columnName());
    }
}
 
Example 3
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final MultiGeoPointValues values = valuesSource.geoPointValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            centroids = bigArrays.grow(centroids, bucket + 1);
            counts = bigArrays.grow(counts, bucket + 1);

            values.setDocument(doc);
            final int valueCount = values.count();
            if (valueCount > 0) {
                double[] pt = new double[2];
                // get the previously accumulated number of counts
                long prevCounts = counts.get(bucket);
                // increment by the number of points for this document
                counts.increment(bucket, valueCount);
                // get the previous GeoPoint if a moving avg was computed
                if (prevCounts > 0) {
                    final GeoPoint centroid = GeoPoint.fromIndexLong(centroids.get(bucket));
                    pt[0] = centroid.lon();
                    pt[1] = centroid.lat();
                }
                // update the moving average
                for (int i = 0; i < valueCount; ++i) {
                    GeoPoint value = values.valueAt(i);
                    pt[0] = pt[0] + (value.getLon() - pt[0]) / ++prevCounts;
                    pt[1] = pt[1] + (value.getLat() - pt[1]) / prevCounts;
                }
                centroids.set(bucket, GeoEncodingUtils.mortonHash(pt[0], pt[1]));
            }
        }
    };
}
 
Example 4
@Override
public boolean get(int doc) {
    values.setDocument(doc);
    final int length = values.count();
    for (int i = 0; i < length; i++) {
        GeoPoint point = values.valueAt(i);
        if (((topLeft.lon() <= point.lon() || bottomRight.lon() >= point.lon())) &&
                (topLeft.lat() >= point.lat() && bottomRight.lat() <= point.lat())) {
            return true;
        }
    }
    return false;
}
 
Example 5
@Override
public boolean get(int doc) {
    values.setDocument(doc);
    final int length = values.count();
    for (int i = 0; i < length; i++) {
        GeoPoint point = values.valueAt(i);
        if (topLeft.lon() <= point.lon() && bottomRight.lon() >= point.lon()
                && topLeft.lat() >= point.lat() && bottomRight.lat() <= point.lat()) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source Project: crate   File: GeoPointFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
protected void parse(ParseContext context, GeoPoint point) throws IOException {

        if (ignoreMalformed.value() == false) {
            if (point.lat() > 90.0 || point.lat() < -90.0) {
                throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name());
            }
            if (point.lon() > 180.0 || point.lon() < -180) {
                throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name());
            }
        } else {
            GeoUtils.normalizePoint(point);
        }
        if (fieldType().indexOptions() != IndexOptions.NONE) {
            context.doc().add(new LatLonPoint(fieldType().name(), point.lat(), point.lon()));
        }
        if (fieldType().stored()) {
            context.doc().add(new StoredField(fieldType().name(), point.toString()));
        }
        if (fieldType.hasDocValues()) {
            context.doc().add(new LatLonDocValuesField(fieldType().name(), point.lat(), point.lon()));
        } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) {
            List<IndexableField> fields = new ArrayList<>(1);
            createFieldNamesField(context, fields);
            for (IndexableField field : fields) {
                context.doc().add(field);
            }
        }
        // if the mapping contains multifields then use the geohash string
        if (multiFields.iterator().hasNext()) {
            multiFields.parse(this, context.createExternalValueContext(point.geohash()));
        }
    }
 
Example 7
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        LeafBucketCollector sub) {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final MultiGeoPointValues values = valuesSource.geoPointValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= tops.size()) {
                long from = tops.size();
                tops = bigArrays.grow(tops, bucket + 1);
                tops.fill(from, tops.size(), Double.NEGATIVE_INFINITY);
                bottoms = bigArrays.resize(bottoms, tops.size());
                bottoms.fill(from, bottoms.size(), Double.POSITIVE_INFINITY);
                posLefts = bigArrays.resize(posLefts, tops.size());
                posLefts.fill(from, posLefts.size(), Double.POSITIVE_INFINITY);
                posRights = bigArrays.resize(posRights, tops.size());
                posRights.fill(from, posRights.size(), Double.NEGATIVE_INFINITY);
                negLefts = bigArrays.resize(negLefts, tops.size());
                negLefts.fill(from, negLefts.size(), Double.POSITIVE_INFINITY);
                negRights = bigArrays.resize(negRights, tops.size());
                negRights.fill(from, negRights.size(), Double.NEGATIVE_INFINITY);
            }

            values.setDocument(doc);
            final int valuesCount = values.count();

            for (int i = 0; i < valuesCount; ++i) {
                GeoPoint value = values.valueAt(i);
                double top = tops.get(bucket);
                if (value.lat() > top) {
                    top = value.lat();
                }
                double bottom = bottoms.get(bucket);
                if (value.lat() < bottom) {
                    bottom = value.lat();
                }
                double posLeft = posLefts.get(bucket);
                if (value.lon() >= 0 && value.lon() < posLeft) {
                    posLeft = value.lon();
                }
                double posRight = posRights.get(bucket);
                if (value.lon() >= 0 && value.lon() > posRight) {
                    posRight = value.lon();
                }
                double negLeft = negLefts.get(bucket);
                if (value.lon() < 0 && value.lon() < negLeft) {
                    negLeft = value.lon();
                }
                double negRight = negRights.get(bucket);
                if (value.lon() < 0 && value.lon() > negRight) {
                    negRight = value.lon();
                }
                tops.set(bucket, top);
                bottoms.set(bucket, bottom);
                posLefts.set(bucket, posLeft);
                posRights.set(bucket, posRight);
                negLefts.set(bucket, negLeft);
                negRights.set(bucket, negRight);
            }
        }
    };
}
 
Example 8
Source Project: Elasticsearch   File: ScriptDocValues.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public GeoPoint get(int index) {
    final GeoPoint point = values.valueAt(index);
    return new GeoPoint(point.lat(), point.lon());
}