Search in sources :

Example 61 with GeometryFactory

use of com.vividsolutions.jts.geom.GeometryFactory in project OpenTripPlanner by opentripplanner.

the class TestTurns method testIntersectionVertex.

public void testIntersectionVertex() {
    GeometryFactory gf = new GeometryFactory();
    LineString geometry = gf.createLineString(new Coordinate[] { new Coordinate(-0.10, 0), new Coordinate(0, 0) });
    IntersectionVertex v1 = new IntersectionVertex(null, "v1", -0.10, 0);
    IntersectionVertex v2 = new IntersectionVertex(null, "v2", 0, 0);
    StreetEdge leftEdge = new StreetEdge(v1, v2, geometry, "morx", 10.0, StreetTraversalPermission.ALL, true);
    LineString geometry2 = gf.createLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(-0.10, 0) });
    StreetEdge rightEdge = new StreetEdge(v1, v2, geometry2, "fleem", 10.0, StreetTraversalPermission.ALL, false);
    assertEquals(180, Math.abs(leftEdge.getOutAngle() - rightEdge.getOutAngle()));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge)

Example 62 with GeometryFactory

use of com.vividsolutions.jts.geom.GeometryFactory in project OpenTripPlanner by opentripplanner.

the class OnBoardDepartServiceImplTest method testOnBoardDepartureTime.

@Test
public final void testOnBoardDepartureTime() {
    Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = new Coordinate(0.0, 0.0);
    coordinates[1] = new Coordinate(0.0, 1.0);
    coordinates[2] = new Coordinate(2.0, 1.0);
    coordinates[3] = new Coordinate(5.0, 1.0);
    coordinates[4] = new Coordinate(5.0, 5.0);
    PatternDepartVertex depart = mock(PatternDepartVertex.class);
    PatternArriveVertex dwell = mock(PatternArriveVertex.class);
    PatternArriveVertex arrive = mock(PatternArriveVertex.class);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    ServiceDay serviceDay = mock(ServiceDay.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    CoordinateSequenceFactory coordinateSequenceFactory = geometryFactory.getCoordinateSequenceFactory();
    CoordinateSequence coordinateSequence = coordinateSequenceFactory.create(coordinates);
    LineString geometry = new LineString(coordinateSequence, geometryFactory);
    ArrayList<Edge> hops = new ArrayList<Edge>(2);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Agency agency = new Agency();
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(3);
    StopTime stopDepartTime = new StopTime();
    StopTime stopDwellTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = new Stop();
    Stop stopDwell = new Stop();
    Stop stopArrive = new Stop();
    Trip trip = new Trip();
    routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
    agency.setId(agencyAndId.getAgencyId());
    route.setId(agencyAndId);
    route.setAgency(agency);
    stopDepart.setId(agencyAndId);
    stopDwell.setId(agencyAndId);
    stopArrive.setId(agencyAndId);
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopDwellTime.setArrivalTime(20);
    stopDwellTime.setStop(stopDwell);
    stopDwellTime.setDepartureTime(40);
    stopArriveTime.setArrivalTime(60);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopDwellTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    trip.setTripHeadsign("The right");
    trip.setRoute(route);
    TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = new TripPattern(route, stopPattern);
    TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
    when(depart.getTripPattern()).thenReturn(tripPattern);
    when(dwell.getTripPattern()).thenReturn(tripPattern);
    PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
    PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);
    hops.add(patternHop0);
    hops.add(patternHop1);
    when(graph.getEdges()).thenReturn(hops);
    when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
    routingRequest.from = new GenericLocation();
    routingRequest.startingTransitTripId = agencyAndId;
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(9);
    patternHop0.setGeometry(geometry);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    coordinates = new Coordinate[3];
    coordinates[0] = new Coordinate(3.5, 1.0);
    coordinates[1] = new Coordinate(5.0, 1.0);
    coordinates[2] = new Coordinate(5.0, 5.0);
    coordinateSequence = coordinateSequenceFactory.create(coordinates);
    geometry = new LineString(coordinateSequence, geometryFactory);
    Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
    Edge edge = vertex.getOutgoing().toArray(new Edge[1])[0];
    assertEquals(vertex, edge.getFromVertex());
    assertEquals(dwell, edge.getToVertex());
    assertEquals("The right", edge.getDirection());
    assertEquals(geometry, edge.getGeometry());
    assertEquals(coordinates[0].x, vertex.getX(), 0.0);
    assertEquals(coordinates[0].y, vertex.getY(), 0.0);
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Vertex(org.opentripplanner.routing.graph.Vertex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ServiceDay(org.opentripplanner.routing.core.ServiceDay) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) RoutingContext(org.opentripplanner.routing.core.RoutingContext) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Graph(org.opentripplanner.routing.graph.Graph) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) CoordinateSequenceFactory(com.vividsolutions.jts.geom.CoordinateSequenceFactory) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 63 with GeometryFactory

use of com.vividsolutions.jts.geom.GeometryFactory in project alliance by codice.

the class FrameCenterUpdateFieldFactoryTest method testBuild.

@Test
public void testBuild() {
    GeometryOperator geometryOperator = mock(GeometryOperator.class);
    FrameCenterUpdateFieldFactory factory = new FrameCenterUpdateFieldFactory(geometryOperator, new GeometryFactory());
    UpdateParent.UpdateField updateField = factory.build();
    assertThat(updateField, is(instanceOf(FrameCenterUpdateField.class)));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) Test(org.junit.Test)

Example 64 with GeometryFactory

use of com.vividsolutions.jts.geom.GeometryFactory in project alliance by codice.

the class FrameCenterUpdateFieldTest method testLineString.

@Test
public void testLineString() {
    String wktChild1 = "LINESTRING (30 10, 10 30, 40 40)";
    String wktChild2 = "LINESTRING (50 50, 60 60, 70 70)";
    String wktChild3 = "LINESTRING (80 80, 85 85)";
    String wktExpected = "LINESTRING (30 10, 10 30, 40 40, 50 50, 60 60, 70 70, 80 80, 85 85)";
    Metacard parentMetacard = mock(Metacard.class);
    Metacard childMetacard1 = mock(Metacard.class);
    when(childMetacard1.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild1));
    Metacard childMetacard2 = mock(Metacard.class);
    when(childMetacard2.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild2));
    Metacard childMetacard3 = mock(Metacard.class);
    when(childMetacard3.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild3));
    FrameCenterUpdateField frameCenterUpdateField = new FrameCenterUpdateField(GeometryOperator.IDENTITY, new GeometryFactory());
    Context context = mock(Context.class);
    GeometryOperator.Context geometryOperatorContext = new GeometryOperator.Context();
    geometryOperatorContext.setSubsampleCount(FrameCenterUpdateField.MAX_SIZE * 2);
    when(context.getGeometryOperatorContext()).thenReturn(geometryOperatorContext);
    frameCenterUpdateField.updateField(parentMetacard, Collections.singletonList(childMetacard1), context);
    frameCenterUpdateField.updateField(parentMetacard, Arrays.asList(childMetacard2, childMetacard3), context);
    frameCenterUpdateField.end(parentMetacard, context);
    ArgumentCaptor<Attribute> captor = ArgumentCaptor.forClass(Attribute.class);
    verify(parentMetacard).setAttribute(captor.capture());
    assertThat(captor.getValue().getValue(), is(wktExpected));
    assertThat(geometryOperatorContext.getSubsampleCount(), is(FrameCenterUpdateField.MAX_SIZE * 2));
}
Also used : Context(org.codice.alliance.video.stream.mpegts.Context) Metacard(ddf.catalog.data.Metacard) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Test(org.junit.Test)

Example 65 with GeometryFactory

use of com.vividsolutions.jts.geom.GeometryFactory in project alliance by codice.

the class FrameCenterUpdateFieldTest method testVariousInvalidAndValidFrameCenterValues.

@Test
public void testVariousInvalidAndValidFrameCenterValues() throws ParseException {
    String wktChild1 = "LINESTRING (30 10, 10 30, 40 40)";
    Context context = mock(Context.class);
    GeometryOperator.Context geometryOperatorContext = new GeometryOperator.Context();
    geometryOperatorContext.setSubsampleCount(FrameCenterUpdateField.MAX_SIZE * 2);
    when(context.getGeometryOperatorContext()).thenReturn(geometryOperatorContext);
    Metacard parentMetacard = mock(Metacard.class);
    // this metacard has a valid frame center
    Metacard childMetacard1 = mock(Metacard.class);
    when(childMetacard1.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild1));
    // this metacard is missing the frame center attribute
    Metacard childMetacard2 = mock(Metacard.class);
    // this metacard has an empty frame center attribute
    Metacard childMetacard3 = mock(Metacard.class);
    when(childMetacard3.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, ""));
    // this metacard has a non-String frame center attribute
    Metacard childMetacard4 = mock(Metacard.class);
    when(childMetacard4.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, 1L));
    FrameCenterUpdateField frameCenterUpdateField = new FrameCenterUpdateField(GeometryOperator.IDENTITY, new GeometryFactory());
    frameCenterUpdateField.updateField(parentMetacard, Collections.singletonList(childMetacard1), context);
    frameCenterUpdateField.updateField(parentMetacard, Arrays.asList(childMetacard2, childMetacard3), context);
    frameCenterUpdateField.end(parentMetacard, context);
    ArgumentCaptor<Attribute> captor = ArgumentCaptor.forClass(Attribute.class);
    verify(parentMetacard).setAttribute(captor.capture());
    assertThat(captor.getValue().getValue(), is("LINESTRING (30 10, 10 30, 40 40)"));
    assertThat(geometryOperatorContext.getSubsampleCount(), is(FrameCenterUpdateField.MAX_SIZE * 2));
}
Also used : Context(org.codice.alliance.video.stream.mpegts.Context) Metacard(ddf.catalog.data.Metacard) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Test(org.junit.Test)

Aggregations

GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)67 Coordinate (com.vividsolutions.jts.geom.Coordinate)44 Test (org.junit.Test)25 Geometry (com.vividsolutions.jts.geom.Geometry)20 ArrayList (java.util.ArrayList)20 LineString (com.vividsolutions.jts.geom.LineString)17 SimpleFeature (org.opengis.feature.simple.SimpleFeature)13 File (java.io.File)10 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)10 Point (com.vividsolutions.jts.geom.Point)9 List (java.util.List)8 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)8 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)8 Optional (com.google.common.base.Optional)7 Polygon (com.vividsolutions.jts.geom.Polygon)7 Metacard (ddf.catalog.data.Metacard)7 RevFeature (org.locationtech.geogig.api.RevFeature)7 ImmutableList (com.google.common.collect.ImmutableList)6 LinearRing (com.vividsolutions.jts.geom.LinearRing)6 GeometryOperator (org.codice.alliance.libs.klv.GeometryOperator)6