osg3.6.5 osgEarth3.2中,生成ive格式文件,使用osgViewer.exe命令无法显示

osg系列文章目录

前言

osg3.6.5 osgEarth3.2中,生成ive格式文件,使用osgViewer.exe命令打开ive文件时,却无法正常显示。
在这里插入图片描述

代码如下:

#include <Windows.h>
#include <iostream>
#include <string>
#include <cstdlib> // For rand() and srand()
#include <ctime>   // For time()

#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarth/ImageLayer>
#include <osgEarth/EarthManipulator>
#include <osgEarth/OGRFeatureSource>
#include <osgEarth/FeatureModelLayer>
#include <osgEarth/FeatureImageLayer>
#include <osgEarth/ECEF>
#include <osgEarth/GeoData>
#include <osgEarth/Viewpoint>
#include <osgEarth/TerrainOptions>
#include <osgGA/SphericalManipulator>
#include <osgEarth/Symbol>
#include <osgEarth/Feature>
#include <osgEarth/FeatureModelSource>
#include <osgUtil/Tessellator>
#include <osg/LineWidth> 
#include <osg/Depth>
#include <osg/PolygonMode>

using namespace std;

void LoadShape()
{
   
   
	srand(static_cast<unsigned int>(time(nullptr)));

	//// Load the base map (globe)
	//osg::ref_ptr<osg::Node> globe = osgDB::readNodeFile("../vs2022_64bit_3rdParty_osg365_oe32/runtime/test/earthFile/china-simple.earth");
	//if (!globe)
	//{
   
   
	//	std::cerr << "Failed to load earth file." << std::endl;
	//	return;
	//}

	/*osg::ref_ptr<osg::Group> gp = new osg::Group;
	gp->addChild(globe);

	osg::ref_ptr<osgEarth::MapNode> mapNode = osgEarth::MapNode::get(globe);
	if (!mapNode)
	{
		std::cerr << "Failed to get MapNode." << std::endl;
		return;
	}

	osg::ref_ptr<osg::Geode> gNode = new osg::Geode;
	gp->addChild(gNode);
	osg::ref_ptr<osgEarth::Map> map = mapNode->getMap();*/

	// Load the Shapefile
	osg::ref_ptr<osgEarth::OGRFeatureSource> features = new osgEarth::OGRFeatureSource;
	features->setURL("F:/osg/yangShiXing/019.Earth/builder/data/shpFile/world.shp"); // china.shp  world.shp

	if (!features->open())
	{
   
   
		std::cerr << "Failed to load shapefile: " << features->getStatus().message() << std::endl;
		return;
	}
	else
	{
   
   
		std::cout << "Shapefile loaded successfully." << std::endl;
	}

	// Initialize the query object
	osgEarth::Query query;
	//query.expression() = "1=1"; // A simple query that matches all features

	// Log the query expression if it exists
	if (query.expression().isSet())
	{
   
   
		std::cout << "Query expression: " << query.expression().value() << std::endl;
	}

	// Create a feature cursor with the query
	osg::ref_ptr<osgEarth::FeatureCursor> cursor = features->createFeatureCursor(query, nullptr);
	if (!cursor)
	{
   
   
		std::cerr << "Failed to create feature cursor." << std::endl;
		return;
	}
	else
	{
   
   
		std::cout << "Feature cursor created successfully." << std::endl;
	}

	const osgEarth::SpatialReference* srs = features->getFeatureProfile()->getSRS();
	const osgEarth::SpatialReference* mapSRS = features->getFeatureProfile()->getSRS();

	//osg::ref_ptr<osg::Geode> gNode = new osg::Geode;

	int colorIndex = 0;
	osg::Vec4 color1 = osg::Vec4(1.0, 0.0, 0.0, 0.2);
	osg::Vec4 color2 = osg::Vec4(1.0, 1.0, 0.0, 0.2);
	osg::Vec4 color3 = osg::Vec4(1.0, 0.0, 1.0, 0.2);
	osg::Vec4 color4 = osg::Vec4(0.0, 1.0, 0.0, 0.2);
	osg::Vec4 color5 = osg::Vec4(0.0, 0.0, 1.0, 0.2);
	osg::Vec4 color6 = osg::Vec4(1.0, 1.0, 1.0, 0.2);
	osg::Vec4 color7 = osg::Vec4(0.5, 0.2, 0.1, 0.2);

	osg::ref_ptr<osg::Group> gp = new osg::Group;

	
	while (cursor
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值