[原][OE][官方例子]osgearth_features OE地球添加shp文件(特征标识)

官方示例代码
/* -*-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文件(特征标识)的更多相关文章
- [原][OE][官方例子]osgearth_annotation OE地球添加热点标签
OE所有官方例子 OE代码样例 /* -*-c++-*- */ /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph * Co ...
- Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图
Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图 在本节中,您需要修改HelloWorldController类,从而使用视图模板文件,干净优雅的封装生成返回到客户端浏览器HTML ...
- Java Restful框架:Jersey入门示例(官方例子)
本文主要介绍了Java Restful框架Jersey入门例子(来源于官方网站https://jersey.java.net/),废话不多说进入正题. 在Jersey官方示例中(https://jer ...
- Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型
Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型 在这一节中,你将添加用于管理数据库中电影的类.这些类是ASP.NET MVC应用程序的模型部分. 你将使用.NET Framewo ...
- ArcGIS Earth(原谷歌地球)如何获取高精度矢量地图数据?(shp文件/要素类/kml)
大家好,这次来分享干货.做地理分析的同学,或者需要使用地图却不知道哪里有矢量数据的时候,怎么办呢? 这次,我就告诉大家哪里能自己手工制作矢量点线面数据!注意哦,是自己绘制的. 使用到的软件: ArcG ...
- 解析苹果的官方例子LazyTableImages实现图片懒加载原理
解析苹果的官方例子LazyTableImages实现图片懒加载原理 首先在官网下载源码: https://developer.apple.com/library/ios/navigation/#sec ...
- 向Maven的本地库中添加jar文件
有时我们要用的 maven 依赖项在官方repo库中找不到,然而我们从其他渠道获得了依赖项中的所有jar文件,本文记录了如何向本地库添加jar文件. 从复杂到简单,有三种方法: 使用 maven 的仓 ...
- 关于在工程中添加新文件时的LNK2019错误的一个解决办法
我这几天一直在研究Qt的串口程序,在读懂了官方给出的实例程序后我决定把其多线程的串口监视程序加入到我自己的工程中,便直接把问价复制到自己的工程下面,在Qt中加入到自己的工程中,但是总是出现LNK201 ...
- Android 使用版本控制工具时添加忽略文件方式
一.使用SVN管理项目时,添加忽略文件的方式 Android Studio 配合SVN时,添加忽略文件相对简单,首先打开项目的Settings选项,切换到Version Control下的Ignore ...
随机推荐
- MySQL数据库开发规范-EC
最近一段时间一边在线上抓取SQL来优化,一边在整理这个开发规范,尽量减少新的问题SQL进入生产库.今天也是对公司的开发做了一次培训,PPT就不放上来了,里面有十来个生产SQL的案例.因为规范大部分还是 ...
- #2590. 「NOIP2009」最优贸易
C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分为双向通行的道路,双向通行的道 ...
- Django --- cookie与session,中间件
目录 1.cookie与session 1.cookie 2.session 2.中间件 1.中间件作用 2.用户可以自定义的五个方法 3.自定义中间件 1.cookie与session 1.cook ...
- php 文件包含函数
在实际开发中,常常需要把程序中的公用代码放到一个文件中,使用这些代码的文件只需要包含这个文件即可.这种方法有助于提高代码的重用性,给代码的编写与维护带来很大的便利.在PHP中, 有require.re ...
- 【洛谷2791】 幼儿园篮球题 第二类斯特林数+NTT
求 \(\sum_{i=0}^{k}\binom{m}{i}\binom{n-m}{k-i}i^L\) \((1\leqslant n,m\leqslant 2\times 10^7,1\leqsla ...
- qDeleteAll与clear
qDeleteAll:专门用于指针容器,对容器或者迭代器中的每个对象进行delete操作,而不是从容器中移除对象.源代码如下: void qDeleteAll(ForwardIterator begi ...
- 案例:3D切割轮播图
一.3d转换 3D旋转套路:顺着轴的正方向看,顺时针旋转是负角度,逆时针旋转是正角度 二.代码 <!DOCTYPE html> <html lang="en"&g ...
- Zatree - Zabbix图表展示
Zatree Zatree 是 一个php web的插件,做个展示树:可以提供host group的树形展示和在item里指定关键字查询及数据排序. 下载地址 可以根据zabbix不同版本下载:htt ...
- Python学习之--字典
一.字典的表示 字典用放在花括号{} 中的一系列键—值对表示,键—值对是两个相关联的值:键和值之间用冒号分隔,如circle = {'color':'green', 'points':5} 二.取值 ...
- 数据结构实验之排序六:希尔排序 (SDUT 3403)
其实,感觉好像增量不同的冒泡,希尔排序概念以后补上. #include <bits/stdc++.h> using namespace std; int a[10005]; int b[1 ...