pszufe / OpenStreetMapX.jl

OpenStreetMap (*.osm) support for Julia 1.0 and up
MIT License
123 stars 24 forks source link

where to find this OpenStreetMapX.nearest_node(m, features[key]) function? #18

Open bsnyh opened 5 years ago

bsnyh commented 5 years ago

Hi, I hope that I did not misunderstand anything. I was a bit confused about the following code.

####################################################
### For Each Feature Find the Nearest Graph Node ###
####################################################

function features_to_graph(m::OpenStreetMapX.MapData, features::Dict{Int,Tuple{String,String}}) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})
    features_to_nodes = Dict{Int,Int}()
    sizehint!(features_to_nodes,length(features))
    for (key,value) in features
        if !haskey(m.v,key)
            features_to_nodes[key] = OpenStreetMapX.nearest_node(m,features[key])
        else
            features_to_nodes[key] = key
        end
    end
    return features_to_nodes
end

Firstly, what is exactly "for each feature, find the nearest graph node"? What does it mean? Secondly, where to find this function OpenStreetMapX.nearest_node(m, features[key])?

bartoszpankratz commented 5 years ago

Hi,

In the most basic scenario, when you use features from the osm file you don't need to bother yourself with this function, features are already nodes. Hovewer, when you want to use the features from the outside file (e.g. you got some special list of objects necessary in your model) or filter the roads (e.g. you only interested in having highways) then it might be quite useful. The code is here

bsnyh commented 5 years ago

Hi, bartoszpankratz, Great! Thank you a lot. You mean the code is as the following, right?

function nearest_node(m::MapData, loc::ENU, vs_only::Bool=true)
    vs_only ? nearest_node(m.nodes,loc, keys(m.v)) : nearest_node(m.nodes,loc)
end
bartoszpankratz commented 5 years ago

Yeah, that's right. My mistake.

bsnyh commented 5 years ago

Or am I wrong also? The features parameter in the function features_to_graph is a Dict{Int,Tuple{String,String}}......

bartoszpankratz commented 5 years ago

Ok, sorry. I have changed a lot, someone mess around with this function and no one have update it. I remeber that at the beginning this function was written to work with external data sources, like CSV files, thats the reason why features are Dict{Int,Tuple{String,String}} - Tuple{String,String} was the pair of coordinates which then was translated to LLA type. Thank you! We will repair it obviously.