Libre-TrainSim / Libre-TrainSim

Train Simulator written in Godot Engine - Free for everyone.
https://www.libretrainsim.de/
GNU General Public License v3.0
299 stars 47 forks source link

Information: Automatical import track from OpenStreetmap.org #480

Open opi99 opened 1 year ago

opi99 commented 1 year ago

Hi,

I like to inform about an automatic import of tracks from OSM I tried to develop today by using PHP. The used track for testing is "DB Strecke 6052" from Leipzig, Miltitzer-Allee to Leipzig-Plagwitz.

opi99 commented 1 year ago

Screenshot_20230211_195845

opi99 commented 1 year ago

I'd liked to add the tscn file here, but I can't upload .tscn or .log or .txt ... github says "Something went really wrong" :-(

opi99 commented 1 year ago

I'd like to get some help/information how the "connect" between lines is detected. Also, till yet, I didn't see a use of "start_pos" and "end_pos" also "start_rot" and "end_rot". The automatism generates for every point from OSM a track to the next point (WGS84 conversion to plane/cardinal coordinates and calculating the distance). But I don't know yet, how to get this "curved" and the tracks "connected".

HaSa1002 commented 1 year ago

Hey, first of all thanks for sharing your project. You can try https://transfer.sh or pastebin. Rails are connected if they share approximately the same position and rotation. If you're asking how the curved rails are made, then the answer is by using circles. If that's not the question then, please help me understanding.

DasCapschen commented 1 year ago

First of all: Great! Cool that you actually made this work so far. That's really cool!

But I don't think that taking the vector data from OSM and translating all the points of paths 1-to-1 into rails is the way to go. That way, you probably end up with much more rails than necessary, and also lose curvature. This is a problem I have not yet solved myself, but plan to tackle some time. I have a qGis file lying around to experiment with different processing steps :)

How the game checks if 2 rails are connected (see Rail.gd:update_connections()):

opi99 commented 1 year ago

Hi,

yes, I know, it is a starting point, for more processing I need curved connection and so on. Will see if this leads to "less" tracks then OSM points or not.

How is start_rot/end_rot calculated from the input values? It seams a track base is the Startpoint (x,y,z) and Rotation as also Length + Radius (for Endpoint). We will see ;)

opi99 commented 1 year ago

After thinking twice over the issue of curves, a Spline or Bezier Curved Line isn't possible, as LibreTraimSim uses circles.

So, from point to point we could have one "circled line" or multiple. But it also could be that multiple points could be on one "circled line". Example 1: Connectors for parallel tracks. They have on switch 1 a track with radius x, which will change to a track with radius -x to get a connection with switch 2. This will be 2 node points with one line in OSM.

Example 2: As OSM have only node points with straight lines between, a track with a 90 degree curve may consist of multiple nodes with short straight lines to get this visually as curve. For LibreTrainSim this (could) be on track of length X with radius r.

ATM I didn't found a good library or method to calculate this.

opi99 commented 1 year ago

Test.tscn https://pastebin.com/EJTEUC2X

Track 6052 and 6383 resulting in 81 OSM ways and 558 OSM nodes. 556 Tracks generated. It seams I need to rotate it by -90 degree. ;-)

Screenshot_20230213_161224

merspieler commented 1 year ago

Is it possible you share your code and steps to do this? Also, I guess you don't take elevation into account yet, right? There are train lines with interesting runs through valleys such as Ulm -> Stuttgart which would be interesting to have with not only flat area around them.

HaSa1002 commented 1 year ago

Well we'd need terrain first :D That's 0.10 material, though.

DasCapschen commented 1 year ago

To add height information to Vector data from Raster data (heightmaps), you could use QGIS' Drape function.
https://docs.qgis.org/3.22/en/docs/user_manual/processing_algs/qgis/vectorgeometry.html#drape-set-z-value-from-raster

opi99 commented 1 year ago

Till yet, I've no height information, it is also very experimental and code base is in rewrite ... I'll share it afterwards in a github repository here.

At the moment I try to get the ways more aligned and respect switches. I also try to set the signals.

Mathias-Fuchs commented 1 year ago

From the discussion of the comments I see that train tracks need to be decomposed into straight line segments, and circular arcs before they can be understood by LibreTrainSim. However, in realty curved train tracks should usually be clothoids. Before people import their tracks to straight lines and arcs, wouldn't it make sense to first add clothoid support to the engine? Otherwise, someone will do it one day and then the process to import tracks will be very different. I think it is not just a geometrical issue. Some day, there will be very accurate physics in LibreTrainSim which need to know about lateral forces and accelerations experienced by the wheels, and these depend a lot on the type of curve: in an arc, it is just a constant centrifugal force, and in a clothoid, the force grows along the curve.

DasCapschen commented 1 year ago

Thank you for your comment @Mathias-Fuchs !
Until recently, I was not aware of what clothoids are or that they even existed, nor that real train tracks are that kind of shape.
But I think for many more reasons than those you mentioned, it would be important to add clothoid support to LTS. I will open a ticket for it, and perhaps I can even implement it soon :)