OE所有官方样例

官方示例代码

/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2016 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/ #include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
#include <osgEarth/ModelLayer>
#include <osgEarthUtil/ExampleResources>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AutoClipPlaneHandler> #include <osgEarthSymbology/Style>
#include <osgEarthFeatures/FeatureModelLayer>
#include <osgEarthFeatures/ConvertTypeFilter> #include <osgEarthDrivers/engine_rex/RexTerrainEngineOptions>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include <osgEarthDrivers/agglite/AGGLiteOptions>
#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions> #include <osgDB/WriteFile> using namespace osgEarth;
using namespace osgEarth::Features;
using namespace osgEarth::Drivers;
using namespace osgEarth::Symbology;
using namespace osgEarth::Util; int usage(const std::string& app)
{
OE_NOTICE "\n" << app << "\n"
<< " --rasterize : draw features as rasterized image tiles \n"
<< " --overlay : draw features as projection texture \n"
<< " --mem : load features from memory \n"
<< " --labels : add feature labels \n"
<< "\n"
<< MapNodeHelper().usage(); return -;
} //
// NOTE: run this sample from the repo/tests directory.
//
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc, argv); if (arguments.read("--help"))
return usage(argv[]); bool useRaster = arguments.read("--rasterize");
bool useOverlay = arguments.read("--overlay");
bool useMem = arguments.read("--mem");
bool useLabels = arguments.read("--labels"); osgViewer::Viewer viewer(arguments); // Start by creating the map:
Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver
// to load a local GeoTIFF file:
GDALOptions basemap;
basemap.url() = "E:/temp/OE/data/world.tif";
map->addLayer(new ImageLayer(ImageLayerOptions("basemap", basemap))); // Next we add a feature layer.
OGRFeatureOptions ogrData;
if (!useMem)
{
// Configures the feature driver to load the vectors from a shapefile:
ogrData.url() = "E:/temp/OE/data/world.shp";
}
else
{
// the --mem options tells us to just make an in-memory geometry:
Ring* line = new Ring();
line->push_back(osg::Vec3d(-, , ));
line->push_back(osg::Vec3d(-, , ));
line->push_back(osg::Vec3d(-, , ));
line->push_back(osg::Vec3d(-, , ));
ogrData.geometry() = line;
} // Make a feature source layer and add it to the Map:
FeatureSourceLayerOptions ogrLayer;
ogrLayer.name() = "vector-data";
ogrLayer.featureSource() = ogrData;
map->addLayer(new FeatureSourceLayer(ogrLayer)); // Define a style for the feature data. Since we are going to render the
// vectors as lines, configure the line symbolizer:
Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
ls->stroke()->color() = Color::Yellow;
ls->stroke()->width() = 2.0f; // That's it, the map is ready; now create a MapNode to render the Map:
osgEarth::Drivers::RexTerrainEngine::RexTerrainEngineOptions rex; MapNodeOptions mapNodeOptions;
mapNodeOptions.enableLighting() = false;
mapNodeOptions.setTerrainOptions(rex);
MapNode* mapNode = new MapNode(map, mapNodeOptions); osg::Group* root = new osg::Group();
root->addChild(mapNode);
viewer.setSceneData(root);
viewer.setCameraManipulator(new EarthManipulator()); // Process cmdline args
MapNodeHelper().parse(mapNode, arguments, &viewer, root, new LabelControl("Features Demo")); if (useRaster)
{
AGGLiteOptions rasterOptions;
rasterOptions.featureOptions() = ogrData;
rasterOptions.styles() = new StyleSheet();
rasterOptions.styles()->addStyle(style);
map->addLayer(new ImageLayer("My Features", rasterOptions));
}
else //if (useGeom || useOverlay)
{
FeatureModelLayerOptions fml;
fml.name() = "My Features";
fml.featureSourceLayer() = "vector-data";
fml.styles() = new StyleSheet();
fml.styles()->addStyle(style);
fml.enableLighting() = false; map->addLayer(new FeatureModelLayer(fml));
} if (useLabels)
{
// set up symbology for drawing labels. We're pulling the label
// text from the name attribute, and its draw priority from the
// population attribute.
Style labelStyle; TextSymbol* text = labelStyle.getOrCreateSymbol<TextSymbol>();
text->content() = StringExpression("[cntry_name]");
text->priority() = NumericExpression("[pop_cntry]");
text->size() = 16.0f;
text->alignment() = TextSymbol::ALIGN_CENTER_CENTER;
text->fill()->color() = Color::White;
text->halo()->color() = Color::DarkGray; // and configure a model layer:
FeatureModelLayerOptions fml;
fml.name() = "Labels";
fml.featureSourceLayer() = "vector-data";
//fml.featureSource() = featureOptions;
fml.styles() = new StyleSheet();
fml.styles()->addStyle(labelStyle); map->addLayer(new FeatureModelLayer(fml));
} // add some stock OSG handlers:
viewer.addEventHandler(new osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = ;
traits->y = ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ; osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(, , traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer);
viewer.addSlave(camera); return viewer.run();
}

开启"--labels"  标注的图元信息,这些是读取shp中的字段加载的!

        Ring* line = new Ring();
line->push_back(osg::Vec3d(-, , ));
line->push_back(osg::Vec3d(-, , ));
line->push_back(osg::Vec3d(-, , ));
line->push_back(osg::Vec3d(-, , ));
ogrData.geometry() = line;

开启"--mem"代码绘制

开启"--mem"代码绘制

开启栅格化"--rasterize"

[原][OE][官方例子]osgearth_features OE地球添加shp文件(特征标识)的更多相关文章

  1. [原][OE][官方例子]osgearth_annotation OE地球添加热点标签

    OE所有官方例子 OE代码样例 /* -*-c++-*- */ /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph * Co ...

  2. Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图

    Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图 在本节中,您需要修改HelloWorldController类,从而使用视图模板文件,干净优雅的封装生成返回到客户端浏览器HTML ...

  3. Java Restful框架:Jersey入门示例(官方例子)

    本文主要介绍了Java Restful框架Jersey入门例子(来源于官方网站https://jersey.java.net/),废话不多说进入正题. 在Jersey官方示例中(https://jer ...

  4. Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型

    Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型 在这一节中,你将添加用于管理数据库中电影的类.这些类是ASP.NET MVC应用程序的模型部分. 你将使用.NET Framewo ...

  5. ArcGIS Earth(原谷歌地球)如何获取高精度矢量地图数据?(shp文件/要素类/kml)

    大家好,这次来分享干货.做地理分析的同学,或者需要使用地图却不知道哪里有矢量数据的时候,怎么办呢? 这次,我就告诉大家哪里能自己手工制作矢量点线面数据!注意哦,是自己绘制的. 使用到的软件: ArcG ...

  6. 解析苹果的官方例子LazyTableImages实现图片懒加载原理

    解析苹果的官方例子LazyTableImages实现图片懒加载原理 首先在官网下载源码: https://developer.apple.com/library/ios/navigation/#sec ...

  7. 向Maven的本地库中添加jar文件

    有时我们要用的 maven 依赖项在官方repo库中找不到,然而我们从其他渠道获得了依赖项中的所有jar文件,本文记录了如何向本地库添加jar文件. 从复杂到简单,有三种方法: 使用 maven 的仓 ...

  8. 关于在工程中添加新文件时的LNK2019错误的一个解决办法

    我这几天一直在研究Qt的串口程序,在读懂了官方给出的实例程序后我决定把其多线程的串口监视程序加入到我自己的工程中,便直接把问价复制到自己的工程下面,在Qt中加入到自己的工程中,但是总是出现LNK201 ...

  9. Android 使用版本控制工具时添加忽略文件方式

    一.使用SVN管理项目时,添加忽略文件的方式 Android Studio 配合SVN时,添加忽略文件相对简单,首先打开项目的Settings选项,切换到Version Control下的Ignore ...

随机推荐

  1. mysqlslap压测

    mysqlslap 是MySQL自带的压测工具: -P --create-schema=test -S /tmp/mysql_sandbox18601.sock --number-of-queries ...

  2. 铁力项目mysql异常处理过程记录

    地区:铁力 故障:2019-06-26 10:19:34 139921514837760 [ERROR] mysqld: Error writing file 'mysql-bin' (errno: ...

  3. 后台将数据传回前台的三种绑定的方式(Model,Map.ModelAndView)

    //方式1:通过model 将数据绑定 @RequestMapping(value = "findByIdModel", method = RequestMethod.GET) p ...

  4. python_并发编程——守护进程

    1.守护进程 守护进程会随着主进程的代码执行结束而结束. 语法:进程对象.daemon = True时,表示将进程设置为守护进程,一定在start之前设置. import time from mult ...

  5. PHP一个for循环输出9*9乘法表

    一个for循环输出9*9乘法表 代码如下 <?php for ($i = 1, $j = 1; $i <= 9; $i++) { if ($i > $j) { $j++; $i = ...

  6. Linux命令基础3-cd命令

    cd 到带空格的文件夹 [root@cctg-sjc16-grafana ccatgbld]# cd 'my test' [root@cctg-sjc16-grafana my test]# cd . ...

  7. GBDT(梯度提升树) 原理小结

    在之前博客中,我们对Boosting家族的Adaboost算法做了总结,本文就对Boosting家族中另一个重要的算法梯度提升树(Gradient Boosting Decison Tree, 以下简 ...

  8. Hive节点及原理

    1.什么是Hive:hive是一种基于hadoop的数据仓库,能够将结构化的数据映射成一张表,并提供HQL进行查询.其数据是存储在hdfs上,本质是将sql命令转化成MapReduce来执行. 2.H ...

  9. Yarn节点及作用

    1.yarn中的角色:ResourceManager.NodeManager.ApplicationMaster. ResourceManager:集群计算资源的分配,启动ApplicationMas ...

  10. Hello 2019【A,B,C】

    #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ string str; ...