i'm not an engineer, but my best guess is that it depends on track geometry, mostly curvature, needed to achieve wanted speeds. whatever is on the railway's right of way has to be cleared first, whether trees, rocks, or just grass, after which the balast is laid, and then the tracks.
the factor that probably defines the shape of the track the most is the geography, like hills, mountains, valleys, including water bodies like rivers and lakes. if they are in the way, they are avoided by constructing turns as much as possible, because making more tunnels and bridges would be more expensive, especially for water bodies - tracks near rivers and lakes usually follow the outlines of their banks, because building loads of long bridges in a row would be insane and very exspensive and it takes too long. i'm guessing lakes are usually avoided, unless they are oblong and narrow, like rivers. this is probably why most newer high-speed lines aren't built in river valleys, but older lines often follow rivers.
speaking of smaller features, idk if they plan what they move in advance, or if they just get some excavators if they find something on the go, but i think it's gotta be some of that. usually, especially in flat regions, smaller obstacles are removed, and if there is a small stream or a pond, short bridges can be built, sometimes they put a tube and dump soil over it, some streams are just slightly diverted because they are small. if there are less trees in the way, they get removed, and if there is a small wash, they probably plan how to avoid that in advance, like, to go around it. if the land is kinda bumpy, and it usually is, building dykes and cutting into the ground is unavoidable.
↑ this is a photo i found - from https://herge.eklablog.com/tgv-pse-a129959650 - of a TGV sud-est going through some random rock, next to Graveson, a town near Avignon. the line is not an LGV (a high speed line), it has 1.5 kV and not 25 kV electrification, but it allows speeds of up to 200 km/h anyways. i looked at a map, an it seemed like there was enough space for the rock to be avoided, but maybe they just really needed to go through that rock to achieve the curvature needed for higher speeds.
↑ here is an example of how obstacles were found during research of the planned route, that i found very interesting. 2TDK (drugi tir Divača-Koper, or second track Divača-Koper) is a project aiming to significantly reduce travel times in Slovenia. there is a 400 meter elevation difference between two cities, and the line is mostly in tunnels. due to geology, which is mostly karst type of rock, there are many hidden caverns, most of which were unknown prior to the construction. when they discovered this, the engineers had to come up with designs for litteral underground bridges. the video is in slovene, but it's very visual, so i think it's moslty clear.
Welcome to the biggest online-encyclopedia for railway construction and technology! The Trackopedia-encyclopedia is full of knowledge and to
trackopedia is an interesting source i found about building tracks, and other things. i'm not sure if there is something about how exactly, and who removes smaller obstacles. tbh i got lost in it and just started reading random things lol. i searched 'obstacles' and found sth about obstacles on existing tracks and things like that, but also some articles that might be interesting
↑ alignment, about curve radii and gradients
The correct ballast cross-section, as defined by the permanent way regulations, is very important. Above all, it is important for the safety
↑ about machines used in building tracks
i also happen to know that @rikkita is a civil engineer, and she told me they had some course about building tracks in her college so maybe she knows sth abt that.