接口设计需要传入查询信息关键字,属性表字段,坐标点,查询范围
算法思路:
(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();
}
}