height of the terrain at given lat and lon

classic Classic list List threaded Threaded
6 messages Options
bhanu406 bhanu406
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

height of the terrain at given lat and lon

Hi,
I am trying to load the 3D model on to the earth by the following code.

osg::Node *model = osgDB::readNodeFile("uh60.3ds");
const SpatialReference* srs = mapNode->getMapSRS()->getGeographicSRS();

GeoTransform* xform = new GeoTransform();
xform->addChild(model);

double z = 10;//assuming the terrain height
double x = -71.0763;
double y = 42.34425;

GeoPoint point(srs, x, y, z, ALTMODE_ABSOLUTE);
xform->setPosition(point);

It is working fine. But, I want exact terrain height(z) at above x and y positions.Is there any method to get terrain height ?


       
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: height of the terrain at given lat and lon

bhanu,

You can use MapNode::getTerrain()->getHeight() to query the scene graph's terrain height at a point. Of course, this can change as data pages in, so if you want your model to stay on the terrain, you can use the ALTMODE_RELATIVE mode in your GeoPoint:

GeoPoint point(srs, x, y);

Hope this helps.
Glenn Waldron / Pelican Mapping
bhanu406 bhanu406
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: height of the terrain at given lat and lon

In reply to this post by bhanu406
hi,
I tried with following code.
int main(int argc, char **argv)
       {
                osg::Group* root = new osg::Group;

                osgEarth::Map * map = new Map;

                osgEarth::Drivers::GDALOptions gdal;
                gdal.url() = "../tiled/texture_EPSG_4326.tif";
                ImageLayer* layer = new ImageLayer("EPSG:4326", gdal);
                map->addImageLayer(layer);

                osgEarth::Drivers::GDALOptions gdal_dem;
                gdal_dem.url() = "../dem_EPSG_4326.tif";
                ElevationLayer* layer1 = new ElevationLayer("EPSG:4326", gdal_dem);
                map->addElevationLayer(layer1);

               osgEarth::MapNode* mapNode = new MapNode(map);
                root->addChild(mapNode);
               
               osg::Node *model = osgDB::readNodeFile("uh60.3ds");

              const SpatialReference* srs = mapNode->getMapSRS()->getGeographicSRS();

                GeoTransform* xform = new GeoTransform();
                xform->addChild(model);
                double z;
                double x = -71.0763;
                double y = 42.34425;
               mapNode->getTerrain()->getHeight(srs, x, y, &z);//Here i am getting z value is -11543

              GeoPoint point(srs, x, y, z, ALTMODE_RELATIVE);
       
                xform->setPosition(point);
       
                root->addChild(xform);

              osgViewer::Viewer viewer;

              EarthManipulator* manip = new EarthManipulator();
              viewer.setCameraManipulator(manip);
             viewer.setSceneData(root);
            return viewer.run();
     }
I am getting incorrect z value. Is there any thing wrong in my code ?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: height of the terrain at given lat and lon

That is because the terrain scene graph doesn't even exist before you call viewer.run().

If you want your model on the terrain, use z=0 with ALTMODE_RELATIVE.
Glenn Waldron / Pelican Mapping
bhanu406 bhanu406
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: height of the terrain at given lat and lon

In reply to this post by bhanu406
Hi,
I tried with following code
                double z = 0;
                double x = -71.0763;
                double y = 42.34425;

               GeoTransform* xform = new GeoTransform();
                xform->addChild(model);
              GeoPoint point(srs, x, y, z, ALTMODE_RELATIVE);
       
                xform->setPosition(point);

Even if i set ALTMODE_RELATIVE with z = 0. I am not getting model on terrain. Is there any example for loading 3D model on the terrain ? Please send me the link.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: height of the terrain at given lat and lon

Loading...