|
原有的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中描述的真实的坐标值?
|
|