In Terragen the displacement pipeline and the colour/shading pipeline are processed at different times. First, all of the shaders are used to displace the surface of the object so that the final displacement is known. Then all of the shaders are used to calculate colour and shading according to the final displacement. In your setup the Distribution Shader won't see any displacement because it's applied to an object that has no displacement (intentionally, I assume). It doesn't matter that its input can generate displacement, because displacement isn't automatically calculated when a shader is used as a mask; the mask shader only generates colour.
A different method is needed, and this is where Dune's method is useful. The terrain needs to be converted to a value using "Displacement to Scalar" node. This node requests displacement from its input during the colour/shading pipeline and converts it to a value that can be used as a scalar or a greyscale colour. This then can be used as a mask, but you'll want to remap the values to a range between 0 and 1 using a Colour Adjust Shader, or Smooth Step Scalar, or something like that.
Another thing to remember: Although data usually seems to flow from top to bottom (from a shader's output to the input port of another node), things are really calculated in reverse. An object or shader requests data from its input(s). Therefore the values generated by a shader depend on the context in which they are requested.
Matt