[原][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 ...
随机推荐
- Linux中rpm命令用法
rpm -ivh 软件包名 安装软件包并显示安装进度.这个是用得最多的了. rpm -qa 查询已经安装哪些软件包. rpm -q 软件包名 查询指定软件包是否已经安装. rpm -Uvh 软件包名 ...
- ClassLoader类加载器 & Java类加载机制 & 破坏双亲委托机制
ClassLoader类加载器 Java 中的类加载器大致可以分成两类: 一类是系统提供的: 引导类加载器(Bootstrap classloader):它用来加载 Java 的核心库(如rt.jar ...
- machine learning (4)---feature scaling
feature scaling:缩小或扩大feature的值,使所有的feature处于类似的范围,这样进行gradient descnet时更快趋向最小值.因为不同的feature的范围相差很大时, ...
- oracle中日期相关的区间
and czrqb.lsrqb_rh_sj >= to_date('[?query_date_begin|2011-09-01?]A', 'yyyy-mm-dd') and czrqb.lsrq ...
- 行为型模式(四) 观察者模式(Observer)
一.动机(Motivate) "观察者模式"在现实生活中,实例其实是很多的,比如:八九十年代我们订阅的报纸,我们会定期收到报纸,因为我们订阅了.银行可以给储户发手机短信,也是&qu ...
- RCNN,Fast RCNN,Faster RCNN 的前生今世:(2) R- CNN (3,2,1)
3.三次IOU 2.2次model run 1,一次深度神经网络 rcnn主要作用就是用于物体检测,就是首先通过selective search 选择2000个候选区域,这些区域中有我们需要的所对 ...
- http健康状态检查
来自为知笔记(Wiz)
- python - 使用psutils
oshelper.py #encoding=utf-8 import psutil import datetime #查看cpu的信息 print u"CPU 个数 %s"%psu ...
- 洛谷 P2363 马农
题目描述 分别枚举两个矩阵?那样n^6太要命了. 可以枚举两个矩形的交点 将交点看成原点,可以将整个区域分成四个象限,1与3对应,2与4对应 再枚举相对应的象限计算可以获得的利益,用hash判重 可枚 ...
- Pytest权威教程13-Fixture方法及测试用例的参数化
目录 Fixture方法及测试用例的参数化 @pytest.mark.parametrize:参数化测试函数 基本的pytest_generate_tests例子 更多示例 返回: Pytest权威教 ...