Are coordinates on a specific railway trac?

Hi there,

Sorry for the stupid newbie questions.
I have 2 questions:
1: How (using which select query) can I identify only the railway track in the OSM database?

2: How can I check (again from the database out) if a coordinate (± 10 meters:because of the GPS precision) is on a specific railway track?

Thanks

The first question: there are many ways up the mountain, depending on how big an area you want to analyse. Overpass might do for a smaller area, if bigger, there are full dumps for countries and continents available you can read into a database. I liked working with sqlite for this kind of thing.

The second: if it is an analysis on your computer, you could do this with this qgis (or another gis package) . Start with your coordinates as a point layer. Use the buffer function to make 10 meter circles out of them. Then use intersect or spatial join to find out which points are near what railway.

First of all thank you for the answer.

I think I have to be more precise.
I have already all the country specific data in my database (actually even 2 databases: 1 Postgres and I SQLite. The first issue: The schema of those two are different :frowning: ).
My biggest issue is that I do not understand (yet) the schema. I don’t know which key-value pairs I have to use to identify a railway track. As I’ve told you I’m a beginner to the mapping world. :frowning:

As for the first question:I just simply would like to put (let’s say every 20-50 meters) a dot on a map where there is a railway track. Those points could BTW constitute the database for the question #2

The task I’m looking for to accomplish in the question 2 is the following:
Given a coordinate I have to know whether it is on a railway track or not.

A pseudo query would be (of course this schema does not correspond to any OSM DB schema):

select count(*) as C from points P
where myLat between P.lat - 0.0001 and P.lat + 0.0001
anc myLon between P.lon - 0.0001 and P.lon + 0.0001
and P.kind = ‘railway’

How should I write this query within the real OSM DB?

Depends on what database schema you’re using. There are at least five plus a lot of customized ones. If you don’t really care which one you’ll use: What language are you coding in and for what platform? Is using a Web-API like Overpass allowed? Maybe then someone has a better suggestion :wink:

railway=rail for regular railways (mostly 1435mm),
railway=narrow_gauge for smaller gauges (mostly a different law),
railway=light_rail for something special (differs a bit around the world),
railway=tram for tramways,
railway=disused, =abandoned and =razed for former railways (any of the above).
But not simply all railway=*, because that would also contain i.e railway=platform, railway=station or railway=no.