@Override public boolean contains(Shape shape, Shape shape1) { if(shape instanceof ShapeCollection || shape1 instanceof ShapeCollection){ return shape.relate(shape1).equals(SpatialRelation.CONTAINS); } Geometry geometry = factory.toGeometry(shape); Geometry geometry1 = factory.toGeometry(shape1); return geometry.contains(geometry1); }
@Override public boolean within(Shape shape, Shape shape1) { if(shape instanceof ShapeCollection || shape1 instanceof ShapeCollection){ return shape.relate(shape1).equals(SpatialRelation.WITHIN); } Geometry geometry = factory.toGeometry(shape); Geometry geometry1 = factory.toGeometry(shape1); return geometry.within(geometry1); }
/** * Returns true if the provided vehiclePosition is within the provided shape, false if it is not * * @param vehiclePosition the vehiclePosition to test against the shape * @param bounds the shape to test against the vehiclePosition * @return true if the provided vehiclePosition is within the provided shape, false if it is not */ public static boolean isPositionWithinShape(GtfsRealtime.Position vehiclePosition, Shape bounds) { ShapeFactory sf = GEO.getShapeFactory(); org.locationtech.spatial4j.shape.Point p = sf.pointXY(vehiclePosition.getLongitude(), vehiclePosition.getLatitude()); return bounds.relate(p).equals(SpatialRelation.CONTAINS); }