当前位置: 首页>>代码示例>>Java>>正文


Java SpatialContext.makeRectangle方法代码示例

本文整理汇总了Java中com.spatial4j.core.context.SpatialContext.makeRectangle方法的典型用法代码示例。如果您正苦于以下问题:Java SpatialContext.makeRectangle方法的具体用法?Java SpatialContext.makeRectangle怎么用?Java SpatialContext.makeRectangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.spatial4j.core.context.SpatialContext的用法示例。


在下文中一共展示了SpatialContext.makeRectangle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeShape

import com.spatial4j.core.context.SpatialContext; //导入方法依赖的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);
}
 
开发者ID:orientechnologies,项目名称:orientdb-spatial,代码行数:24,代码来源:ORectangleLegacyBuilder.java

示例2: calcDistanceFromErrPct

import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Test
public void calcDistanceFromErrPct() {
  final SpatialContext ctx = SpatialContext.GEO;
  final double DEP = 0.5;//distErrPct

  //the result is the diagonal distance from the center to the closest corner,
  // times distErrPct

  Shape superwide = ctx.makeRectangle(-180, 180, 0, 0);
  //0 distErrPct means 0 distance always
  assertEquals(0, SpatialArgs.calcDistanceFromErrPct(superwide, 0, ctx), 0);
  assertEquals(180 * DEP, SpatialArgs.calcDistanceFromErrPct(superwide, DEP, ctx), 0);

  Shape supertall = ctx.makeRectangle(0, 0, -90, 90);
  assertEquals(90 * DEP, SpatialArgs.calcDistanceFromErrPct(supertall, DEP, ctx), 0);

  Shape upperhalf = ctx.makeRectangle(-180, 180, 0, 90);
  assertEquals(45 * DEP, SpatialArgs.calcDistanceFromErrPct(upperhalf, DEP, ctx), 0.0001);

  Shape midCircle = ctx.makeCircle(0, 0, 45);
  assertEquals(60 * DEP, SpatialArgs.calcDistanceFromErrPct(midCircle, DEP, ctx), 0.0001);
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:SpatialArgsTest.java

示例3: makeShape

import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Override
public Shape 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++;
  }
  return ctx.makeRectangle(points[0], points[1]);
}
 
开发者ID:orientechnologies,项目名称:orientdb-lucene,代码行数:15,代码来源:ORectangleShapeFactory.java

示例4: bufferShape

import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
/** Returns a new shape that is larger than shape by at distErr.
 */
//TODO move this generic code elsewhere?  Spatial4j?
protected Shape bufferShape(Shape shape, double distErr) {
  if (distErr <= 0)
    throw new IllegalArgumentException("distErr must be > 0");
  SpatialContext ctx = grid.getSpatialContext();
  if (shape instanceof Point) {
    return ctx.makeCircle((Point)shape, distErr);
  } else if (shape instanceof Circle) {
    Circle circle = (Circle) shape;
    double newDist = circle.getRadius() + distErr;
    if (ctx.isGeo() && newDist > 180)
      newDist = 180;
    return ctx.makeCircle(circle.getCenter(), newDist);
  } else {
    Rectangle bbox = shape.getBoundingBox();
    double newMinX = bbox.getMinX() - distErr;
    double newMaxX = bbox.getMaxX() + distErr;
    double newMinY = bbox.getMinY() - distErr;
    double newMaxY = bbox.getMaxY() + distErr;
    if (ctx.isGeo()) {
      if (newMinY < -90)
        newMinY = -90;
      if (newMaxY > 90)
        newMaxY = 90;
      if (newMinY == -90 || newMaxY == 90 || bbox.getWidth() + 2*distErr > 360) {
        newMinX = -180;
        newMaxX = 180;
      } else {
        newMinX = DistanceUtils.normLonDEG(newMinX);
        newMaxX = DistanceUtils.normLonDEG(newMaxX);
      }
    } else {
      //restrict to world bounds
      newMinX = Math.max(newMinX, ctx.getWorldBounds().getMinX());
      newMaxX = Math.min(newMaxX, ctx.getWorldBounds().getMaxX());
      newMinY = Math.max(newMinY, ctx.getWorldBounds().getMinY());
      newMaxY = Math.min(newMaxY, ctx.getWorldBounds().getMaxY());
    }
    return ctx.makeRectangle(newMinX, newMaxX, newMinY, newMaxY);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:44,代码来源:WithinPrefixTreeFilter.java

示例5: toSpatial4j

import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public com.spatial4j.core.shape.Shape toSpatial4j(SpatialContext spatialContext) {
    return spatialContext.makeRectangle(minLongitude, maxLongitude, minLatitude, maxLatitude);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:6,代码来源:GeoRectangle.java


注:本文中的com.spatial4j.core.context.SpatialContext.makeRectangle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。