Skip to content

Commit

Permalink
#278 monitor route analysis - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Feb 11, 2024
1 parent af11dfc commit 387c571
Show file tree
Hide file tree
Showing 7 changed files with 539 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ object MonitorUpdateTool {
}
}
val tool = new MonitorUpdateTool(database, overpassQueryExecutor)
tool.testUpdate("A", "EV1")
// tool.update()
tool.update()
}
("update completed", ())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.nio.charset.Charset
object DownloadRelationTool {

private val routes = Seq(
"route1" -> 6968141,
"route1" -> 11524393,
)

def main(args: Array[String]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.locationtech.jts.geom.GeometryFactory
import org.springframework.stereotype.Component

@Component
class MonitorRouteOsmSegmentAnalyzerImpl() extends MonitorRouteOsmSegmentAnalyzer {
class MonitorRouteOsmSegmentAnalyzerImpl extends MonitorRouteOsmSegmentAnalyzer {

private val geometryFactory = new GeometryFactory
private val log = Log(classOf[MonitorRouteOsmSegmentAnalyzerImpl])
Expand All @@ -32,7 +32,7 @@ class MonitorRouteOsmSegmentAnalyzerImpl() extends MonitorRouteOsmSegmentAnalyze
Seq.empty
}

val routeSegments = elementGroups.zipWithIndex.map { case (elementGroup, index) =>
val routeSegments = elementGroups.zipWithIndex.flatMap { case (elementGroup, index) =>
val lineStrings = elementGroup.elements.map { element =>
val coordinates = element.nodeIds.flatMap(nodeMap.get)
geometryFactory.createLineString(coordinates.toArray)
Expand All @@ -44,31 +44,41 @@ class MonitorRouteOsmSegmentAnalyzerImpl() extends MonitorRouteOsmSegmentAnalyze
case _ => true
}
}
val startNodeId = forwardElements.head.forwardStartNodeId
val endNodeId = forwardElements.last.forwardEndNodeId

val meters = Math.round(lineStrings.map(lineString => Haversine.meters(lineString)).sum)
val allCoordinates = lineStrings.flatMap(lineString => lineString.getCoordinates.toSeq)
val bounds = MonitorRouteAnalysisSupport.toBounds(allCoordinates)

val geometryCollection = geometryFactory.createGeometryCollection(lineStrings.toArray)

val geoJson = MonitorRouteAnalysisSupport.toGeoJson(geometryCollection)

val segment = MonitorRouteSegment(
id = index + 1,
startNodeId,
endNodeId,
meters,
bounds,
geoJson
)

MonitorRouteSegmentData(
id = index + 1,
segment,
lineStrings
)

if (forwardElements.isEmpty) {
// TODO should still look at backwardElements !!!
None
}
else {

val startNodeId = forwardElements.head.forwardStartNodeId
val endNodeId = forwardElements.last.forwardEndNodeId

val meters = Math.round(lineStrings.map(lineString => Haversine.meters(lineString)).sum)
val allCoordinates = lineStrings.flatMap(lineString => lineString.getCoordinates.toSeq)
val bounds = MonitorRouteAnalysisSupport.toBounds(allCoordinates)

val geometryCollection = geometryFactory.createGeometryCollection(lineStrings.toArray)

val geoJson = MonitorRouteAnalysisSupport.toGeoJson(geometryCollection)

val segment = MonitorRouteSegment(
id = index + 1,
startNodeId,
endNodeId,
meters,
bounds,
geoJson
)

Some(
MonitorRouteSegmentData(
id = index + 1,
segment,
lineStrings
)
)
}
}
val osmDistance = routeSegments.map(_.segment.meters).sum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class StructureElementAnalyzer(wayMembers: Seq[WayMember], traceEnabled: Boolean

finalizeCurrentElement()
val wayNodeIds = closedLoopLink.nodeIds
// TODO for walking routes, should choose shortest path here instead of adding both forward and backward element
// TODO for hiking routes, should choose shortest path here instead of adding both forward and backward element
StructureUtil.closedLoopNodeIds(wayNodeIds.head, endNodeId, wayNodeIds) match {
case None => throw new Exception("internal error TODO better message")
case Some(nodeIds) =>
Expand Down Expand Up @@ -151,7 +151,7 @@ class StructureElementAnalyzer(wayMembers: Seq[WayMember], traceEnabled: Boolean
case Some(endNodeId) =>

finalizeCurrentElement()
// TODO for walking routes, should choose shortest path here instead of adding both forward and backward element
// TODO for hiking routes, should choose shortest path here instead of adding both forward and backward element
StructureUtil.closedLoopNodeIds(startNodeId, endNodeId, closedLoopLink.nodeIds) match {
case None => throw new Exception("internal error TODO better message")
case Some(nodeIds) =>
Expand Down Expand Up @@ -191,7 +191,7 @@ class StructureElementAnalyzer(wayMembers: Seq[WayMember], traceEnabled: Boolean

finalizeCurrentElement()
val wayNodeIds = closedLoopLink.nodeIds
// TODO for walking routes, should choose shortest path here instead of adding both forward and backward element
// TODO for hiking routes, should choose shortest path here instead of adding both forward and backward element
StructureUtil.closedLoopNodeIds(startNodeId, endNodeId, wayNodeIds) match {
case None =>
throw new Exception("internal error TODO better message")
Expand Down

0 comments on commit 387c571

Please sign in to comment.