core icon indicating copy to clipboard operation
core copied to clipboard

Get the id by latitude and logitude

Open salarnz opened this issue 3 years ago • 2 comments

Hi im using openstreetmap online api for getting the id from latitude an longitude(then i use this id to get the max speed limit of that road). now im using OsmSharp to do this job offline. in the first step how can i get the id from latitude and longitude ?

salarnz avatar Jun 22 '22 17:06 salarnz

Elements are not indexed by their location so there is no built-in efficient way to retrieve them that way. You could either build your own collection using lat/lon as the key or enumerate every element and compare it's location to your target location.

Looking for elements by proximity was something I did a lot and needed to be efficient. My approach was to create two duplicate lists of elements, one sorted by lat and the other by lon. Each lookup-by-location was done by intersecting a range of candidates from the two collections.

The locations of a node is simple, the "location" of a way or relation takes a little math.

An example: https://github.com/blackboxlogic/OsmPipeline/blob/b93e9ecd7d5487d7c6879cac4144ab82a15f3f19/Fittings/Geometry.cs#L350

blackboxlogic avatar Aug 02 '22 16:08 blackboxlogic

@blackboxlogic thanks for the idea, this's what I need

IldarKhayrutdinov avatar Aug 18 '22 15:08 IldarKhayrutdinov