从 Qt Creator 构建 osgEarth 应用程序

Build osgEarth application from Qt Creator

我试过 运行 简单 osgearth 示例:

#include <osgViewer/Viewer>

#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
#include <osgEarth/ElevationLayer>
#include <osgEarth/ModelLayer>
#include <osgEarth/GeoTransform>

#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/ExampleResources>
#include <osgEarthUtil/AutoScaleCallback>

#include <osgEarthDrivers/tms/TMSOptions>
#include <osgEarthDrivers/wms/WMSOptions>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/osg/OSGOptions>
#include <osgEarthDrivers/xyz/XYZOptions>

#include <osg/PositionAttitudeTransform>

using namespace osgEarth;
using namespace osgEarth::Drivers;
using namespace osgEarth::Util;

/**
 * How to create a simple osgEarth map and display it.
 */
int
main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);

    // create the empty map.
    Map* map = new Map();

    // add a TMS imagery layer:
    TMSOptions imagery;
    imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/7/";
    map->addLayer( new ImageLayer("ReadyMap Imagery", imagery) );

    // add a TMS elevation layer:
    TMSOptions elevation;
    elevation.url() = "http://readymap.org/readymap/tiles/1.0.0/116/";
    map->addLayer( new ElevationLayer("ReadyMap Elevation", elevation) );

    // add a semi-transparent XYZ layer:
    XYZOptions xyz;
    xyz.url() = "http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png";
    xyz.profile()->namedProfile() = "spherical-mercator";
    ImageLayer* imageLayer = new ImageLayer("OSM", xyz);
    imageLayer->setOpacity(0.5f);
    map->addLayer(imageLayer);

    // add a local GeoTIFF inset layer:
    GDALOptions gdal;
    gdal.url() = "../data/boston-inset.tif";
    map->addLayer(new ImageLayer("Boston", gdal));

    // add a WMS radar layer with transparency, and disable caching since
    // this layer updates on the server periodically.
    WMSOptions wms;
    wms.url() = "http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi";
    wms.format() = "png";
    wms.layers() = "nexrad-n0r";
    wms.srs() = "EPSG:4326";
    wms.transparent() = true;
    ImageLayerOptions wmsLayerOptions("WMS NEXRAD", wms);
    wmsLayerOptions.cachePolicy() = CachePolicy::NO_CACHE;
    map->addLayer(new ImageLayer(wmsLayerOptions));

    // add a local simple image as a layer using the OSG driver:
    OSGOptions osg;
    osg.url() = "../data/osgearth.gif";
    osg.profile()->srsString() = "wgs84";
    osg.profile()->bounds()->set(-90.0, 10.0, -80.0, 15.0);
    map->addLayer(new ImageLayer("Simple image", osg));

    // put a model on the map atop Pike's Peak, Colorado, USA
    osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile("cow.osgt.(0,0,3).trans.osgearth_shadergen");
    if (model.valid())
    {
        osg::PositionAttitudeTransform* pat = new osg::PositionAttitudeTransform();
        pat->addCullCallback(new AutoScaleCallback<osg::PositionAttitudeTransform>(5.0));
        pat->addChild(model.get());

        GeoTransform* xform = new GeoTransform();
        xform->setPosition(GeoPoint(SpatialReference::get("wgs84"), -105.042292, 38.840829));
        xform->addChild(pat);

        map->addLayer(new ModelLayer("Model", xform));
    }

    // make the map scene graph:
    MapNode* node = new MapNode( map );

    // initialize a viewer:
    osgViewer::Viewer viewer(arguments);
    viewer.setCameraManipulator( new EarthManipulator() );
    viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
    viewer.setSceneData( node );

    // add some stock OSG handlers:
    MapNodeHelper().configureView(&viewer);

    return viewer.run();
}

但是我的QtCreator找不到所有的osgEarth包。同时,他毫无问题地找到了osgViewer/Viewer这个包。 好的。我接受了测试 .earth 文件并尝试 运行 与 osgearth_viewer file.earth:

<map name="readymap.org" type="geocentric">

    <image name="readymap_imagery" driver="tms">
        <url>http://readymap.org/readymap/tiles/1.0.0/7/</url>
    </image>

    <elevation name="readymap_elevation" driver="tms" vdatum="egm96">
        <url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
    </elevation>

    <xi:include href="viewpoints.xml"/>
</map>

输出osgearth_viewer file.earth:

[osgEarth]* [MapNodeHelper] No earth file.
[osgEarth]  
Usage: osgearth_viewer file.earth
  --sky                         : add a sky model
  --ocean                       : add an ocean model
  --kml <file.kml>              : load a KML or KMZ file
  --coords                      : display map coords under mouse
  --dms                         : dispay deg/min/sec coords under mouse
  --dd                          : display decimal degrees coords under mouse
  --mgrs                        : show MGRS coords under mouse
  --ortho                       : use an orthographic camera
  --autoclip                    : installs an auto-clip plane callback
  --images [path]               : finds and loads image layers from folder [path]
  --image-extensions [ext,...]  : with --images, extensions to use
  --out-earth [file]            : write the loaded map to an earth file
  --uniform [name] [min] [max]  : create a uniform controller with min/max values

它可能是什么?我不明白。请帮忙:(

试试这个简单的东西: https://github.com/gwaldron/osgearth/blob/master/tests/gdal_multiple_files.earth

下载并尝试加载上面的简单文件。确保您拥有与“.earth”文件相关的所有数据。

谢谢。