org.locationtech.spatial4j.shape.Point Java Examples
The following examples show how to use
org.locationtech.spatial4j.shape.Point.
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
Source File: LiteralValueFormatter.java From crate with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public void formatValue(Object value, StringBuilder builder) { if (value == null) { builder.append("NULL"); } else if (value instanceof Map) { formatMap((Map<String, Object>) value, builder); } else if (value instanceof Collection) { formatIterable((Iterable<?>) value, builder); } else if (value.getClass().isArray()) { formatArray(value, builder); } else if (value instanceof String || value instanceof Point || value instanceof Period) { builder.append(Literals.quoteStringLiteral(value.toString())); } else if (value instanceof Long && ((Long) value <= Integer.MAX_VALUE || (Long) value >= Integer.MIN_VALUE)) { builder.append(value.toString()); builder.append("::bigint"); } else { builder.append(value.toString()); } }
Example #2
Source File: Geo3dDistanceCalculator.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Point pointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse) { Geo3dPointShape geoFrom = (Geo3dPointShape) from; GeoPoint point = (GeoPoint) geoFrom.shape; double dist = DistanceUtils.DEGREES_TO_RADIANS * distDEG; double bearing = DistanceUtils.DEGREES_TO_RADIANS * bearingDEG; GeoPoint newPoint = planetModel.surfacePointOnBearing(point, dist, bearing); double newLat = newPoint.getLatitude() * DistanceUtils.RADIANS_TO_DEGREES; double newLon = newPoint.getLongitude() * DistanceUtils.RADIANS_TO_DEGREES; if (reuse != null) { reuse.reset(newLon, newLat); return reuse; } else { return ctx.getShapeFactory().pointXY(newLon, newLat); } }
Example #3
Source File: LatLonPointSpatialField.java From lucene-solr with Apache License 2.0 | 6 votes |
protected Query makeQueryFromDocValues(Shape shape) { // note: latitude then longitude order for LLP's methods if (shape instanceof Circle) { Circle circle = (Circle) shape; double radiusMeters = circle.getRadius() * DistanceUtils.DEG_TO_KM * 1000; return LatLonDocValuesField.newSlowDistanceQuery(getFieldName(), circle.getCenter().getY(), circle.getCenter().getX(), radiusMeters); } else if (shape instanceof Rectangle) { Rectangle rect = (Rectangle) shape; return LatLonDocValuesField.newSlowBoxQuery(getFieldName(), rect.getMinY(), rect.getMaxY(), rect.getMinX(), rect.getMaxX()); } else if (shape instanceof Point) { Point point = (Point) shape; return LatLonDocValuesField.newSlowDistanceQuery(getFieldName(), point.getY(), point.getX(), 0); } else { throw new UnsupportedOperationException("Shape " + shape.getClass() + " is not supported by " + getClass()); } // } else if (shape instanceof LucenePolygonShape) { // // TODO support multi-polygon // Polygon poly = ((LucenePolygonShape)shape).lucenePolygon; // return LatLonPoint.newPolygonQuery(getFieldName(), poly); }
Example #4
Source File: Geo3dShape.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public SpatialRelation relate(Shape other) { int relationship; if (other instanceof Geo3dShape<?>) { relationship = relate((Geo3dShape<?>) other); } else if (other instanceof Rectangle) { relationship = relate((Rectangle) other); } else if (other instanceof Point) { relationship = relate((Point) other); } else { throw new RuntimeException("Unimplemented shape relationship determination: " + other.getClass()); } switch (relationship) { case GeoArea.DISJOINT: return SpatialRelation.DISJOINT; case GeoArea.OVERLAPS: return (other instanceof Point ? SpatialRelation.CONTAINS : SpatialRelation.INTERSECTS); case GeoArea.CONTAINS: return (other instanceof Point ? SpatialRelation.CONTAINS : SpatialRelation.WITHIN); case GeoArea.WITHIN: return SpatialRelation.CONTAINS; } throw new RuntimeException("Undetermined shape relationship: " + relationship); }
Example #5
Source File: PackedQuadPrefixTree.java From lucene-solr with Apache License 2.0 | 6 votes |
protected void checkBattenbergNotRobustly(byte quad, double cx, double cy, int level, List<Cell> matches, long term, Shape shape, int maxLevel) { // short-circuit if we find a match for the point (no need to continue recursion) if (shape instanceof Point && !matches.isEmpty()) return; double w = levelW[level] / 2; double h = levelH[level] / 2; SpatialRelation v = shape.relate(ctx.getShapeFactory().rect(cx - w, cx + w, cy - h, cy + h)); if (SpatialRelation.DISJOINT == v) { return; } // set bits for next level term |= (((long)(quad))<<(64-(++level<<1))); // increment level term = ((term>>>1)+1)<<1; if (SpatialRelation.CONTAINS == v || (level >= maxLevel)) { matches.add(new PackedQuadCell(term, v.transpose())); } else {// SpatialRelation.WITHIN, SpatialRelation.INTERSECTS buildNotRobustly(cx, cy, level, matches, term, shape, maxLevel); } }
Example #6
Source File: SpatialExample.java From lucene-solr with Apache License 2.0 | 6 votes |
private Document newSampleDocument(int id, Shape... shapes) { Document doc = new Document(); doc.add(new StoredField("id", id)); doc.add(new NumericDocValuesField("id", id)); //Potentially more than one shape in this field is supported by some // strategies; see the javadocs of the SpatialStrategy impl to see. for (Shape shape : shapes) { for (Field f : strategy.createIndexableFields(shape)) { doc.add(f); } //store it too; the format is up to you // (assume point in this example) Point pt = (Point) shape; doc.add(new StoredField(strategy.getFieldName(), pt.getX()+" "+pt.getY())); } return doc; }
Example #7
Source File: SummitsContext.java From crate with Apache License 2.0 | 6 votes |
SummitsContext(String mountain, Integer height, Integer prominence, Point coordinates, String region, String classification, String range, String country, Integer firstAscent) { this.mountain = mountain; this.height = height; this.prominence = prominence; this.coordinates = coordinates; this.range = range; this.region = region; this.classification = classification; this.country = country; this.firstAscent = firstAscent; }
Example #8
Source File: PointType.java From crate with Apache License 2.0 | 6 votes |
@Override Point decodeUTF8Text(byte[] bytes) { String value = new String(bytes, StandardCharsets.UTF_8); StringTokenizer tokenizer = new StringTokenizer(value, ",()"); double x; double y; if (tokenizer.hasMoreTokens()) { x = Double.parseDouble(tokenizer.nextToken()); } else { throw new IllegalArgumentException("Cannot parse input as point: " + value + " expected a point in format: (x, y)"); } if (tokenizer.hasMoreTokens()) { y = Double.parseDouble(tokenizer.nextToken()); } else { throw new IllegalArgumentException("Cannot parse input as point: " + value + " expected a point in format: (x, y)"); } return new PointImpl(x, y, JtsSpatialContext.GEO); }
Example #9
Source File: PointVectorStrategy.java From lucene-solr with Apache License 2.0 | 6 votes |
/** @see #createIndexableFields(org.locationtech.spatial4j.shape.Shape) */ public Field[] createIndexableFields(Point point) { Field[] fields = new Field[fieldsLen]; int idx = -1; if (hasStored) { fields[++idx] = new StoredField(fieldNameX, point.getX()); fields[++idx] = new StoredField(fieldNameY, point.getY()); } if (hasDocVals) { fields[++idx] = new DoubleDocValuesField(fieldNameX, point.getX()); fields[++idx] = new DoubleDocValuesField(fieldNameY, point.getY()); } if (hasPointVals) { fields[++idx] = new DoublePoint(fieldNameX, point.getX()); fields[++idx] = new DoublePoint(fieldNameY, point.getY()); } assert idx == fields.length - 1; return fields; }
Example #10
Source File: GeoPointType.java From crate with Apache License 2.0 | 6 votes |
@Override public int compare(Point val1, Point val2) { if (val1 == null) { return -1; } if (val2 == null) { return 1; } // this is probably not really correct, but should be sufficient for the compareValueTo use case // (which is ordering and equality check) int latComp = Double.compare(val1.getX(), val2.getX()); if (latComp != 0) { return latComp; } return Double.compare(val1.getY(), val2.getY()); }
Example #11
Source File: DistanceQuery.java From crate with Apache License 2.0 | 6 votes |
private static Query eqDistance(Function parentFunction, LuceneQueryBuilder.Context context, String columnName, Double distance, Point lonLat) { double smallDistance = distance * 0.99; if (smallDistance <= 0.0) { return LatLonPoint.newDistanceQuery(columnName, lonLat.getY(), lonLat.getX(), 0); } Query withinSmallCircle = LatLonPoint.newDistanceQuery(columnName, lonLat.getY(), lonLat.getX(), smallDistance); Query withinLargeCircle = LatLonPoint.newDistanceQuery(columnName, lonLat.getY(), lonLat.getX(), distance * 1.01); return new BooleanQuery.Builder() .add(withinLargeCircle, BooleanClause.Occur.MUST) .add(withinSmallCircle, BooleanClause.Occur.MUST_NOT) .add(genericFunctionFilter(parentFunction, context), BooleanClause.Occur.FILTER) .build(); }
Example #12
Source File: PointVectorStrategy.java From lucene-solr with Apache License 2.0 | 6 votes |
/** @see #createIndexableFields(org.locationtech.spatial4j.shape.Shape) */ public Field[] createIndexableFields(Point point) { Field[] fields = new Field[fieldsLen]; int idx = -1; if (hasStored) { fields[++idx] = new StoredField(fieldNameX, point.getX()); fields[++idx] = new StoredField(fieldNameY, point.getY()); } if (hasDocVals) { fields[++idx] = new DoubleDocValuesField(fieldNameX, point.getX()); fields[++idx] = new DoubleDocValuesField(fieldNameY, point.getY()); } if (hasPointVals) { fields[++idx] = new DoublePoint(fieldNameX, point.getX()); fields[++idx] = new DoublePoint(fieldNameY, point.getY()); } if (legacyNumericFieldType != null) { fields[++idx] = new LegacyDoubleField(fieldNameX, point.getX(), legacyNumericFieldType); fields[++idx] = new LegacyDoubleField(fieldNameY, point.getY(), legacyNumericFieldType); } assert idx == fields.length - 1; return fields; }
Example #13
Source File: SpatialArgs.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Computes the distance given a shape and the {@code distErrPct}. The * algorithm is the fraction of the distance from the center of the query * shape to its closest bounding box corner. * * @param shape Mandatory. * @param distErrPct 0 to 0.5 * @param ctx Mandatory * @return A distance (in degrees). */ public static double calcDistanceFromErrPct(Shape shape, double distErrPct, SpatialContext ctx) { if (distErrPct < 0 || distErrPct > 0.5) { throw new IllegalArgumentException("distErrPct " + distErrPct + " must be between [0 to 0.5]"); } if (distErrPct == 0 || shape instanceof Point) { return 0; } Rectangle bbox = shape.getBoundingBox(); //Compute the distance from the center to a corner. Because the distance // to a bottom corner vs a top corner can vary in a geospatial scenario, // take the closest one (greater precision). Point ctr = bbox.getCenter(); double y = (ctr.getY() >= 0 ? bbox.getMaxY() : bbox.getMinY()); double diagonalDist = ctx.getDistCalc().distance(ctr, bbox.getMaxX(), y); return diagonalDist * distErrPct; }
Example #14
Source File: ElasticsearchSearchQueryBase.java From vertexium with Apache License 2.0 | 6 votes |
private ShapeBuilder getCircleBuilder(GeoCircle geoCircle) { // NOTE: as of ES7, storing circles is no longer supported so we need approximate the circle with a polygon double radius = geoCircle.getRadius(); double maxSideLengthKm = getSearchIndex().getConfig().getGeocircleToPolygonSideLength(); maxSideLengthKm = Math.min(radius, maxSideLengthKm); // calculate how many points we need to use given the length of a polygon side int numberOfPoints = (int) Math.ceil(Math.PI / Math.asin((maxSideLengthKm / (2 * radius)))); numberOfPoints = Math.min(numberOfPoints, getSearchIndex().getConfig().getGeocircleToPolygonMaxNumSides()); // Given the number of sides, loop through slices of 360 degrees and calculate the lat/lon at that radius and heading SpatialContext spatialContext = SpatialContext.GEO; DistanceCalculator distanceCalculator = spatialContext.getDistCalc(); Point centerPoint = spatialContext.getShapeFactory().pointXY(DistanceUtils.normLonDEG(geoCircle.getLongitude()), DistanceUtils.normLatDEG(geoCircle.getLatitude())); ArrayList<GeoPoint> points = new ArrayList<>(); for (float angle = 360; angle > 0; angle -= 360.0 / numberOfPoints) { Point point = distanceCalculator.pointOnBearing(centerPoint, geoCircle.getRadius() * KM_TO_DEG, angle, spatialContext, null); points.add(new GeoPoint(point.getY(), point.getX())); } // Polygons must start/end at the same point, so add the first point onto the end points.add(points.get(0)); return getPolygonBuilder(new GeoPolygon(points, geoCircle.getDescription())); }
Example #15
Source File: PortedSolr3Test.java From lucene-solr with Apache License 2.0 | 6 votes |
private void _checkHits(boolean bbox, Point pt, double distKM, int assertNumFound, int... assertIds) { SpatialOperation op = SpatialOperation.Intersects; double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM); Shape shape = shapeFactory.circle(pt, distDEG); if (bbox) shape = shape.getBoundingBox(); SpatialArgs args = new SpatialArgs(op,shape); //args.setDistPrecision(0.025); Query query = strategy.makeQuery(args); SearchResults results = executeQuery(query, 100); assertEquals(""+shape,assertNumFound,results.numFound); if (assertIds != null) { Set<Integer> resultIds = new HashSet<>(); for (SearchResult result : results.results) { resultIds.add(Integer.valueOf(result.document.get("id"))); } for (int assertId : assertIds) { assertTrue("has " + assertId, resultIds.contains(assertId)); } } }
Example #16
Source File: RandomSpatialOpFuzzyPrefixTreeTest.java From lucene-solr with Apache License 2.0 | 6 votes |
protected Shape gridSnap(Shape snapMe) { if (snapMe == null) return null; if (snapMe instanceof ShapePair) { ShapePair me = (ShapePair) snapMe; return new ShapePair(gridSnap(me.shape1), gridSnap(me.shape2), me.biasContainsThenWithin); } if (snapMe instanceof Point) { snapMe = snapMe.getBoundingBox(); } //The next 4 lines mimic PrefixTreeStrategy.createIndexableFields() double distErrPct = ((PrefixTreeStrategy) strategy).getDistErrPct(); double distErr = SpatialArgs.calcDistanceFromErrPct(snapMe, distErrPct, ctx); int detailLevel = grid.getLevelForDistance(distErr); CellIterator cells = grid.getTreeCellIterator(snapMe, detailLevel); //calc bounding box of cells. List<Shape> cellShapes = new ArrayList<>(1024); while (cells.hasNext()) { Cell cell = cells.next(); if (!cell.isLeaf()) continue; cellShapes.add(cell.getShape()); } return new ShapeCollection<>(cellShapes, ctx).getBoundingBox(); }
Example #17
Source File: HeatmapFacetCounterTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private int countMatchingDocsAtLevel(Point pt, int facetLevel) throws IOException { // we use IntersectsPrefixTreeFilter directly so that we can specify the level to go to exactly. RecursivePrefixTreeStrategy strategy = (RecursivePrefixTreeStrategy) this.strategy; Query filter = new IntersectsPrefixTreeQuery( pt, strategy.getFieldName(), grid, facetLevel, grid.getMaxLevels()); final TotalHitCountCollector collector = new TotalHitCountCollector(); indexSearcher.search(filter, collector); cellsValidated++; if (collector.getTotalHits() > 0) { cellValidatedNonZero++; } return collector.getTotalHits(); }
Example #18
Source File: GeoShapeFieldMapper.java From crate with Apache License 2.0 | 5 votes |
@Override public void parse(ParseContext context) throws IOException { try { Shape shape = context.parseExternalValue(Shape.class); if (shape == null) { ShapeBuilder shapeBuilder = ShapeParser.parse(context.parser(), this); if (shapeBuilder == null) { return; } shape = shapeBuilder.build(); } if (fieldType().pointsOnly() == true) { // index configured for pointsOnly if (shape instanceof XShapeCollection && XShapeCollection.class.cast(shape).pointsOnly()) { // MULTIPOINT data: index each point separately List<Shape> shapes = ((XShapeCollection) shape).getShapes(); for (Shape s : shapes) { indexShape(context, s); } return; } else if (shape instanceof Point == false) { throw new MapperParsingException("[{" + fieldType().name() + "}] is configured for points only but a " + ((shape instanceof JtsGeometry) ? ((JtsGeometry)shape).getGeom().getGeometryType() : shape.getClass()) + " was found"); } } indexShape(context, shape); } catch (Exception e) { if (ignoreMalformed.value() == false) { throw new MapperParsingException("failed to parse field [{}] of type [{}]", e, fieldType().name(), fieldType().typeName()); } context.addIgnoredField(fieldType.name()); } }
Example #19
Source File: LatLonType.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) { Point p1 = SpatialUtils.parsePointSolrException(externalVal, SpatialContext.GEO); SchemaField latSF = subField(field, LAT, parser.getReq().getSchema()); SchemaField lonSF = subField(field, LON, parser.getReq().getSchema()); BooleanQuery.Builder result = new BooleanQuery.Builder(); result.add(latSF.getType().getFieldQuery(parser, latSF, Double.toString(p1.getY())), BooleanClause.Occur.MUST); result.add(lonSF.getType().getFieldQuery(parser, lonSF, Double.toString(p1.getX())), BooleanClause.Occur.MUST); return result.build(); }
Example #20
Source File: RandomSpatialOpFuzzyPrefixTreeTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testPackedQuadPointsOnlyBug() throws IOException { setupQuadGrid(1, true); // packed quad. maxLevels doesn't matter. setupCtx2D(ctx); ((PrefixTreeStrategy) strategy).setPointsOnly(true); Point point = ctx.makePoint(169.0, 107.0); adoc("0", point); commit(); Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, point)); assertEquals(1, executeQuery(query, 1).numFound); }
Example #21
Source File: DistanceStrategyTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testRecipScore() throws IOException { Point p100 = ctx.getShapeFactory().pointXY(2.02, 0.98); adoc("100", p100); Point p101 = ctx.getShapeFactory().pointXY(-1.001, 4.001); adoc("101", p101); adoc("103", (Shape)null);//test score for nothing commit(); double dist = ctx.getDistCalc().distance(p100, p101); Shape queryShape = ctx.makeCircle(2.01, 0.99, dist); checkValueSource(strategy.makeRecipDistanceValueSource(queryShape), new float[]{1.00f, 0.10f, 0f}, 0.09f); }
Example #22
Source File: DistanceValueSource.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns the FunctionValues used by the function query. */ @Override public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException { LeafReader reader = readerContext.reader(); final NumericDocValues ptX = DocValues.getNumeric(reader, strategy.getFieldNameX()); final NumericDocValues ptY = DocValues.getNumeric(reader, strategy.getFieldNameY()); return DoubleValues.withDefault(new DoubleValues() { private final Point from = DistanceValueSource.this.from; private final DistanceCalculator calculator = strategy.getSpatialContext().getDistCalc(); @Override public double doubleValue() throws IOException { double x = Double.longBitsToDouble(ptX.longValue()); double y = Double.longBitsToDouble(ptY.longValue()); return calculator.distance(from, x, y) * multiplier; } @Override public boolean advanceExact(int doc) throws IOException { return ptX.advanceExact(doc) && ptY.advanceExact(doc); } }, nullValue); }
Example #23
Source File: DistanceValueSource.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Constructor. */ public DistanceValueSource(PointVectorStrategy strategy, Point from, double multiplier) { this.strategy = strategy; this.from = from; this.multiplier = multiplier; this.nullValue = 180 * multiplier; }
Example #24
Source File: SpatialUtils.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Calls {@link #parsePoint(String, org.locationtech.spatial4j.context.SpatialContext)} and wraps * the exception with {@link org.apache.solr.common.SolrException} with a helpful message. */ public static Point parsePointSolrException(String externalVal, SpatialContext ctx) throws SolrException { try { return parsePoint(externalVal, ctx); } catch (InvalidShapeException e) { String message = e.getMessage(); if (!message.contains(externalVal)) message = "Can't parse point '" + externalVal + "' because: " + message; throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, message, e); } }
Example #25
Source File: LatLonType.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) { Point p1 = SpatialUtils.parsePointSolrException(part1, SpatialContext.GEO); Point p2 = SpatialUtils.parsePointSolrException(part2, SpatialContext.GEO); SchemaField latSF = subField(field, LAT, parser.getReq().getSchema()); SchemaField lonSF = subField(field, LON, parser.getReq().getSchema()); BooleanQuery.Builder result = new BooleanQuery.Builder(); // points must currently be ordered... should we support specifying any two opposite corner points? result.add(latSF.getType().getRangeQuery(parser, latSF, Double.toString(p1.getY()), Double.toString(p2.getY()), minInclusive, maxInclusive), BooleanClause.Occur.MUST); result.add(lonSF.getType().getRangeQuery(parser, lonSF, Double.toString(p1.getX()), Double.toString(p2.getX()), minInclusive, maxInclusive), BooleanClause.Occur.MUST); return result.build(); }
Example #26
Source File: MultiPointBuilder.java From crate with Apache License 2.0 | 5 votes |
@Override public XShapeCollection<Point> build() { //Could wrap JtsGeometry but probably slower due to conversions to/from JTS in relate() //MultiPoint geometry = FACTORY.createMultiPoint(points.toArray(new Coordinate[points.size()])); List<Point> shapes = new ArrayList<>(coordinates.size()); for (Coordinate coord : coordinates) { shapes.add(SPATIAL_CONTEXT.makePoint(coord.x, coord.y)); } XShapeCollection<Point> multiPoints = new XShapeCollection<>(shapes, SPATIAL_CONTEXT); multiPoints.setPointsOnly(true); return multiPoints; }
Example #27
Source File: CentroidComponent.java From query-segmenter with Apache License 2.0 | 5 votes |
private CentroidTypedSegment getClosestSegment(List<TypedSegment> typedSegments, double[] userLatlon) { CentroidTypedSegment closest = null; double closestDistance = Double.MAX_VALUE; for (TypedSegment typedSegment : typedSegments) { CentroidTypedSegment centroidSegment = (CentroidTypedSegment) typedSegment; Point p1 = new PointImpl(userLatlon[0], userLatlon[1], ctx); Point p2 = new PointImpl(centroidSegment.getLatitude(), centroidSegment.getLongitude(), ctx); double distance = ctx.getDistCalc().distance(p1, p2); if (distance < closestDistance) { closest = centroidSegment; } } return closest; }
Example #28
Source File: PrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public DoubleValuesSource makeDistanceValueSource(Point queryPoint, double multiplier) { PointPrefixTreeFieldCacheProvider p = provider.get( getFieldName() ); if( p == null ) { synchronized (this) {//double checked locking idiom is okay since provider is threadsafe p = provider.get( getFieldName() ); if (p == null) { p = new PointPrefixTreeFieldCacheProvider(grid, getFieldName(), defaultFieldValuesArrayLen); provider.put(getFieldName(),p); } } } return new ShapeFieldCacheDistanceValueSource(ctx, p, queryPoint, multiplier); }
Example #29
Source File: Geo3dDistanceCalculator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public double distance(Point from, double toX, double toY) { GeoPoint fromGeoPoint; if (from instanceof Geo3dPointShape) { fromGeoPoint = (((Geo3dPointShape) from).shape).getCenter(); } else { fromGeoPoint = new GeoPoint(planetModel, from.getY() * DistanceUtils.DEGREES_TO_RADIANS, from.getX() * DistanceUtils.DEGREES_TO_RADIANS); } GeoPoint toGeoPoint = new GeoPoint(planetModel, toY * DistanceUtils.DEGREES_TO_RADIANS, toX * DistanceUtils.DEGREES_TO_RADIANS); return planetModel.surfaceDistance(fromGeoPoint, toGeoPoint) * DistanceUtils.RADIANS_TO_DEGREES; }
Example #30
Source File: Geo3dRectangleShape.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Point getCenter() { Point center = this.center;//volatile read once if (center == null) { GeoPoint point = shape.getCenter(); center = new Geo3dPointShape( GeoPointShapeFactory.makeGeoPointShape(shape.getPlanetModel(), point.getLatitude(), point.getLongitude()), spatialcontext); this.center = center; } return center; }