Hi, I was reading the following function excerpted from OpenStreetMapX package and got a bit confused. Could anyone please let me know how to understand the following function, especially
new_node = OpenStreetMapX.boundary_point(nodes[way.nodes[i-1]], nodes[way.nodes[i]],bounds)
new_id = OpenStreetMapX.add_new_node!(nodes, new_node)
way.nodes[i-1] = new_id
The following is the function.
function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, way::OpenStreetMapX.Way)
valid = falses(length(way.nodes)+2)
n = 1
while n <= length(way.nodes)
if !haskey(nodes, way.nodes[n])
splice!(way.nodes, n)
splice!(valid, n+1)
else
valid[n+1] = OpenStreetMapX.inbounds(nodes[way.nodes[n]], bounds)
n += 1
end
end
if sum(valid) == 0
return true
elseif sum(valid) < (length(valid)-2)
leave = trues(length(way.nodes))
for i in 2:(length(valid)-1)
if !valid[i]
if valid[i-1] != valid[i]
if !OpenStreetMapX.onbounds(nodes[way.nodes[i-2]], bounds)
new_node = OpenStreetMapX.boundary_point(nodes[way.nodes[i-2]], nodes[way.nodes[i-1]],bounds)
new_id = OpenStreetMapX.add_new_node!(nodes, new_node)
way.nodes[i-1] = new_id
else
leave[i-1] = false
end
elseif valid[i] != valid[i+1]
if !OpenStreetMapX.onbounds(nodes[way.nodes[i]], bounds)
new_node = OpenStreetMapX.boundary_point(nodes[way.nodes[i-1]], nodes[way.nodes[i]],bounds)
new_id = OpenStreetMapX.add_new_node!(nodes, new_node)
way.nodes[i-1] = new_id
else
leave[i-1] = false
end
else
leave[i-1] = false
end
end
end
way.nodes = way.nodes[leave]
return false
else
return false
end
end