DeloitteOptimalReality / LightOSM.jl

A Julia package for downloading and analysing geospatial data from OpenStreetMap APIs.
https://deloitteoptimalreality.github.io/LightOSM.jl/docs
Other
47 stars 12 forks source link

Is there a way to extract the lat/long coordinates for each point along a "way?" #65

Open 00krishna opened 2 years ago

00krishna commented 2 years ago

So I get that a way represents a set of edges between nodes in an OSM graph. I was wondering, is there a method to query all of the points that fall along a way? That is, I would like to identify all of the latitude and longitude points along a way.

I did google this question, and it seems like other people push the OSM graph into a database like PostGIS to do this. I was just wondering if there was a way to do this without pulling down to a database? Thanks.

mmiller-max commented 2 years ago

There isn't a direct method (currently) but with the Way and the OSMGraph you could do something like this:

# setup
julia> g = graph_from_download(:point, point=GeoLocation(-37.8142176, 144.9631608), radius=5);

julia> way = first(values(g.ways));

# Use way.nodes to get a list of nodes (possibly not in order, see https://github.com/DeloitteDigitalAPAC/LightOSM.jl/issues/54
julia> way.nodes
2-element Vector{Int64}:
 1479930102
  589708331

# Get an array of GeoLocations for each node
julia> [g.nodes[id].location for id in way.nodes]
2-element Vector{GeoLocation}:
 GeoLocation(-37.8210097, 144.9549332, 0.0)
 GeoLocation(-37.8208828, 144.9548856, 0.0)

# Get an array of Lat Lon pairs for each node
julia> [[g.nodes[id].location.lat, g.nodes[id].location.lon] for id in way.nodes]
2-element Vector{Vector{Float64}}:
 [-37.8210097, 144.9549332]
 [-37.8208828, 144.9548856]

If it's useful, we could add such a function to LightOSM

00krishna commented 2 years ago

@mmiller-max Hey thanks for providing this code. This is very helpful. Yeah, I can take these node pairs and write a function to compute the line between them--and then sample points along that line.

I think that the tricky thing is the compute time for something like this. Does LightOSM.jl support stuff like multi-core or GPU processing? These calculations can be parallelized, since there is no dependency between node pairs. If I wanted to do this in a multi-core manner, I would need to do a bunch of checks to see how many cores are available, installing cuda arrays, etc. So I should probably check about whether any of that exists within LightOSM already for any of your current processing? I don't want to mess up anything that you have already got working.

mmiller-max commented 2 years ago

Currently there is no multi-threading/processing in LightOSM related to this, the only time multiple threads are currently used is in creation of a graph if Dijkstra states are being used (here).

However there is no reason why you couldn't parallelise the above operation yourself - you are not modifying the graph in anyway, just accessing properties from it. Something like Polyester.jl might provide a convenient way for you to multi-thread.

I'm not very familiar with GPU processing so can't help as much there, sorry.