Terrain height detection


I currently have a model rendered as a “terrain”, in which I want to place buildings on.
Since I have specific (x, y) coordinates that I want to place my buildings on, the only problem left is to get the Z-axis of the terrain so that I can offset my building accordingly.
I tried using the GeomVertexReader as such:

geomNodeCollection = self.terrain.findAllMatches('**/+GeomNode')
    for nodePath in geomNodeCollection:
        geomNode = nodePath.node()
        for i in range(geomNode.getNumGeoms()):
            geom = geomNode.getGeom(i)
            vdata = geom.getVertexData()
            vertex = GeomVertexReader(vdata, 'vertex')
            while not vertex.isAtEnd():
                v = vertex.getData3f()

However, I could not get a decent conversion from LVecBase3 to actual Points that I can use to offset the building. Is there a possible solution to this? Any built-in functions that I’m missing?

Thanks for you help!

I do not know if I understand correctly ? Here is an example .

Clicks on the surface , in the console are the coordinates

import direct.directbase.DirectStart

from pandac.PandaModules import CollisionTraverser,CollisionNode   
from pandac.PandaModules import CollisionHandlerQueue,CollisionRay, BitMask32  

def pick(): 
    if base.mouseWatcherNode.hasMouse():
        mpos = base.mouseWatcherNode.getMouse() 
        pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())   
        for i in xrange(pickerQ.getNumEntries()): 
            entry = pickerQ.getEntry(i)   
            print 'entry '+str(entry.getSurfacePoint(render))  

terrain = loader.loadModel("Plane.egg")
terrain.setPos(0, 0, 0)
picker = CollisionTraverser()   
pickerQ = CollisionHandlerQueue()  
pickerCollN = CollisionNode('mouseRay')  
pickerCamN = base.camera.attachNewNode(pickerCollN)      
pickerRay = CollisionRay()     
picker.addCollider(pickerCamN, pickerQ)  
base.accept('mouse1', pick) 

Another wonderful example:

Plane.egg (23 KB)