gdal根据路网数据和矢量点查询最近服务点

本文介绍了一种路网查询与最短路径算法,该算法通过接收查询信息关键字、属性表字段、坐标点及查询范围,实现路网数据筛选、目标矢量信息查询、起始点确定与最短路径计算。具体步骤包括:根据坐标点筛选路网数据,按条件查询目标矢量信息,找到离坐标点最近的起始点,并计算最短路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接口设计需要传入查询信息关键字,属性表字段,坐标点,查询范围
算法思路:
(1)根据坐标点删选出来路网数据的查询范围图层
(2)根据查询条件查询出来目标矢量信息
(3)获取目标矢量信息和开始点信息在Graph中求出离坐标点最近的起始点
(4)根据Graph查询最短路径
算法需要结合最短路径计算算法一起使用,在这里只贴出来前两步的具体算法

class TDFindClosestFacilities :public TDconversionBase
{
public:
	bool process(LayerPathInfoV1 layerpathinfo, LayerPathInfoV1 armlayerpathinfo, std::vector<std::string> vecstr,std::map<std::string, std::string> fieldParams,double range);
protected:
	void cal();
	virtual void calsingleFeature(OGRFeature *poFeature, int flagscal = 0) override;
private:
	std::map<std::string, std::string> m_FieldParams;
	double m_range;
	std::vector<OGRPoint *> m_vecpoint;
};
bool TDFindClosestFacilities::process(LayerPathInfoV1 layerpathinfo, LayerPathInfoV1 armlayerpathinfo, std::vector<std::string> vecstr, std::map<std::string, std::string> fieldParams, double range)
{
	std::for_each(vecstr.begin(), vecstr.end(), [&](std::string & ogrstr) {
		auto pgeoms = OGRGeometryFactory::createFromGeoJson(ogrstr.c_str());
		m_vecpoint.push_back(dynamic_cast<OGRPoint*>(pgeoms));
	});
	m_FieldParams = fieldParams;
	m_range = range;
	auto fun = std::bind(&TDFindClosestFacilities::cal,this);
	return process_byfunction(layerpathinfo, armlayerpathinfo,fun);
}
void TDFindClosestFacilities::calsingleFeature(OGRFeature *poFeature, int flagscal)
{
	IF_NULL_RETRUN(poFeature)
	auto pgeoms = poFeature->GetGeometryRef();
	IF_NULL_RETRUN(pgeoms)
	OGRPoint tempP;
	pgeoms->Centroid(&tempP);
	std::for_each(m_vecpoint.begin(), m_vecpoint.end(), [&](OGRPoint *ppoint) {
		if (TDAPICommon::computeDistanceBearing(tempP, *ppoint, pmoSourceSRS) < m_range)
		{
			m_cachevector.push_back(poFeature->Clone());
		}
	});
}
void TDFindClosestFacilities::cal()
{
	std::ostringstream sql;
	sql << "select * from " << m_orgLayer->GetName() << " WHERE 1=1 ";
	std::for_each(m_FieldParams.begin(), m_FieldParams.end(), [&](std::map<std::string, std::string>::value_type & it) {
		sql << "and " << it.first << "like '%" << it.second << "%'";
	});
	m_cachevector.clear();
	auto temparmlayer = m_preadDataset->ExecuteSQL(sql.str().c_str(), NULL, NULL);
	temparmlayer->ResetReading();
	OGRFeature *poFeature;
	while ((poFeature = temparmlayer->GetNextFeature()) != NULL)
	{
		calsingleFeature(poFeature, m_flagscal);
		wiriteInfo();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值