本文整理汇总了Java中org.elasticsearch.common.geo.GeoPoint类的典型用法代码示例。如果您正苦于以下问题:Java GeoPoint类的具体用法?Java GeoPoint怎么用?Java GeoPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeoPoint类属于org.elasticsearch.common.geo包,在下文中一共展示了GeoPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GeoBoundsAggregator
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
protected GeoBoundsAggregator(String name, SearchContext aggregationContext, Aggregator parent,
ValuesSource.GeoPoint valuesSource, boolean wrapLongitude, List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {
super(name, aggregationContext, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.wrapLongitude = wrapLongitude;
if (valuesSource != null) {
final BigArrays bigArrays = context.bigArrays();
tops = bigArrays.newDoubleArray(1, false);
tops.fill(0, tops.size(), Double.NEGATIVE_INFINITY);
bottoms = bigArrays.newDoubleArray(1, false);
bottoms.fill(0, bottoms.size(), Double.POSITIVE_INFINITY);
posLefts = bigArrays.newDoubleArray(1, false);
posLefts.fill(0, posLefts.size(), Double.POSITIVE_INFINITY);
posRights = bigArrays.newDoubleArray(1, false);
posRights.fill(0, posRights.size(), Double.NEGATIVE_INFINITY);
negLefts = bigArrays.newDoubleArray(1, false);
negLefts.fill(0, negLefts.size(), Double.POSITIVE_INFINITY);
negRights = bigArrays.newDoubleArray(1, false);
negRights.fill(0, negRights.size(), Double.NEGATIVE_INFINITY);
}
}
示例2: resolveBoundingBox
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
private BoundingBox resolveBoundingBox() {
if (Double.isInfinite(top)) {
return null;
} else if (Double.isInfinite(posLeft)) {
return new BoundingBox(new GeoPoint(top, negLeft), new GeoPoint(bottom, negRight));
} else if (Double.isInfinite(negLeft)) {
return new BoundingBox(new GeoPoint(top, posLeft), new GeoPoint(bottom, posRight));
} else if (wrapLongitude) {
double unwrappedWidth = posRight - negLeft;
double wrappedWidth = (180 - posLeft) - (-180 - negRight);
if (unwrappedWidth <= wrappedWidth) {
return new BoundingBox(new GeoPoint(top, negLeft), new GeoPoint(bottom, posRight));
} else {
return new BoundingBox(new GeoPoint(top, posLeft), new GeoPoint(bottom, negRight));
}
} else {
return new BoundingBox(new GeoPoint(top, negLeft), new GeoPoint(bottom, posRight));
}
}
示例3: testNormalizePointOutsideNormalRange
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
public void testNormalizePointOutsideNormalRange() {
for (int i = 0; i < 100; i++) {
double normalisedLat = (randomDouble() * 180.0) - 90.0;
double normalisedLon = (randomDouble() * 360.0) - 180.0;
int shiftLat = (randomBoolean() ? 1 : -1) * randomIntBetween(1, 10000);
int shiftLon = (randomBoolean() ? 1 : -1) * randomIntBetween(1, 10000);
double testLat = normalisedLat + (180.0 * shiftLat);
double testLon = normalisedLon + (360.0 * shiftLon);
double expectedLat = normalisedLat * (shiftLat % 2 == 0 ? 1 : -1);
double expectedLon = normalisedLon + (shiftLat % 2 == 0 ? 0 : 180);
if (expectedLon > 180.0) {
expectedLon -= 360;
}
GeoPoint testPoint = new GeoPoint(testLat, testLon);
GeoPoint expectedPoint = new GeoPoint(expectedLat, expectedLon);
assertNormalizedPoint(testPoint, expectedPoint);
}
}
示例4: innerBuild
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
@Override
protected ValuesSourceAggregatorFactory<ValuesSource.GeoPoint, ?> innerBuild(SearchContext context,
ValuesSourceConfig<ValuesSource.GeoPoint> config, AggregatorFactory<?> parent, Builder subFactoriesBuilder)
throws IOException {
int shardSize = this.shardSize;
int requiredSize = this.requiredSize;
if (shardSize < 0) {
// Use default heuristic to avoid any wrong-ranking caused by
// distributed counting
shardSize = BucketUtils.suggestShardSideQueueSize(requiredSize, context.numberOfShards());
}
if (requiredSize <= 0 || shardSize <= 0) {
throw new ElasticsearchException(
"parameters [required_size] and [shard_size] must be >0 in geohash_grid aggregation [" + name + "].");
}
if (shardSize < requiredSize) {
shardSize = requiredSize;
}
return new GeoHashGridAggregatorFactory(name, config, precision, requiredSize, shardSize, context, parent,
subFactoriesBuilder, metaData);
}
示例5: originalValuesSource
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
/**
* Return the original values source, before we apply `missing`.
*/
private <VS extends ValuesSource> VS originalValuesSource(ValuesSourceConfig<VS> config) throws IOException {
if (config.fieldContext == null) {
if (ValuesSource.Numeric.class.isAssignableFrom(config.valueSourceType)) {
return (VS) numericScript(config);
}
if (ValuesSource.Bytes.class.isAssignableFrom(config.valueSourceType)) {
return (VS) bytesScript(config);
}
throw new AggregationExecutionException("value source of type [" + config.valueSourceType.getSimpleName() + "] is not supported by scripts");
}
if (ValuesSource.Numeric.class.isAssignableFrom(config.valueSourceType)) {
return (VS) numericField(config);
}
if (ValuesSource.GeoPoint.class.isAssignableFrom(config.valueSourceType)) {
return (VS) geoPointField(config);
}
// falling back to bytes values
return (VS) bytesField(config);
}
示例6: getDistanceString
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
@Override
protected String getDistanceString(LeafReaderContext ctx, int docId) {
StringBuilder values = new StringBuilder(mode.name());
values.append(" of: [");
final MultiGeoPointValues geoPointValues = fieldData.load(ctx).getGeoPointValues();
geoPointValues.setDocument(docId);
final int num = geoPointValues.count();
if (num > 0) {
for (int i = 0; i < num; i++) {
GeoPoint value = geoPointValues.valueAt(i);
values.append("Math.max(arcDistance(");
values.append(value).append("(=doc value),");
values.append(origin).append("(=origin)) - ").append(offset).append("(=offset), 0)");
if (i != num - 1) {
values.append(", ");
}
}
} else {
values.append("0.0");
}
values.append("]");
return values.toString();
}
示例7: testGeoDistance
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
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);
final double otherLat = randomLat();
final double otherLon = randomLon();
assertEquals(GeoUtils.arcDistance(lat, lon, otherLat, otherLon) / 1000d,
script.arcDistance(otherLat, otherLon) / 1000d, 0.01);
assertEquals(GeoUtils.arcDistance(lat, lon, otherLat, otherLon) / 1000d,
script.arcDistanceWithDefault(otherLat, otherLon, 42) / 1000d, 0.01);
assertEquals(42, emptyScript.arcDistanceWithDefault(otherLat, otherLon, 42), 0);
assertEquals(GeoUtils.planeDistance(lat, lon, otherLat, otherLon) / 1000d,
script.planeDistance(otherLat, otherLon) / 1000d, 0.01);
assertEquals(GeoUtils.planeDistance(lat, lon, otherLat, otherLon) / 1000d,
script.planeDistanceWithDefault(otherLat, otherLon, 42) / 1000d, 0.01);
assertEquals(42, emptyScript.planeDistanceWithDefault(otherLat, otherLon, 42), 0);
}
示例8: GeoPolygonQueryBuilder
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
public GeoPolygonQueryBuilder(String fieldName, List<GeoPoint> points) {
if (Strings.isEmpty(fieldName)) {
throw new IllegalArgumentException("fieldName must not be null");
}
if (points == null || points.isEmpty()) {
throw new IllegalArgumentException("polygon must not be null or empty");
} else {
GeoPoint start = points.get(0);
if (start.equals(points.get(points.size() - 1))) {
if (points.size() < 4) {
throw new IllegalArgumentException("too few points defined for geo_polygon query");
}
} else {
if (points.size() < 3) {
throw new IllegalArgumentException("too few points defined for geo_polygon query");
}
}
}
this.fieldName = fieldName;
this.shell = new ArrayList<>(points);
if (!shell.get(shell.size() - 1).equals(shell.get(0))) {
shell.add(shell.get(0));
}
}
示例9: testMultiFieldSort
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
/**
* test array syntax variations:
* - "sort" : [ "fieldname", { "fieldname2" : "asc" }, ...]
*/
public void testMultiFieldSort() throws IOException {
String json = "{ \"sort\" : ["
+ "{ \"post_date\" : {\"order\" : \"asc\"}},"
+ "\"user\","
+ "{ \"name\" : \"desc\" },"
+ "{ \"age\" : \"desc\" },"
+ "{"
+ "\"_geo_distance\" : {"
+ "\"pin.location\" : \"40,-70\" } },"
+ "\"_score\""
+ "] }";
List<SortBuilder<?>> result = parseSort(json);
assertEquals(6, result.size());
assertEquals(new FieldSortBuilder("post_date").order(SortOrder.ASC), result.get(0));
assertEquals(new FieldSortBuilder("user").order(SortOrder.ASC), result.get(1));
assertEquals(new FieldSortBuilder("name").order(SortOrder.DESC), result.get(2));
assertEquals(new FieldSortBuilder("age").order(SortOrder.DESC), result.get(3));
assertEquals(new GeoDistanceSortBuilder("pin.location", new GeoPoint(40, -70)), result.get(4));
assertEquals(new ScoreSortBuilder(), result.get(5));
}
示例10: parse
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
@Override
public Mapper parse(ParseContext context) throws IOException {
byte[] bytes = "Hello world".getBytes(Charset.defaultCharset());
binMapper.parse(context.createExternalValueContext(bytes));
boolMapper.parse(context.createExternalValueContext(true));
// Let's add a Dummy Point
Double lat = 42.0;
Double lng = 51.0;
GeoPoint point = new GeoPoint(lat, lng);
pointMapper.parse(context.createExternalValueContext(point));
// Let's add a Dummy Shape
Point shape = ShapeBuilders.newPoint(-100, 45).build();
shapeMapper.parse(context.createExternalValueContext(shape));
context = context.createExternalValueContext(generatedValue);
// Let's add a Original String
stringMapper.parse(context);
multiFields.parse(this, context);
return null;
}
示例11: next
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
public GeoPoint next() throws IOException {
final BytesRef term = termsEnum.next();
if (term == null) {
return null;
}
spare.copyUTF8Bytes(term);
int commaIndex = -1;
for (int i = 0; i < spare.length(); i++) {
if (spare.charAt(i) == ',') { // saves a string creation
commaIndex = i;
break;
}
}
if (commaIndex == -1) {
assert false;
return next.reset(0, 0);
}
final double lat = Double.parseDouble(new String(spare.chars(), 0, commaIndex));
final double lon = Double.parseDouble(new String(spare.chars(), commaIndex + 1, spare.length() - (commaIndex + 1)));
return next.reset(lat, lon);
}
示例12: testGeoGetLatLon
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
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()));
}
示例13: doXContentBody
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
GeoPoint topLeft = topLeft();
GeoPoint bottomRight = bottomRight();
if (topLeft != null) {
builder.startObject("bounds");
builder.startObject("top_left");
builder.field("lat", topLeft.lat());
builder.field("lon", topLeft.lon());
builder.endObject();
builder.startObject("bottom_right");
builder.field("lat", bottomRight.lat());
builder.field("lon", bottomRight.lon());
builder.endObject();
builder.endObject();
}
return builder;
}
示例14: testSimpleUnclosedPolygon
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
public void testSimpleUnclosedPolygon() throws Exception {
List<GeoPoint> points = new ArrayList<>();
points.add(new GeoPoint(40.7, -74.0));
points.add(new GeoPoint(40.7, -74.1));
points.add(new GeoPoint(40.8, -74.1));
points.add(new GeoPoint(40.8, -74.0));
SearchResponse searchResponse = client().prepareSearch("test") // from NY
.setQuery(boolQuery().must(geoPolygonQuery("location", points))).execute().actionGet();
assertHitCount(searchResponse, 4);
assertThat(searchResponse.getHits().getHits().length, equalTo(4));
for (SearchHit hit : searchResponse.getHits()) {
assertThat(hit.getId(), anyOf(equalTo("1"), equalTo("3"), equalTo("4"), equalTo("5")));
}
}
示例15: testSingleValueFieldAsSubAggToGeohashGrid
import org.elasticsearch.common.geo.GeoPoint; //导入依赖的package包/类
public void testSingleValueFieldAsSubAggToGeohashGrid() throws Exception {
SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME)
.addAggregation(geohashGrid("geoGrid").field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)))
.execute().actionGet();
assertSearchResponse(response);
GeoHashGrid grid = response.getAggregations().get("geoGrid");
assertThat(grid, notNullValue());
assertThat(grid.getName(), equalTo("geoGrid"));
List<GeoHashGrid.Bucket> buckets = grid.getBuckets();
for (int i=0; i < buckets.size(); ++i) {
GeoHashGrid.Bucket cell = buckets.get(i);
String geohash = cell.getKeyAsString();
GeoPoint expectedCentroid = expectedCentroidsForGeoHash.get(geohash);
GeoCentroid centroidAgg = cell.getAggregations().get(aggName);
assertThat("Geohash " + geohash + " has wrong centroid latitude ", expectedCentroid.lat(),
closeTo(centroidAgg.centroid().lat(), GEOHASH_TOLERANCE));
assertThat("Geohash " + geohash + " has wrong centroid longitude", expectedCentroid.lon(),
closeTo(centroidAgg.centroid().lon(), GEOHASH_TOLERANCE));
}
}