搜寻与地图上指定点最近的道路节点
private long FindStartLocation()
{
long i=0,startLocation=0,listNum=mDataList.Num;
double minDist=0,tmpDist=0;
string strStartPoint,tableName="出发地",colName="站名";
TNode tNode=new TNode();
strStartPoint=DropDownList1.SelectedItem.ToString();
MapInfo.Mapping.FeatureLayer fl = (MapInfo.Mapping.FeatureLayer)MapControl1.Map.Layers[tableName];
MapInfo.Data.Table t = fl.Table;
Find find=new Find(t,t.TableInfo.Columns[colName]);
FindResult findResult=find.Search(strStartPoint);
tNode.Sx=findResult.FoundPoint.X;
tNode.Sy=findResult.FoundPoint.Y;
find.Dispose();
minDist=dist(tNode,mDataList[i]);
while(i < listNum)
{
if((mDataList[i].Sx==tNode.Sx)&&(mDataList[i].Sy==tNode.Sy))
{
startLocation=i;
return startLocation;
}
else
{
tmpDist=dist(tNode,mDataList[i]);
if(tmpDist < minDist)
{
minDist=tmpDist;
startLocation=i;
}
}
i++;
}
return startLocation;
}
{
long i=0,startLocation=0,listNum=mDataList.Num;
double minDist=0,tmpDist=0;
string strStartPoint,tableName="出发地",colName="站名";
TNode tNode=new TNode();
strStartPoint=DropDownList1.SelectedItem.ToString();
MapInfo.Mapping.FeatureLayer fl = (MapInfo.Mapping.FeatureLayer)MapControl1.Map.Layers[tableName];
MapInfo.Data.Table t = fl.Table;
Find find=new Find(t,t.TableInfo.Columns[colName]);
FindResult findResult=find.Search(strStartPoint);
tNode.Sx=findResult.FoundPoint.X;
tNode.Sy=findResult.FoundPoint.Y;
find.Dispose();
minDist=dist(tNode,mDataList[i]);
while(i < listNum)
{
if((mDataList[i].Sx==tNode.Sx)&&(mDataList[i].Sy==tNode.Sy))
{
startLocation=i;
return startLocation;
}
else
{
tmpDist=dist(tNode,mDataList[i]);
if(tmpDist < minDist)
{
minDist=tmpDist;
startLocation=i;
}
}
i++;
}
return startLocation;
}