查看: 2415|回复: 1

osgdem构建地形,在osg应用程序中怎样获得模型的实际投影坐标

[复制链接]

该用户从未签到

发表于 2013-4-8 16:42:06 | 显示全部楼层 |阅读模式
原有的tif文件的坐标系是经纬度坐标,用gdalinfo查看tif信息如下:


使用gdalwarp转换成merctor投影:gdalwarp -t_srs “+proj=merc +datum=WGS84” 0-40.tif  merctor.tif, merctor.tif用gdalinfo查看信息如下:

然后用osgdem将merctor.tif生成平面模型:osgdem --cs “+proj=merc +datum=WGS84” –xx 10 –yy 10 –v 0.5 –l 3 –o merctor.ive
之后在osg的应用程序中将merctor.ive加入,用osgpick拾取模型:

osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;

     osg::ref_ptr<osg::Group>group=new osg::Group;

     osg::ref_ptr<osg::Node> node= osgDB::readNodeFile("merctor.ive");

osg::ref_ptr<osg::CoordinateSystemNode> csn=new osg::CoordinateSystemNode;

     csn->setEllipsoidModel(new osg::EllipsoidModel);

     csn->addChild(node);

     csn->setFormat("ROJ4");

csn->setCoordinateSystem("+proj=merc +datum=WGS84");

osg::ref_ptr<osgText::Text> updatetext = new osgText::Text();

     CreateHUD *hudText= new CreateHUD();

     csn->addChild(hudText->createHUD(updatetext.get()));

viewer->setSceneData(csn);

     viewer->addEventHandler(new osgViewer::WindowSizeHandler);

     viewer->addEventHandler(new osgViewer::StatsHandler);

     //添加PICK事件处理器

viewer->addEventHandler(new CPickHandler(updatetext.get()));
其中的CPickHandler拾取相交部分:

if (viewer->computeIntersections(x,y,intersections))

     {

osg::ref_ptr<osg::CoordinateSystemNode> csn=dynamic_cast<osg::CoordinateSystemNode*>(viewer->getSceneData()->asGroup());

         osg::EllipsoidModel* em=csn->getEllipsoidModel();

         //得到相交交集的交点

for(osgUtil:ineSegmentIntersector::Intersections::iterator hitr = intersections.begin();hitr != intersections.end();++hitr)

         {

              os<<"Mouse in World  X:"<< hitr->getWorldIntersectPoint().x()<<"Y: "<<

hitr->getWorldIntersectPoint().y()<<"Z: "<< hitr->getWorldIntersectPoint().z()<<std::endl ;


              //转换坐标系

              double x,y,z;

//平面模型能否也用EllipsoidModel取得经纬度坐标?

em->convertXYZToLatLongHeight(hitr->getWorldIntersectPoint().x(),hitr->getWorldIntersectPoint().y(),hitr->getWorldIntersectPoint().z(),y,x,z);

os<<osg::RadiansToDegrees(x)<<"    "<<osg::RadiansToDegrees(y)<<"       "<<z<<std::endl;

//以下是否可以得到模型tif中真实的投影坐标?

osg::Vec3 mercVec=csn->computeLocalUpVector(hitr->getWorldIntersectPoint());

os<<mercVec.x()<<mercVec.y()<<mercVec.z()<<std::endl;

         }

}
上述指定程序的coordinatorsystem,setform、setcoordiantorsystem是否正确,还有用EillpsoidModel能否获取实际经纬度?怎样从鼠标点击点与模型的交点中获取模型如tif中描述的真实的坐标值?

merctor.bmp
0-40.bmp

该用户从未签到

发表于 2013-4-12 10:19:44 | 显示全部楼层
可以用EillpsoidModel来计算经纬度,不过它只有wgs84球的计算
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表