矢量数据提取分析(甲方平台)

目录

步骤分析:(以居民地为例)

1)满足平台规范,调用平台接口,实现在该平台上UI布局。

​编辑2)居民地命令类

[3.void BeResidentCmd::execute() 流程(点击事件自动触发)](#3.void BeResidentCmd::execute() 流程(点击事件自动触发))

[4.QVector points = BenviInfo::getInstance()->getCurrentPlot();//完成区域绘制时,获取绘制区域点集合。 jmd.startDeal();//开始分析处理](#4.QVector points = BenviInfo::getInstance()->getCurrentPlot();//完成区域绘制时,获取绘制区域点集合。 jmd.startDeal();//开始分析处理)

4.1)BeGeneralAnalyse::startDeal();流程

[4.1.1)if (initAnalyse()){BEAParam* mp = createParam();流程:](#4.1.1)if (initAnalyse()){BEAParam* mp = createParam();流程:)

4.1.2)mp->getResult();流程

[4.1.2.1)QMap > mapFeature = getFeatures();获取要素](#4.1.2.1)QMap > mapFeature = getFeatures();获取要素)

[4.1.2.1.1)//构建查询条件 ,矢量图层类,查询要素(核心部分)](#4.1.2.1.1)//构建查询条件 ,矢量图层类,查询要素(核心部分))

[4.1.2.2)dealGeometry(feature, polygon, iter.key());流程](#4.1.2.2)dealGeometry(feature, polygon, iter.key());流程)

4.1.2.3)点包含判断

[4.1.2.4)坐标转换( 地理坐标转地图坐标)](#4.1.2.4)坐标转换( 地理坐标转地图坐标))

4.2)pBeResidentSystemWin->setData(m_d->jtfx);//触发绘制

4.2.1)触发绘制

4.2.1.1)坐标转换(地理坐标转像素坐标)

5.结果

​编辑以上是矢量数据的提取


步骤分析:(以居民地为例)

1)满足平台规范,调用平台接口,实现在该平台上UI布局。

复制代码
#pragma once

#ifndef  _BEGEOANALYSIS_H_
#define  _BEGEOANALYSIS_H_

#include "AppEngine/Plugin.h"
#include "Base/Event/Event.h"

class BeGeoanalysis : public RyAppEngine::CRyPlugin
{
public:
	BeGeoanalysis();
	virtual ~BeGeoanalysis();


public:
	virtual bool initialize();
	virtual bool isLicenseValid() { return true; }

};

#endif  

using namespace RyBase;
using namespace RyDisplay;
using namespace RyAppBase;
using namespace RyAppEngine;

#ifdef RY_OS_WIN
#define SLT_API __declspec(dllexport)
#else
#define SLT_API
#endif

extern "C"
SLT_API CRyPlugin* createAppPlugin()
{
	return new BeGeoanalysis;
}

BeGeoanalysis::BeGeoanalysis()
	: CRyPlugin(new RyAppBase::CRyPluginApplication())
{
	mDelayLoad = false;
	mAdaptability = FitFor2DMapView /*| FitForLayoutView | FitForFramedMapView*/;
	mName = RY_TEXT("BeGeoanalysis");
	mAlias = RY_TEXT("地理要素");
	mDescription = RY_TEXT("地理要素");
	mUIOrder = -9;
	mSupportExport = false;
}

BeGeoanalysis::~BeGeoanalysis()
{
	uninitialize();
}

bool BeGeoanalysis::initialize()
{

	CRyToolBarDef* YSanalysis = new CRyToolBarDef();
	YSanalysis->setCaption(RY_TEXT("要素统计分析"));
	CRyToolBarDef* FeatureExtract = new CRyToolBarDef();
	FeatureExtract->setCaption(RY_TEXT("特征提取"));
	CRyToolBarDef* LandformAnalysis = new CRyToolBarDef();
	LandformAnalysis->setCaption(RY_TEXT("地貌分析"));


	//居民地
	BeResidentCmd* cmd22 = new BeResidentCmd(this);
	mCommands.push_back(cmd22, cmd22->getName());
	YSanalysis->addItemDef(CRyItemDef(cmd22->getName(), false, ATCommand));

	//交通
	BeTrafficCmd* cmd23 = new BeTrafficCmd(this);
	mCommands.push_back(cmd23, cmd23->getName());
	YSanalysis->addItemDef(CRyItemDef(cmd23->getName(), false, ATCommand));

2)居民地命令类

复制代码
#pragma once
#ifndef  _BERESIDENTCMD_H_
#define  _BERESIDENTCMD_H_

#include "AppEngine\Command.h"
#include "BattEnvironmentDef.h"


namespace RyGraphics
{
	class CRyColorRamp;
}

class BeResidentCmd : public RyAppEngine::CRyCommand
{
public:
	BeResidentCmd(RyAppEngine::CRyPlugin* plugin);
	virtual ~BeResidentCmd();

public:
	virtual void execute();
	virtual bool isEnabled() const { return true; }

};
#endif  

3.void BeResidentCmd::execute() 流程(点击事件自动触发)

复制代码
using namespace RyAppEngine;
using namespace RyAppBase;
using namespace RyBase;
using namespace RyGraphics;


BeResidentCmd::BeResidentCmd(RyAppEngine::CRyPlugin* plugin)
	:CRyCommand(plugin)

{
	mIconSize = RyAppEngine::Small;
	mActionStyle = RyAppEngine::TextBesideIcon;
	mName = plugin->getName() + RY_TEXT(".BeResidentCmd");
	mCaption = RY_TEXT("居民地");
	mStatusTip = RY_TEXT("居民地");
	mTooltip = RY_TEXT("居民地");
	mIconFiles.insert(mIconSize, RyAppEngine::RyGetIconPath(plugin->getName(), RY_TEXT("JMD-01.png")));

}

BeResidentCmd::~BeResidentCmd()
{
	
}

void BeResidentCmd::execute()
{
	QVector<QPointF> points = BenviInfo::getInstance()->getCurrentPlot();
	if (points.size() > 0)
	{
		BeAnalyseJMD  jmd;
		jmd.setPloygon(points);
		jmd.startDeal();
	}
	else
	{
		QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请划设分析区域"));
	}
	
}

4.QVector<QPointF> points = BenviInfo::getInstance()->getCurrentPlot();//完成区域绘制时,获取绘制区域点集合。

jmd.startDeal();//开始分析处理

复制代码
void BeAnalyseJMD::startDeal()
{
	BeGeneralAnalyse::startDeal();
	RyCarto::CRyLayer* layer = XGISInterface::getLayer(QString::fromLocal8Bit("居民地及附属设施_面"));
	RySRS::CRyCoordinateSystem* tarCS = layer->getDataSpatialReferenceRef();
	BeResidentSystemWin* pBeResidentSystemWin = new BeResidentSystemWin;
	pBeResidentSystemWin->setWkt(QString::fromStdWString(tarCS->toWkt()));
	pBeResidentSystemWin->setPolygon(m_d->m_polygon);
	m_d->jtfx.m_polygon = m_d->m_polygon;
	pBeResidentSystemWin->showText(m_d->jtfx);
	pBeResidentSystemWin->setData(m_d->jtfx);
	pBeResidentSystemWin->setText();
	pBeResidentSystemWin->setDisplyLoca();
	pBeResidentSystemWin->show();

}

4.1)BeGeneralAnalyse::startDeal();流程

复制代码
void BeGeneralAnalyse::startDeal()
{
	if (initAnalyse())
	{
		BEAParam* mp = createParam();

		Q_ASSERT(NULL != mp);
		if (mp != NULL)
		{
			mp->getResult();
			delete mp;
		}
	}
}

4.1.1)if (initAnalyse()){BEAParam* mp = createParam();流程:

复制代码
//通用型接口类,不返回结果
class BeEnvi_EXPORT BeGeneralAnalyse : public BeInterface
{
public:
	BeGeneralAnalyse() {};
	virtual ~BeGeneralAnalyse() {};

	//处理之前的初始化
	virtual bool initAnalyse() { return true; };

	//创建参数
	virtual BEAParam* createParam() = 0;

	//分析类型
	virtual int  getType() const { return -1; };

	//开始处理
	virtual void startDeal();
};

BEAParam* BeAnalyseJMD::createParam()
{
	BEAParamMuitAnalyse* pParam = new BEAParamMuitAnalyse;
	{
		BEAParamJMD* jmdArea = new BEAParamJMD(QString::fromLocal8Bit("居民地及附属设施_面"));
		jmdArea->setRect(m_d->m_polygon.boundingRect());
		jmdArea->m_polygon = m_d->m_polygon;

		// 街区  高层房屋及街区 普通街区  破坏房屋及街区
		QString strWhere = QString::fromStdWString(RY_TEXT("编码=130200 OR 编码=130202 OR 编码=130204 OR 编码=130205"));
		jmdArea->setFilter(strWhere);
		jmdArea->mst = &(m_d->jtfx);
		pParam->addParamAnalyse(jmdArea);
	}
	return pParam;
}

4.1.2)mp->getResult();流程

复制代码
//矢量参数基类
class BeEnvi_EXPORT BEAParamSHPSimple : public BEAParamSHP
{
public:
	BEAParamSHPSimple(const QString& strparam = QString());
	~BEAParamSHPSimple();

	virtual void setFilter(const QString& cWhere = QString());
};

void* BEAParamSHP::getResult()
{
	QMap<int, QVector<BeFeaturePtr>> mapFeature = getFeatures();
	QMap<int, QVector<BeFeaturePtr>>::Iterator iter = mapFeature.begin();

	while (iter != mapFeature.end())
	{
		const QVector<BeFeaturePtr>& vecFeature = iter.value();
		for (int i = 0; i < vecFeature.size(); ++i)
		{
			BeFeature* feature = vecFeature[i];
			if (feature == NULL)
			{
				continue;
			}
			RyGeometry::CRyGeometry* getMetry = feature->getGeometryRef();
			if (getMetry==NULL)
			{
				continue;
			}
			
			RyGeometry::RyGeometryType type = getMetry->getGeometryType();
			if (type == RyGeometry::gtPoint)
			{
				RyGeometry::CRyGPoint* point = (RyGeometry::CRyGPoint*)getMetry;
				dealGeometry(feature, point, iter.key());
			}
			else if (type == RyGeometry::gtLineString)
			{
				RyGeometry::CRyLineString* polyline = (RyGeometry::CRyLineString*)getMetry;
				dealGeometry(feature,  polyline, iter.key());
			}
			else if (type == RyGeometry::gtPolygon)
			{
				RyGeometry::CRyPolygon* polygon = (RyGeometry::CRyPolygon*)getMetry;
				dealGeometry(feature, polygon, iter.key());
			}
		}

		iter++;
	}

	return NULL;
}
4.1.2.1)QMap<int, QVector<BeFeaturePtr>> mapFeature = getFeatures();获取要素
复制代码
QMap<int, QVector<BeFeaturePtr>> BEAParamSHP::getFeatures()
{
	QMap<int, QVector<BeFeaturePtr>> mapFeature;
	QMap<int, QString>::Iterator iter = m_d->mwhereParam.begin();

	int iCount = m_d->mwhereParam.size();
	while (iter != m_d->mwhereParam.end())
	{
		BeFeatureReader* featurereader = getFeaturesFromSrc(iter.value());
		if (featurereader != NULL)
		{
			while (featurereader->readNext())
			{
				BeFeaturePtr feature = featurereader->getFeature();
				if (NULL == feature) continue;
				if (isEffecttive(feature))
				mapFeature[iter.key()].push_back(feature);
			}
		}

		iter++;
	}

	return mapFeature;
}
4.1.2.1.1)//构建查询条件 ,矢量图层类,查询要素(核心部分)

平台/// CRyFeatureLayer 矢量图层类

RyCarto::CRyLayer* layer = XGISInterface::getLayer(getParamName());

filter->setWhereClause(strWhere.toStdWString());

featurereader = Layer->search(filter);

复制代码
RyDataEngine::CRyFeatureReader* BEAParamSHP::getFeaturesFromSrc(const QString& strWhere)
{
	RyCarto::CRyLayer* layer = XGISInterface::getLayer(getParamName());
	RyCarto::CRyFeatureLayer* Layer = dynamic_cast<RyCarto::CRyFeatureLayer*>(layer);

	RyDataEngine::CRyFeatureReader* featurereader = NULL;
	if (NULL == Layer) return NULL;

	if (m_d->mrtf.isNull())
	{
		featurereader = Layer->search(NULL);
	}
	else
	{
		RyBase::CRyRectD reqRect = XGISInterface::getSelectRect(m_d->mrtf);

		//构建查询条件
		CRyPtr<RyGisBase::CRySpatialFilter> filter = new RyGisBase::CRySpatialFilter();

		if (strWhere.length() > 0)
		{
			filter->setWhereClause(strWhere.toStdWString());
		}
		//////////////////////////////////////////////////////////////////////////
		//RySRS::CRyCoordinateSystem* srcCS = Layer->getSpatialReferenceRef();
		//QString srcWKT = QString::fromStdWString(srcCS->toWkt());
		//////////////////////////////////////////////////////////////////////////
		//////////////////////////////////////////////////////////////////////////
		//RySRS::CRyCoordinateSystem* tarCS = Layer->getDataSpatialReferenceRef();
		//QString tarWKT = QString::fromStdWString(tarCS->toWkt());
		//////////////////////////////////////////////////////////////////////////


		filter->setFilterRect(reqRect,Layer->getDataSpatialReferenceRef());//Layer->getSpatialReferenceRef();

		filter->setSpatialRelation(RyGisBase::SpatialRelation_Intersects);
		featurereader = Layer->search(filter);
	}
	return featurereader;
}
4.1.2.2)dealGeometry(feature, polygon, iter.key());流程
复制代码
class BEAParamJMD : public BEAParamSHPSimple
{
public:
	BEAParamJMD(const QString& layerName) : BEAParamSHPSimple(layerName) {}

	virtual void dealGeometry(RyGisBase::CRyFeature* feature, RyGeometry::CRyPolygon* polygon, const short v)
	{
		RyGeometry::CRyLinearRing* lineRing = polygon->getExteriorRingRef();
		int pNum = lineRing->getNumPoints();
		RyBase::CRyPointD* pPoints = new RyBase::CRyPointD[pNum];
		lineRing->getPoints(pPoints);

		//QVector<QPointF> polygon_line;
		QPolygonF q_polygon;
		for (int i = 0; i < pNum; i++) 
		{
			QPointF point(pPoints[i].x, pPoints[i].y);

			if (m_polygon.containsPoint(point, Qt::OddEvenFill))
			{
				q_polygon.push_back(QPointF(pPoints[i].x, pPoints[i].y));
			}
		}

		if (q_polygon.size()>1)
		{
			const RyBase::CRyVariant& var = feature->getValue(RY_TEXT("编码"));
			mst->m_jmdSystem[QString::number(var.getINT32())].append(q_polygon);

			const RyBase::CRyVariant& var1 = feature->getValue(RY_TEXT("Area"));
			const RyBase::CRyVariant& var2 = feature->getValue(RY_TEXT("名称"));
			const RyBase::CRyVariant& var4 = feature->getValue(RY_TEXT("要素编号"));
			mst->totalArea+= XGISInterface::getArea(q_polygon);
			mst->m_id[QString::number(var4.getINT32())]= XGISInterface::getArea(q_polygon);
			mst->m_Areas[QString::fromStdWString(var2.toWString())] = XGISInterface::getArea(q_polygon);// var1.getDouble();
			const RyBase::CRyVariant& var3 = feature->getValue(RY_TEXT("类型"));
			if (QString::fromStdWString(var3.toWString()) != QString::fromLocal8Bit("县、县级市驻地"))
			{
				mst->BigCity++;
			}
			else if (QString::fromStdWString(var3.toWString()) != QString::fromLocal8Bit("乡镇、农场驻地"))
			{
				mst->MiddleTownship++;
			}
			else if(QString::fromStdWString(var3.toWString()) != QString::fromLocal8Bit("村"))
			{
				mst->SmallCountry++;
			}
		}
		
	
		delete[] pPoints;
	}

	QPolygonF m_polygon;
	stJmdfx* mst;
};
4.1.2.3)点包含判断
复制代码
		//QVector<QPointF> polygon_line;
		QPolygonF q_polygon;
		for (int i = 0; i < pNum; i++) 
		{
			QPointF point(pPoints[i].x, pPoints[i].y);

			if (m_polygon.containsPoint(point, Qt::OddEvenFill))
			{
				q_polygon.push_back(QPointF(pPoints[i].x, pPoints[i].y));
			}
		}
4.1.2.4)坐标转换( 地理坐标转地图坐标)
复制代码
double XGISInterface::getArea(const QPolygonF& pt)
{
	double area = 0.0;
	QPolygonF pts = pt;
	XGISInterface::geo2Map(pts);

	CRyPointD* points = new CRyPointD[pts.size()];
	for (int i = 0; i < pts.size(); i++)
	{
		points[i] = RyBase::CRyPointD(pts[i].x(), pts[i].y());
	}
	RyGeometry::CRyPolygon polygon(points, pts.size());
	area = polygon.getArea() / 1000 / 1000;
	delete[] points;
	return area;
}

4.2)pBeResidentSystemWin->setData(m_d->jtfx);//触发绘制

复制代码
void BeResidentSystemWin::setData(const stJmdfx &sx)
{
	mpResidentPlotGraphics->m_jmdSystem= sx.m_jmdSystem;
	mpResidentPlotGraphics->m_Areas = sx.m_Areas;
	mpResidentPlotGraphics->m_MaxArea = sx.m_MaxArea;
	mpResidentPlotGraphics->m_SecondArea = sx.m_SecondArea;
	mpResidentPlotGraphics->m_MaxAreaName = sx.m_MaxAreaName;
	mpResidentPlotGraphics->m_SecondAreaName = sx.m_SecondAreaName;
	mpResidentPlotGraphics->m_Density = sx.m_Density;
	BePlotGraphicsMgr::instance()->refresh();
}

4.2.1)触发绘制

复制代码
class ResidentPlotGraphics : public BePlotGraphics
{
public:
	virtual void draw(RyGraphics::CRyGraphics* graphics)
	{

		for (QMap<QString, QVector<QVector<QPointF>>>::iterator it = m_jmdSystem.begin(); it != m_jmdSystem.end(); it++)
		{
			QVector<QVector<QPointF>> vecPts1 = it.value();
			for (int i = 0; i < vecPts1.size(); ++i)
			{
				QVector<QPointF> vecPts = vecPts1[i];
				int iSize = vecPts.size();
				XGISInterface::geo2Pix(vecPts, LayerSRS.toStdWString());
				RyBase::CRyPointF* points = new RyBase::CRyPointF[iSize];
				for (int k = 0; k < iSize; ++k)
				{
					const QPointF& pt = vecPts.at(k);
					points[k].x = pt.x();
					points[k].y = pt.y();
				}
				QColor color = getColor(it.key().toInt());
				RyGraphics::CRyPen pen(RyGraphics::CRyColor(color.red(), color.green(), color.blue()));
				pen.setWidth(3);
				//graphics->drawLines(pen, points, iSize);

				if (vecPts.front() == vecPts.back())
				{
					RyGraphics::CRySolidBrush fillbrush(RyGraphics::CRyColor(color.red(), color.green(), color.blue()));
					graphics->fillPolygon(fillbrush, points, iSize);
				}
			}
		}
	}

	QColor getColor(const int idnex)
	{
		static QVector<QColor> mapColor;
		if (mapColor.isEmpty())
		{
			mapColor.push_back(QColor(36, 235, 240));
			mapColor.push_back(QColor(36, 235, 240));
			mapColor.push_back(QColor(36, 235, 240));
			mapColor.push_back(QColor(36, 235, 240));
			mapColor.push_back(QColor(36, 235, 240));

		}
		return mapColor[idnex % mapColor.size()];
	}

	//面积集合
	QMap<QString, QVector<QVector<QPointF>>> m_jmdSystem;
	//名称 面积  集合
	QMap<QString, double> m_Areas;
	//最大面积
	double m_MaxArea;
	//第二面积
	double m_SecondArea;
	QString m_MaxAreaName;
	QString m_SecondAreaName;
	//密度
	double m_Density;
	QPolygonF m_polygon;
	QString LayerSRS;
};
4.2.1.1)坐标转换(地理坐标转像素坐标)
复制代码
void XGISInterface::geo2Pix(QVector<QPointF>& srcPts, const WSTRING Wkt)
{
	for (int i = 0; i < srcPts.size(); ++i)
	{
		geo2Pix(srcPts[i].rx(), srcPts[i].ry(), Wkt);
	}
}

5.结果

以上是矢量数据的提取

相关推荐
慕木沐19 小时前
Google ADK Java 1.0版本 核心机制与实战 Demo
java·开发语言·python
Roann_seo%20 小时前
C++文件操作完全指南:从文本读写到二进制文件处理
开发语言·c++
huangdong_21 小时前
淘宝商品SKU图自动分类技术深度解析:从DOM解析到智能归档
开发语言·javascript·ecmascript
阿正的梦工坊21 小时前
【Rust】12-借用检查器与非词法生命周期
开发语言·后端·rust
qq_25183645721 小时前
基于java Web网络订餐系统设计与实现 源码文档
java·开发语言·前端
秋921 小时前
3年经验Python后端转AI Engineer:3个月实战转型计划(2026版)
开发语言·人工智能·python
凡人叶枫21 小时前
Effective C++ 条款17:以独立语句将 newed 对象置入智能指针
java·linux·开发语言·c++·算法
飞天狗11121 小时前
零基础JavaWeb入门——第2课:让网页“活”起来 —— JSP是什么?
java·开发语言·前端·后端·web
醇氧1 天前
【Linux】Java 服务生产级部署指南:实现常驻后台、开机自启与系统服务化管理
java·开发语言
凡人叶枫1 天前
Effective C++ 条款16:成对使用 new 和 delete 时要采取相同形式
开发语言·c++·effective c++