OpenStreetMapX.jl icon indicating copy to clipboard operation
OpenStreetMapX.jl copied to clipboard

what is the logic of the following function "find_segments"?

Open bsnyh opened this issue 5 years ago • 1 comments

function find_segments(nodes::Dict{Int,T}, highways::Vector{OpenStreetMapX.Way}, intersections::Dict{Int,Set{Int}}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}
    segments = OpenStreetMapX.Segment[]
    intersect = Set(keys(intersections))
    for highway in highways
        firstNode = 1
        for j = 2:length(highway.nodes)
            if highway.nodes[firstNode] != highway.nodes[j] && (in(highway.nodes[j], intersect)|| j == length(highway.nodes))
                if !reverseway(highway)
                    seg = OpenStreetMapX.Segment(highway.nodes[firstNode],highway.nodes[j],highway.nodes[firstNode:j], OpenStreetMapX.distance(nodes, highway.nodes[firstNode:j]), highway.id)
                    push!(segments,seg)
                else
                    seg = OpenStreetMapX.Segment(highway.nodes[j],highway.nodes[firstNode],reverse(highway.nodes[firstNode:j]), OpenStreetMapX.distance(nodes, highway.nodes[firstNode:j]), highway.id)
                    push!(segments,seg)
                end
                if !oneway(highway)
                    seg = OpenStreetMapX.Segment(highway.nodes[j],highway.nodes[firstNode],reverse(highway.nodes[firstNode:j]), OpenStreetMapX.distance(nodes, highway.nodes[firstNode:j]), highway.id)
                    push!(segments,seg)
                end
				firstNode = j
            end
        end
    end
    return segments
end

Hi, I have a question about the logic of the first if statement. I do not quite understand how it works. I mean, why is it exactly like this? Based on my understanding, highway.nodes[firstNode] is always not the same as highway.nodes[j], right? Moreover, why do we require highway.nodes[j] in the set intersect? It is rather strange to me at least. Could you kindly clarify a little bit?

bsnyh avatar Aug 18 '19 19:08 bsnyh

Since Ways represent any kind of shape I understand that we can have a situation where the same nodes can occur more than once in a single Way. From graph routing point of view this means having an unnecessary cycle and hence should be avoided. Perhaps @bartoszpankratz can elaborate more on this.

pszufe avatar Aug 27 '19 17:08 pszufe