com.spatial4j.core.shape.Rectangle Java Examples

The following examples show how to use com.spatial4j.core.shape.Rectangle. 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: ShapeReadWriter.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
/** Overloaded to provide a number format. */
public String writeShape(Shape shape, NumberFormat nf) {
  if (shape instanceof Point) {
    Point point = (Point) shape;
    return nf.format(point.getX()) + " " + nf.format(point.getY());
  } else if (shape instanceof Rectangle) {
    Rectangle rect = (Rectangle) shape;
    return nf.format(rect.getMinX()) + " " + nf.format(rect.getMinY()) + " " + nf.format(rect.getMaxX()) + " "
        + nf.format(rect.getMaxY());
  } else if (shape instanceof Circle) {
    Circle c = (Circle) shape;
    return "Circle(" + nf.format(c.getCenter().getX()) + " " + nf.format(c.getCenter().getY()) + " " + "d="
        + nf.format(c.getRadius()) + ")";
  }
  return shape.toString();
}
 
Example #2
Source File: LuceneQueryBuilder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Query getQuery(Function inner, Context context) {
    RefLiteralPair innerPair = new RefLiteralPair(inner);
    if (!innerPair.isValid()) {
        return null;
    }
    if (innerPair.reference().valueType().equals(DataTypes.GEO_SHAPE)) {
        // we have within('POINT(0 0)', shape_column)
        return genericFunctionFilter(inner, context);
    }
    GeoPointFieldMapper.GeoPointFieldType geoPointFieldType = getGeoPointFieldType(
            innerPair.reference().ident().columnIdent().fqn(),
            context.mapperService);

    Map<String, Object> geoJSON = (Map<String, Object>) innerPair.input().value();
    Shape shape = GeoJSONUtils.map2Shape(geoJSON);
    Geometry geometry = JtsSpatialContext.GEO.getGeometryFrom(shape);
    IndexGeoPointFieldData fieldData = context.fieldDataService.getForField(geoPointFieldType);
    if (geometry.isRectangle()) {
        Rectangle boundingBox = shape.getBoundingBox();
        return new InMemoryGeoBoundingBoxQuery(
                new GeoPoint(boundingBox.getMaxY(), boundingBox.getMinX()),
                new GeoPoint(boundingBox.getMinY(), boundingBox.getMaxX()),
                fieldData
        );
    } else {
        Coordinate[] coordinates = geometry.getCoordinates();
        GeoPoint[] points = new GeoPoint[coordinates.length];
        for (int i = 0; i < coordinates.length; i++) {
            Coordinate coordinate = coordinates[i];
            points[i] = new GeoPoint(coordinate.y, coordinate.x);
        }
        return new GeoPolygonQuery(fieldData, points);
    }
}
 
Example #3
Source File: EnvelopeBuilder.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Rectangle build() {
    return SPATIAL_CONTEXT.makeRectangle(topLeft.x, bottomRight.x, bottomRight.y, topLeft.y);
}
 
Example #4
Source File: OShapeFactoryImpl.java    From orientdb-lucene with Apache License 2.0 4 votes vote down vote up
protected OShapeFactoryImpl() {
  registerFactory(Point.class, new OPointShapeFactory());
  registerFactory(Rectangle.class, new ORectangleShapeFactory());
  registerFactory(Shape.class, new OPolygonShapeFactory());
}