本文整理汇总了Java中com.spatial4j.core.shape.Rectangle类的典型用法代码示例。如果您正苦于以下问题:Java Rectangle类的具体用法?Java Rectangle怎么用?Java Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于com.spatial4j.core.shape包,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeShape
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Override
public Rectangle makeShape(OCompositeKey key, SpatialContext ctx) {
Point[] points = new Point[2];
int i = 0;
for (Object o : key.getKeys()) {
List<Number> numbers = (List<Number>) o;
double lat = ((Double) OType.convert(numbers.get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(numbers.get(1), Double.class)).doubleValue();
points[i] = ctx.makePoint(lng, lat);
i++;
}
Point lowerLeft = points[0];
Point topRight = points[1];
if (lowerLeft.getX() > topRight.getX()) {
double x = lowerLeft.getX();
lowerLeft = ctx.makePoint(topRight.getX(), lowerLeft.getY());
topRight = ctx.makePoint(x, topRight.getY());
}
return ctx.makeRectangle(lowerLeft, topRight);
}
示例2: calcDistanceFromErrPct
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
/**
* 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;
}
示例3: makeSpatialQuery
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
private Query makeSpatialQuery(SpatialArgs args) {
Shape shape = args.getShape();
if (!(shape instanceof Rectangle))
throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
Rectangle bbox = (Rectangle) shape;
Query spatial;
// Useful for understanding Relations:
// http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm
SpatialOperation op = args.getOperation();
if( op == SpatialOperation.BBoxIntersects ) spatial = makeIntersects(bbox);
else if( op == SpatialOperation.BBoxWithin ) spatial = makeWithin(bbox);
else if( op == SpatialOperation.Contains ) spatial = makeContains(bbox);
else if( op == SpatialOperation.Intersects ) spatial = makeIntersects(bbox);
else if( op == SpatialOperation.IsEqualTo ) spatial = makeEquals(bbox);
else if( op == SpatialOperation.IsDisjointTo ) spatial = makeDisjoint(bbox);
else if( op == SpatialOperation.IsWithin ) spatial = makeWithin(bbox);
else { //no Overlaps support yet
throw new UnsupportedSpatialOperation(op);
}
return spatial;
}
示例4: toNonGeo
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
private Shape toNonGeo(Shape shape) {
if (!ctx.isGeo())
return shape;//already non-geo
if (shape instanceof Rectangle) {
Rectangle rect = (Rectangle) shape;
if (rect.getCrossesDateLine()) {
return new ShapePair(
ctx2D.makeRectangle(rect.getMinX(), 180, rect.getMinY(), rect.getMaxY()),
ctx2D.makeRectangle(-180, rect.getMaxX(), rect.getMinY(), rect.getMaxY()),
biasContainsThenWithin);
} else {
return ctx2D.makeRectangle(rect.getMinX(), rect.getMaxX(), rect.getMinY(), rect.getMaxY());
}
}
//no need to do others; this addresses the -180/+180 ambiguity corner test problem
return shape;
}
示例5: testCellTraverse
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Test
public void testCellTraverse() {
trie = new GeohashPrefixTree(ctx,4);
Cell prevC = null;
Cell c = trie.getWorldCell();
assertEquals(0, c.getLevel());
assertEquals(ctx.getWorldBounds(), c.getShape());
while(c.getLevel() < trie.getMaxLevels()) {
prevC = c;
c = c.getSubCells().iterator().next();//TODO random which one?
assertEquals(prevC.getLevel()+1,c.getLevel());
Rectangle prevNShape = (Rectangle) prevC.getShape();
Shape s = c.getShape();
Rectangle sbox = s.getBoundingBox();
assertTrue(prevNShape.getWidth() > sbox.getWidth());
assertTrue(prevNShape.getHeight() > sbox.getHeight());
}
}
示例6: testQueries
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Test
public void testQueries() throws IOException {
String name = StrategyTestCase.QTEST_Cities_Intersects_BBox;
InputStream in = getClass().getClassLoader().getResourceAsStream(name);
SpatialContext ctx = SpatialContext.GEO;
Iterator<SpatialTestQuery> iter = SpatialTestQuery.getTestQueries(
new SpatialArgsParser(), ctx, name, in );//closes the InputStream
List<SpatialTestQuery> tests = new ArrayList<>();
while( iter.hasNext() ) {
tests.add( iter.next() );
}
Assert.assertEquals( 3, tests.size() );
SpatialTestQuery sf = tests.get(0);
// assert
Assert.assertEquals( 1, sf.ids.size() );
Assert.assertTrue( sf.ids.get(0).equals( "G5391959" ) );
Assert.assertTrue( sf.args.getShape() instanceof Rectangle);
Assert.assertEquals(SpatialOperation.Intersects, sf.args.getOperation());
}
示例7: gridSnapp
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
protected Rectangle gridSnapp(Shape snapMe) {
//The next 4 lines mimic PrefixTreeStrategy.createIndexableFields()
double distErrPct = ((PrefixTreeStrategy) strategy).getDistErrPct();
double distErr = SpatialArgs.calcDistanceFromErrPct(snapMe, distErrPct, ctx);
int detailLevel = grid.getLevelForDistance(distErr);
List<Node> cells = grid.getNodes(snapMe, detailLevel, false, true);
//calc bounding box of cells.
double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY, maxY = Double.NEGATIVE_INFINITY;
for (Node cell : cells) {
assert cell.getLevel() <= detailLevel;
Rectangle cellR = cell.getShape().getBoundingBox();
minX = Math.min(minX, cellR.getMinX());
maxX = Math.max(maxX, cellR.getMaxX());
minY = Math.min(minY, cellR.getMinY());
maxY = Math.max(maxY, cellR.getMaxY());
}
return ctx.makeRectangle(minX, maxX, minY, maxY);
}
示例8: testNodeTraverse
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Test
public void testNodeTraverse() {
trie = new GeohashPrefixTree(ctx,4);
Node prevN = null;
Node n = trie.getWorldNode();
assertEquals(0,n.getLevel());
assertEquals(ctx.getWorldBounds(),n.getShape());
while(n.getLevel() < trie.getMaxLevels()) {
prevN = n;
n = n.getSubCells().iterator().next();//TODO random which one?
assertEquals(prevN.getLevel()+1,n.getLevel());
Rectangle prevNShape = (Rectangle) prevN.getShape();
Shape s = n.getShape();
Rectangle sbox = s.getBoundingBox();
assertTrue(prevNShape.getWidth() > sbox.getWidth());
assertTrue(prevNShape.getHeight() > sbox.getHeight());
}
}
示例9: testQueries
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Test
public void testQueries() throws IOException {
String name = StrategyTestCase.QTEST_Cities_Intersects_BBox;
InputStream in = getClass().getClassLoader().getResourceAsStream(name);
SpatialContext ctx = SpatialContext.GEO;
Iterator<SpatialTestQuery> iter = SpatialTestQuery.getTestQueries(
new SpatialArgsParser(), ctx, name, in );
List<SpatialTestQuery> tests = new ArrayList<SpatialTestQuery>();
while( iter.hasNext() ) {
tests.add( iter.next() );
}
Assert.assertEquals( 3, tests.size() );
SpatialTestQuery sf = tests.get(0);
// assert
Assert.assertEquals( 1, sf.ids.size() );
Assert.assertTrue( sf.ids.get(0).equals( "G5391959" ) );
Assert.assertTrue( sf.args.getShape() instanceof Rectangle);
Assert.assertEquals( SpatialOperation.Intersects, sf.args.getOperation() );
}
示例10: writeShape
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
/** 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();
}
示例11: gridSnap
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
protected Rectangle gridSnap(Shape snapMe) {
//The next 4 lines mimic PrefixTreeStrategy.createIndexableFields()
double distErrPct = ((PrefixTreeStrategy) strategy).getDistErrPct();
double distErr = SpatialArgs.calcDistanceFromErrPct(snapMe, distErrPct, ctx);
int detailLevel = grid.getLevelForDistance(distErr);
List<Cell> cells = grid.getCells(snapMe, detailLevel, false, true);
//calc bounding box of cells.
double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY, maxY = Double.NEGATIVE_INFINITY;
for (Cell cell : cells) {
assert cell.getLevel() <= detailLevel;
Rectangle cellR = cell.getShape().getBoundingBox();
minX = Math.min(minX, cellR.getMinX());
maxX = Math.max(maxX, cellR.getMaxX());
minY = Math.min(minY, cellR.getMinY());
maxY = Math.max(maxY, cellR.getMaxY());
}
return ctx.makeRectangle(minX, maxX, minY, maxY);
}
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:22,代码来源:SpatialOpRecursivePrefixTreeTest.java
示例12: relate
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Override
public SpatialRelation relate(Shape other) {
SpatialRelation r = relateApprox(other);
if (r != INTERSECTS && !(r == WITHIN && biasContainsThenWithin))
return r;
//See if the correct answer is actually Contains, when the indexed shapes are adjacent,
// creating a larger shape that contains the input shape.
Rectangle oRect = (Rectangle)other;
boolean pairTouches = shape1.relate(shape2).intersects();
if (!pairTouches)
return r;
//test all 4 corners
if (relate(ctx.makePoint(oRect.getMinX(), oRect.getMinY())) == CONTAINS
&& relate(ctx.makePoint(oRect.getMinX(), oRect.getMaxY())) == CONTAINS
&& relate(ctx.makePoint(oRect.getMaxX(), oRect.getMinY())) == CONTAINS
&& relate(ctx.makePoint(oRect.getMaxX(), oRect.getMaxY())) == CONTAINS)
return CONTAINS;
return r;
}
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:20,代码来源:SpatialOpRecursivePrefixTreeTest.java
示例13: getQuery
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
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);
}
}
示例14: fromDoc
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Override
public Rectangle fromDoc(ODocument document) {
validate(document);
List<Number> coordinates = document.field(COORDINATES);
Point topLeft = SPATIAL_CONTEXT.makePoint(coordinates.get(0).doubleValue(), coordinates.get(1).doubleValue());
Point bottomRight = SPATIAL_CONTEXT.makePoint(coordinates.get(2).doubleValue(), coordinates.get(3).doubleValue());
Rectangle rectangle = SPATIAL_CONTEXT.makeRectangle(topLeft, bottomRight);
return rectangle;
}
示例15: toDoc
import com.spatial4j.core.shape.Rectangle; //导入依赖的package包/类
@Override
public ODocument toDoc(final Rectangle shape) {
ODocument doc = new ODocument(getName());
doc.field(COORDINATES, new ArrayList<Double>() {
{
add(shape.getMinX());
add(shape.getMinY());
add(shape.getMaxX());
add(shape.getMaxY());
}
});
return doc;
}