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);
}
}
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());
}
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;
}
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];
}
};
}
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];
}
};
}
Aggregations