Package com.spatial4j.core.shape

Examples of com.spatial4j.core.shape.Point


    for (Field field : fields) {
      doc.add(field)
    }
    addDocument(doc);

    Point upperleft = ctx.makePoint(-122.88, 48.54);
    Point lowerright = ctx.makePoint(-122.82, 48.62);
   
    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));
    commit();
   
    TopDocs search = indexSearcher.search(query, 10);
View Full Code Here


    return new ShapeConverter() {
      @Override
      public Shape convert(Shape shape) {
        if (shape instanceof Point && (radiusDegrees != 0.0 || plusMinus != 0.0)) {
          Point point = (Point)shape;
          double radius = radiusDegrees;
          if (plusMinus > 0.0) {
            Random random = new Random(point.hashCode());//use hashCode so it's reproducibly random
            radius += random.nextDouble() * 2 * plusMinus - plusMinus;
            radius = Math.abs(radius);//can happen if configured plusMinus > radiusDegrees
          }
          shape = spatialStrategy.getSpatialContext().makeCircle(point, radius);
        }
View Full Code Here

  }

  /** 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) {
View Full Code Here

        int idx = str.lastIndexOf(')');
        if (idx > 0) {
          String body = str.substring("Circle(".length(), idx);
          StringTokenizer st = new StringTokenizer(body, " ");
          String token = st.nextToken();
          Point pt;
          if (token.indexOf(',') != -1) {
            pt = readLatCommaLonPoint(token);
          } else {
            double x = Double.parseDouble(token);
            double y = Double.parseDouble(st.nextToken());
View Full Code Here

    for (Field field : fields) {
      doc.add(field);
    }
    addDocument(doc);

    Point upperleft = ctx.makePoint(-122.88, 48.54);
    Point lowerright = ctx.makePoint(-122.82, 48.62);

    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));

    commit();
View Full Code Here

  private List<Node> query$(IndexReader indexReader, Shape shape, int limit, SpatialOperation operation) throws IOException {
    if (limit <= 0)
      limit = MAX_N;

    IndexSearcher indexSearcher = new IndexSearcher(indexReader);
    Point pt = shape.getCenter();
    ValueSource valueSource = strategy.makeDistanceValueSource(pt);// the
                                    // distance
                                    // (in
                                    // degrees)
    Sort distSort = new Sort(valueSource.getSortField(false))
View Full Code Here

    checkDistValueSource("4,0", 3.6043684f, 0.9975641f, 180f);
  }

  @Test
  public void testRecipScore() throws IOException {
    Point p100 = ctx.makePoint(2, 1);
    adoc("100", p100);
    Point p101 = ctx.makePoint(-1, 4);
    adoc("101", p101);
    adoc("103", (Shape)null);//test score for nothing
    commit();

    double dist = ctx.getDistCalc().distance(p100, p101);
View Full Code Here

  //     shape = ctx.makeRectangle(shape.getCenter(), shape.getCenter());
  //   return super.newDoc(id, shape);
  // }

  void checkDistValueSource(String ptStr, float... distances) throws IOException {
    Point pt = (Point) ctx.readShape(ptStr);
    checkValueSource(strategy.makeDistanceValueSource(pt), distances, 1.0e-4f);
  }
View Full Code Here

      assertDocMatchedIds(indexSearcher, docs, 2);
      //Now, lets get the distance for the 1st doc via computing from stored point value:
      // (this computation is usually not redundant)
      Document doc1 = indexSearcher.doc(docs.scoreDocs[0].doc);
      String doc1Str = doc1.getField(strategy.getFieldName()).stringValue();
      Point doc1Point = (Point) ctx.readShape(doc1Str);
      double doc1DistDEG = ctx.getDistCalc().distance(args.getShape().getCenter(), doc1Point);
      assertEquals(121.6d, DistanceUtils.degrees2Dist(doc1DistDEG, DistanceUtils.EARTH_MEAN_RADIUS_KM), 0.1);
    }
    //--Match all, order by distance ascending
    {
      Point pt = ctx.makePoint(60, -50);
      ValueSource valueSource = strategy.makeDistanceValueSource(pt);//the distance (in degrees)
      Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(indexSearcher);//false=asc dist
      TopDocs docs = indexSearcher.search(new MatchAllDocsQuery(), 10, distSort);
      assertDocMatchedIds(indexSearcher, docs, 4, 20, 2);
      //To get the distance, we could compute from stored values like earlier.
View Full Code Here

    }
    if (shape instanceof JtsPoint) {
      return ((JtsPoint) shape).getGeom();
    }
    if (shape instanceof Point) {
      Point point = (Point) shape;
      return geometryFactory.createPoint(new Coordinate(point.getX(),point.getY()));
    }
    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle)shape;
      if (r.getCrossesDateLine()) {
        Collection<Geometry> pair = new ArrayList<Geometry>(2);
View Full Code Here

TOP

Related Classes of com.spatial4j.core.shape.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.