Skip to content

Commit

Permalink
DROTH-3397 moved getTwoDigitLaneCode to LaneNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
anttiahopeltositowise committed Nov 8, 2022
1 parent 80f9e75 commit ce47f21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fi.liikennevirasto.digiroad2.lane

import fi.liikennevirasto.digiroad2.Point
import fi.liikennevirasto.digiroad2.asset.{AdministrativeClass, TrafficDirection}
import fi.liikennevirasto.digiroad2.asset.SideCode.{AgainstDigitizing, BothDirections, TowardsDigitizing}
import fi.liikennevirasto.digiroad2.asset.{AdministrativeClass, SideCode, TrafficDirection}
import fi.liikennevirasto.digiroad2.linearasset.PolyLine
import org.joda.time.DateTime

Expand Down Expand Up @@ -99,6 +100,20 @@ object LaneNumber {
lanesNumbers.exists(x => x.againstDirection == laneCode || x.towardsDirection == laneCode || x.oneDigitLaneCode == laneCode) || MainLane.motorwayMaintenance == laneCode
}

def getTwoDigitLaneCode(roadAddressSideCode: SideCode, laneSideCode: SideCode, oneDigitLaneCode: Int): Int = {
val laneCodeFirstDigit = roadAddressSideCode match {
case TowardsDigitizing if laneSideCode == TowardsDigitizing => 1
case TowardsDigitizing if laneSideCode == AgainstDigitizing => 2

case AgainstDigitizing if laneSideCode == TowardsDigitizing => 2
case AgainstDigitizing if laneSideCode == AgainstDigitizing => 1
case _ if laneSideCode == BothDirections => 3
}
val twoDigitLaneCode = laneCodeFirstDigit.toString.concat(oneDigitLaneCode.toString).toInt

twoDigitLaneCode
}

case object MainLane extends LaneNumber {
def towardsDirection = 11
def againstDirection = 21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fi.liikennevirasto.digiroad2.client.viite.SearchViiteClient
import fi.liikennevirasto.digiroad2.client.{RoadLinkClient, RoadLinkFetched}
import fi.liikennevirasto.digiroad2.client.vvh.ChangeInfo
import fi.liikennevirasto.digiroad2.lane.LaneNumber.MainLane
import fi.liikennevirasto.digiroad2.lane.{LaneEndPoints, LaneProperty, LanePropertyValue, LaneRoadAddressInfo, NewLane, PersistedHistoryLane, PersistedLane, PieceWiseLane}
import fi.liikennevirasto.digiroad2.lane.{LaneEndPoints, LaneNumber, LaneProperty, LanePropertyValue, LaneRoadAddressInfo, NewLane, PersistedHistoryLane, PersistedLane, PieceWiseLane}
import fi.liikennevirasto.digiroad2.linearasset.RoadLink
import fi.liikennevirasto.digiroad2.postgis.PostGISDatabase
import fi.liikennevirasto.digiroad2.service.lane.LaneService
Expand Down Expand Up @@ -237,7 +237,7 @@ object LaneUtils {
val roadLink = roadLinks.find(_.linkId == lane.linkId).get
val roadAddressSideCode = SideCode.apply(roadLink.attributes("SIDECODE").asInstanceOf[Int])
val laneSideCode = SideCode.apply(lane.sideCode)
val twoDigitLaneCode = getTwoDigitLaneCode(roadAddressSideCode, laneSideCode, lane.laneCode)
val twoDigitLaneCode = LaneNumber.getTwoDigitLaneCode(roadAddressSideCode, laneSideCode, lane.laneCode)

lane.copy(laneCode = twoDigitLaneCode)
})
Expand All @@ -248,7 +248,7 @@ object LaneUtils {
val roadLink = roadLinks.find(_.linkId == lane.linkId).get
val roadAddressSideCode = SideCode.apply(roadLink.attributes("SIDECODE").asInstanceOf[Int])
val laneSideCode = SideCode.apply(lane.sideCode)
val twoDigitLaneCode = getTwoDigitLaneCode(roadAddressSideCode, laneSideCode, lane.laneCode)
val twoDigitLaneCode = LaneNumber.getTwoDigitLaneCode(roadAddressSideCode, laneSideCode, lane.laneCode)

lane.copy(laneCode = twoDigitLaneCode)
})
Expand All @@ -260,26 +260,12 @@ object LaneUtils {
val roadAddressSideCode = SideCode.apply(lane.attributes("SIDECODE").asInstanceOf[Int])
val laneSideCode = SideCode.apply(lane.sideCode)
val oneDigitLaneCode = laneService.getLaneCode(lane)
val twoDigitLaneCode = getTwoDigitLaneCode(roadAddressSideCode, laneSideCode, oneDigitLaneCode)
val twoDigitLaneCode = LaneNumber.getTwoDigitLaneCode(roadAddressSideCode, laneSideCode, oneDigitLaneCode)

val laneCodeAttribute = Seq(LaneProperty("lane_code", Seq(LanePropertyValue(twoDigitLaneCode))))
val newLaneAttributes = lane.laneAttributes.filterNot(_.publicId == "lane_code") ++ laneCodeAttribute
lane.copy(laneAttributes = newLaneAttributes)
})
}

def getTwoDigitLaneCode(roadAddressSideCode: SideCode, laneSideCode: SideCode, oneDigitLaneCode: Int): Int = {
val laneCodeFirstDigit = roadAddressSideCode match {
case TowardsDigitizing if laneSideCode == TowardsDigitizing => 1
case TowardsDigitizing if laneSideCode == AgainstDigitizing => 2

case AgainstDigitizing if laneSideCode == TowardsDigitizing => 2
case AgainstDigitizing if laneSideCode == AgainstDigitizing => 1
case _ if laneSideCode == BothDirections => 3
}
val twoDigitLaneCode = laneCodeFirstDigit.toString.concat(oneDigitLaneCode.toString).toInt

twoDigitLaneCode
}

}

0 comments on commit ce47f21

Please sign in to comment.