[原][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 ...
随机推荐
- nodejs模块化标准
commonjs 导出一个 a.js function add(a, b){ return a+b; } module.exports = add; b.js const add = require( ...
- 2019-08-28 redhat linux如何部署禅道服务器(一键安装包)
linux一键安装包内置了XXD.apache, php, mysql这些应用程序,不需要再单独安装部署. linux一键安装包分为32位和64位两个包,请大家根据操作系统的情况下载相应的包. 一.准 ...
- Django解析器
1.什么是解析器? 对请求的数据进行解析-请求体进行解析.解析器在你不拿请求体数据时,不会被调用. 安装与使用:(官方文档) https://www.django-rest-framework.org ...
- HDU - 4352 - XHXJ's LIS(数位DP)
链接: https://vjudge.net/problem/HDU-4352 题意: a 到 b中一个数组成递增子序列长度等于k的数的个数 思路: 因为只有10个数,使用二进制维护一个递增序列,每次 ...
- SIGAI机器学习第十九集 随机森林
讲授集成学习的概念,Bootstrap抽样,Bagging算法,随机森林的原理,训练算法,包外误差,计算变量的重要性,实际应用 大纲: 集成学习简介 Boostrap抽样 Bagging算法 随机森林 ...
- learning java AWT 手绘窗口
import java.awt.*;port java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import jav ...
- ipkg-nas
http://pkg.entware.net/binaries/x86-64/ https://forum.synology.com/enu/viewtopic.php?t=95346 http:// ...
- 洛谷 P1714 切蛋糕 题解
P1714 切蛋糕 题目描述 今天是小Z的生日,同学们为他带来了一块蛋糕.这块蛋糕是一个长方体,被用不同色彩分成了N个相同的小块,每小块都有对应的幸运值. 小Z作为寿星,自然希望吃到的第一块蛋糕的幸运 ...
- 洛谷 P1152 欢乐的跳 题解
洛谷 P1152 欢乐的跳 题目描述 一个nn个元素的整数数组,如果数组两个连续元素之间差的绝对值包括了[1,n-1][1,n−1]之间的所有整数,则称之符合"欢乐的跳",如数组1 ...
- 机器学习---用python实现感知机算法和口袋算法(Machine Learning PLA Pocket Algorithm Application)
之前在<机器学习---感知机(Machine Learning Perceptron)>一文中介绍了感知机算法的理论知识,现在让我们来实践一下. 有两个数据文件:data1和data2,分 ...