Java Code Examples for org.locationtech.spatial4j.shape.Shape#getClass()

The following examples show how to use org.locationtech.spatial4j.shape.Shape#getClass() . 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: Geo3dShape.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public SpatialRelation relate(Shape other) {
  int relationship;
  if (other instanceof Geo3dShape<?>) {
    relationship = relate((Geo3dShape<?>) other);
  } else if (other instanceof Rectangle) {
    relationship = relate((Rectangle) other);
  } else if (other instanceof Point) {
    relationship = relate((Point) other);
  } else {
    throw new RuntimeException("Unimplemented shape relationship determination: " + other.getClass());
  }

  switch (relationship) {
    case GeoArea.DISJOINT:
      return SpatialRelation.DISJOINT;
    case GeoArea.OVERLAPS:
      return (other instanceof Point ? SpatialRelation.CONTAINS : SpatialRelation.INTERSECTS);
    case GeoArea.CONTAINS:
      return (other instanceof Point ? SpatialRelation.CONTAINS : SpatialRelation.WITHIN);
    case GeoArea.WITHIN:
      return SpatialRelation.CONTAINS;
  }

  throw new RuntimeException("Undetermined shape relationship: " + relationship);
}
 
Example 2
Source File: LatLonPointSpatialField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected Query makeQueryFromIndex(Shape shape) {
      // note: latitude then longitude order for LLP's methods
      if (shape instanceof Circle) {
        Circle circle = (Circle) shape;
        double radiusMeters = circle.getRadius() * DistanceUtils.DEG_TO_KM * 1000;
        return LatLonPoint.newDistanceQuery(getFieldName(),
            circle.getCenter().getY(), circle.getCenter().getX(),
            radiusMeters);
      } else if (shape instanceof Rectangle) {
        Rectangle rect = (Rectangle) shape;
        return LatLonPoint.newBoxQuery(getFieldName(),
            rect.getMinY(), rect.getMaxY(), rect.getMinX(), rect.getMaxX());
      } else if (shape instanceof Point) {
        Point point = (Point) shape;
        return LatLonPoint.newDistanceQuery(getFieldName(),
            point.getY(), point.getX(), 0);
      } else {
        throw new UnsupportedOperationException("Shape " + shape.getClass() + " is not supported by " + getClass());
      }
//      } else if (shape instanceof LucenePolygonShape) {
//        // TODO support multi-polygon
//        Polygon poly = ((LucenePolygonShape)shape).lucenePolygon;
//        return LatLonPoint.newPolygonQuery(getFieldName(), poly);
    }
 
Example 3
Source File: LatLonPointSpatialField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected Query makeQueryFromDocValues(Shape shape) {
      // note: latitude then longitude order for LLP's methods
      if (shape instanceof Circle) {
        Circle circle = (Circle) shape;
        double radiusMeters = circle.getRadius() * DistanceUtils.DEG_TO_KM * 1000;
        return LatLonDocValuesField.newSlowDistanceQuery(getFieldName(),
            circle.getCenter().getY(), circle.getCenter().getX(),
            radiusMeters);
      } else if (shape instanceof Rectangle) {
        Rectangle rect = (Rectangle) shape;
        return LatLonDocValuesField.newSlowBoxQuery(getFieldName(),
            rect.getMinY(), rect.getMaxY(), rect.getMinX(), rect.getMaxX());
      } else if (shape instanceof Point) {
        Point point = (Point) shape;
        return LatLonDocValuesField.newSlowDistanceQuery(getFieldName(),
            point.getY(), point.getX(), 0);
      } else {
        throw new UnsupportedOperationException("Shape " + shape.getClass() + " is not supported by " + getClass());
      }
//      } else if (shape instanceof LucenePolygonShape) {
//        // TODO support multi-polygon
//        Polygon poly = ((LucenePolygonShape)shape).lucenePolygon;
//        return LatLonPoint.newPolygonQuery(getFieldName(), poly);
    }
 
Example 4
Source File: GeoShapeFieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(ParseContext context) throws IOException {
    try {
        Shape shape = context.parseExternalValue(Shape.class);
        if (shape == null) {
            ShapeBuilder shapeBuilder = ShapeParser.parse(context.parser(), this);
            if (shapeBuilder == null) {
                return;
            }
            shape = shapeBuilder.build();
        }
        if (fieldType().pointsOnly() == true) {
            // index configured for pointsOnly
            if (shape instanceof XShapeCollection && XShapeCollection.class.cast(shape).pointsOnly()) {
                // MULTIPOINT data: index each point separately
                List<Shape> shapes = ((XShapeCollection) shape).getShapes();
                for (Shape s : shapes) {
                    indexShape(context, s);
                }
                return;
            } else if (shape instanceof Point == false) {
                throw new MapperParsingException("[{" + fieldType().name() + "}] is configured for points only but a " +
                    ((shape instanceof JtsGeometry) ? ((JtsGeometry)shape).getGeom().getGeometryType() : shape.getClass()) + " was found");
            }
        }
        indexShape(context, shape);
    } catch (Exception e) {
        if (ignoreMalformed.value() == false) {
            throw new MapperParsingException("failed to parse field [{}] of type [{}]", e, fieldType().name(),
                    fieldType().typeName());
        }
        context.addIgnoredField(fieldType.name());
    }
}
 
Example 5
Source File: PrefixTreeStrategy.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
protected Iterator<Cell> createCellIteratorToIndex(Shape shape, int detailLevel, Iterator<Cell> reuse) {
  if (pointsOnly && !isPointShape(shape)) {
    throw new IllegalArgumentException("pointsOnly is true yet a " + shape.getClass() + " is given for indexing");
  }
  return grid.getTreeCellIterator(shape, detailLevel);//TODO should take a re-use iterator
}