PointAlongLineEncoder implements LocationReferenceEncoder { @Override public LocationReference encode(RawLocationReference rawLocationReference) throws OpenLRProtoException { if (rawLocationReference.getLocationType() != LocationType.POINT_ALONG_LINE) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } List<LocationReferencePoint> locationReferencePoints = rawLocationReference.getLocationReferencePoints(); if (locationReferencePoints.size() < 2) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } openlr.proto.schema.LocationReferencePoint first = locationReferencePointEncoder.encode(locationReferencePoints.get(0)); openlr.proto.schema.LocationReferencePoint last = locationReferencePointEncoder.encode(locationReferencePoints.get(locationReferencePoints.size() - 1)); Offsets offsets = rawLocationReference.getOffsets(); int positiveLength = locationReferencePoints.get(0).getDistanceToNext(); int positiveOffset = offsets.getPositiveOffset(positiveLength); openlr.proto.schema.SideOfRoad sideOfRoad = map(rawLocationReference.getSideOfRoad()); openlr.proto.schema.Orientation orientation = map(rawLocationReference.getOrientation()); PointAlongLineLocationReference pointAlongLineLocationReference = PointAlongLineLocationReference.newBuilder() .setFirst(first) .setLast(last) .setPositiveOffset(positiveOffset) .setSideOfRoad(sideOfRoad) .setOrientation(orientation) .build(); LocationReferenceData locationReferenceData = LocationReferenceData.newBuilder() .setPointAlongLineLocationReference(pointAlongLineLocationReference) .build(); return new LocationReferenceProtoImpl(rawLocationReference.getID(), LocationType.POINT_ALONG_LINE, locationReferenceData); } PointAlongLineEncoder(LocationReferencePointEncoder locationReferencePointEncoder); @Override LocationReference encode(RawLocationReference rawLocationReference);  }
@Test public void testEncodeLine() throws OpenLRProtoException { LocationReferencePointProtoImpl first = new LocationReferencePointProtoImpl( 1, 5.7, 53.5, 15.5, FunctionalRoadClass.FRC_3, FormOfWay.MULTIPLE_CARRIAGEWAY, 200, FunctionalRoadClass.FRC_4); LocationReferencePointProtoImpl last = new LocationReferencePointProtoImpl( 2, 5.6, 53.6, 165, FunctionalRoadClass.FRC_4, FormOfWay.MULTIPLE_CARRIAGEWAY); Offsets offsets = new OffsetsProtoImpl(20); RawLocationReference rawLocationReference = new RawPointAlongLocRef("1", first, last, offsets, SideOfRoad.LEFT, Orientation.AGAINST_LINE_DIRECTION); LocationReference locationReference = pointAlongLineEncoder.encode(rawLocationReference); assertNotNull(locationReference); assertEquals(locationReference.getID(), "1"); assertEquals(locationReference.getLocationType(), LocationType.POINT_ALONG_LINE); assertTrue(locationReference.isValid()); assertEquals(locationReference.getDataClass(), LocationReferenceData.class); Object locationReferenceData = locationReference.getLocationReferenceData(); assertNotNull(locationReferenceData); assertTrue(locationReferenceData instanceof LocationReferenceData); LocationReferenceData data = (LocationReferenceData) locationReferenceData; assertTrue(data.hasPointAlongLineLocationReference()); PointAlongLineLocationReference pointAlongLineLocationReference = data.getPointAlongLineLocationReference(); assertTrue(pointAlongLineLocationReference.hasFirst()); openlr.proto.schema.LocationReferencePoint firstLrp = pointAlongLineLocationReference.getFirst(); assertTrue(firstLrp.hasCoordinates()); Coordinates firstCoordinates = firstLrp.getCoordinates(); assertEquals(firstCoordinates.getLongitude(),5.7); assertEquals(firstCoordinates.getLatitude(), 53.5); assertTrue(firstLrp.hasLineAttributes()); LineAttributes firstLineAttributes = firstLrp.getLineAttributes(); assertEquals(firstLineAttributes.getBearing(), 15); assertEquals(firstLineAttributes.getFrc(), FRC.FRC_3); assertEquals(firstLineAttributes.getFow(), FOW.FOW_MULTIPLE_CARRIAGEWAY); assertTrue(firstLrp.hasPathAttributes()); PathAttributes firstPathAttributes = firstLrp.getPathAttributes(); assertEquals(firstPathAttributes.getDistanceToNext(), 200); assertEquals(firstPathAttributes.getLowestFrcAlongPath(), FRC.FRC_4); assertTrue(pointAlongLineLocationReference.hasLast()); openlr.proto.schema.LocationReferencePoint lastLrp = pointAlongLineLocationReference.getLast(); assertTrue(lastLrp.hasCoordinates()); Coordinates lastCoordinates = lastLrp.getCoordinates(); assertEquals(lastCoordinates.getLongitude(),5.6); assertEquals(lastCoordinates.getLatitude(), 53.6); assertTrue(lastLrp.hasLineAttributes()); LineAttributes lastLineAttributes = lastLrp.getLineAttributes(); assertEquals(lastLineAttributes.getBearing(), 165); assertEquals(lastLineAttributes.getFrc(), FRC.FRC_4); assertEquals(lastLineAttributes.getFow(), FOW.FOW_MULTIPLE_CARRIAGEWAY); assertEquals(pointAlongLineLocationReference.getPositiveOffset(), 20); assertEquals(pointAlongLineLocationReference.getSideOfRoad(), openlr.proto.schema.SideOfRoad.SIDE_OF_ROAD_LEFT); assertEquals(pointAlongLineLocationReference.getOrientation(), openlr.proto.schema.Orientation.ORIENTATION_AGAINST_LINE_DIRECTION); }