use of org.locationtech.spatial4j.shape.ShapeFactory in project gtfs-realtime-validator by CUTR-at-USF.
the class UtilTest method testPositionWithinShape.
@Test
public void testPositionWithinShape() {
// Create USF Bull Runner bounding box
ShapeFactory sf = GEO.getShapeFactory();
ShapeFactory.MultiPointBuilder shapeBuilder = sf.multiPoint();
shapeBuilder.pointXY(-82.438456, 28.041606);
shapeBuilder.pointXY(-82.438456, 28.082202);
shapeBuilder.pointXY(-82.399531, 28.082202);
shapeBuilder.pointXY(-82.399531, 28.041606);
Shape boundingBox = shapeBuilder.build().getBoundingBox();
// Test utility method - USF campus location
GtfsRealtime.Position.Builder positionBuilder = GtfsRealtime.Position.newBuilder();
positionBuilder.setLatitude(28.0587f);
positionBuilder.setLongitude(-82.4139f);
boolean result = GtfsUtils.isPositionWithinShape(positionBuilder.build(), boundingBox);
assertTrue(result);
// Test utility method - Downtown Tampa, FL
positionBuilder.setLatitude(27.9482837f);
positionBuilder.setLongitude(-82.4655826f);
result = GtfsUtils.isPositionWithinShape(positionBuilder.build(), boundingBox);
assertFalse(result);
}
use of org.locationtech.spatial4j.shape.ShapeFactory in project gtfs-realtime-validator by CUTR-at-USF.
the class GtfsUtils method isPositionWithinShape.
/**
* 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);
}
Aggregations