Java Code Examples for org.locationtech.spatial4j.shape.Rectangle#getWidth()

The following examples show how to use org.locationtech.spatial4j.shape.Rectangle#getWidth() . 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: HeatmapFacetCounterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void validateHeatmapResult(Rectangle inputRange, int facetLevel, HeatmapFacetCounter.Heatmap heatmap)
    throws IOException {
  final Rectangle heatRect = heatmap.region;
  assertTrue(heatRect.relate(inputRange) == SpatialRelation.CONTAINS || heatRect.equals(inputRange));
  final double cellWidth = heatRect.getWidth() / heatmap.columns;
  final double cellHeight = heatRect.getHeight() / heatmap.rows;
  for (int c = 0; c < heatmap.columns; c++) {
    for (int r = 0; r < heatmap.rows; r++) {
      final int facetCount = heatmap.getCount(c, r);
      double x = DistanceUtils.normLonDEG(heatRect.getMinX() + c * cellWidth + cellWidth / 2);
      double y = DistanceUtils.normLatDEG(heatRect.getMinY() + r * cellHeight + cellHeight / 2);
      Point pt =  shapeFactory.pointXY(x, y);
      assertEquals(countMatchingDocsAtLevel(pt, facetLevel), facetCount);
    }
  }
}
 
Example 2
Source File: LegacyPrefixTree.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public double getDistanceForLevel(int level) {
  if (level < 1 || level > getMaxLevels())
    throw new IllegalArgumentException("Level must be in 1 to maxLevels range");
  //TODO cache for each level
  Cell cell = getCell(ctx.getWorldBounds().getCenter(), level);
  Rectangle bbox = cell.getShape().getBoundingBox();
  double width = bbox.getWidth();
  double height = bbox.getHeight();
  //Use standard cartesian hypotenuse. For geospatial, this answer is larger
  // than the correct one but it's okay to over-estimate.
  return Math.sqrt(width * width + height * height);
}
 
Example 3
Source File: HeatmapFacetCounterTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
@Repeat(iterations = 20)
public void testRandom() throws IOException {
  // Tests using random index shapes & query shapes. This has found all sorts of edge case bugs (e.g. dateline,
  // cell border, overflow(?)).

  final int numIndexedShapes = 1 + atMost(9);
  List<Shape> indexedShapes = new ArrayList<>(numIndexedShapes);
  for (int i = 0; i < numIndexedShapes; i++) {
    indexedShapes.add(randomIndexedShape());
  }

  //Main index loop:
  for (int i = 0; i < indexedShapes.size(); i++) {
    Shape shape = indexedShapes.get(i);
    adoc("" + i, shape);

    if (random().nextInt(10) == 0)
      commit();//intermediate commit, produces extra segments
  }
  //delete some documents randomly
  for (int id = 0; id < indexedShapes.size(); id++) {
    if (random().nextInt(10) == 0) {
      deleteDoc("" + id);
      indexedShapes.set(id, null);
    }
  }

  commit();

  // once without dateline wrap
  final Rectangle rect = randomRectangle();
  queryHeatmapRecursive(usually() ? ctx.getWorldBounds() : rect, 1);
  // and once with dateline wrap
  if (rect.getWidth() > 0) {
    double shift = random().nextDouble() % rect.getWidth();
    queryHeatmapRecursive(shapeFactory.rect(
            DistanceUtils.normLonDEG(rect.getMinX() - shift),
            DistanceUtils.normLonDEG(rect.getMaxX() - shift),
            rect.getMinY(), rect.getMaxY()),
        1);
  }
}