GIS软件工程实习报告最短路径分析Word文档下载推荐.docx
《GIS软件工程实习报告最短路径分析Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《GIS软件工程实习报告最短路径分析Word文档下载推荐.docx(18页珍藏版)》请在冰豆网上搜索。
![GIS软件工程实习报告最短路径分析Word文档下载推荐.docx](https://file1.bdocx.com/fileroot1/2023-1/31/714eb6eb-c044-4afc-9762-adad372ffc91/714eb6eb-c044-4afc-9762-adad372ffc911.gif)
2 添加代码
privateIActiveViewm_ipActiveView;
privateIMapm_ipMap;
//地图控件中地图
privateIGraphicsContainerpGC;
//图形对象
privateboolclicked=false;
intclickedcount=0;
privatedoublem_dblPathCost=0;
privateIGeometricNetworkm_ipGeometricNetwork;
privateIPointCollectionm_ipPoints;
//输入点集合
privateIPointToEIDm_ipPointToEID;
privateIEnumNetEIDm_ipEnumNetEID_Junctions;
privateIEnumNetEIDm_ipEnumNetEID_Edges;
privateIPolylinem_ipPolyline;
privateIMapControl3mapctrlMainMap=null;
privatevoidForm1_Load(objectsender,EventArgse)
{
//对象初始化
mapctrlMainMap=(IMapControl3)this.axMapControl1.Object;
m_ipActiveView=axMapControl1.ActiveView;
m_ipMap=m_ipActiveView.FocusMap;
clicked=false;
pGC=m_ipMapasIGraphicsContainer;
}
privatevoidFindpath_Click(objectsender,EventArgse)
mapctrlMainMap.CurrentTool=null;
//设置鼠标样式
axMapControl1.MousePointer=esriControlsMousePointer.esriPointerCrosshair;
if(axMapControl1.LayerCount==0)
MessageBox.Show("
请先加载几何网络数据!
"
);
return;
ILayeripLayer=m_ipMap.get_Layer(0);
IFeatureLayeripFeatureLayer=ipLayerasIFeatureLayer;
IFeatureDatasetipFDS=ipFeatureLayer.FeatureClass.FeatureDataset;
OpenFeatureDatasetNetwork(ipFDS);
clicked=true;
clickedcount=0;
pGC.DeleteAllElements();
privatevoidSolvePath_Click(objectsender,EventArgse)
axMapControl1.MousePointer=esriControlsMousePointer.esriPointerDefault;
if(SolvePathGan("
Weight"
))//先解析路径
IPolylineipPolyResult=PathPolyLine();
//最后返回最短路径
if(ipPolyResult.IsEmpty)
没有路径可到!
!
else
IRgbColorcolor=newRgbColorClass();
color.Red=255;
color.Blue=64;
color.Green=128;
LineElementClasselement=newLineElementClass();
ILineSymbollinesymbol=newSimpleLineSymbolClass();
linesymbol.Color=colorasIColor;
linesymbol.Width=3;
element.Geometry=m_ipPolyline;
element.Symbol=linesymbol;
pGC.AddElement(element,0);
m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);
axMapControl1.FlashShape(element.Geometry);
路径经过"
+m_ipEnumNetEID_Edges.Count+"
条线"
+"
\r\n"
经过节点数为"
+m_ipEnumNetEID_Junctions.Count+"
路线长度为"
+m_ipPolyline.Length.ToString("
#######.##"
)+"
"
几何路径信息"
//路径缩放功能
privatevoidSuoFang_Click(objectsender,EventArgse)
if(m_ipPolyline==null)
当前没有执行路径查询!
!
请确认!
this.axMapControl1.Extent=m_ipPolyline.Envelope;
#region自定义路径查询函数
publicvoidOpenFeatureDatasetNetwork(IFeatureDatasetFeatureDataset)
CloseWorkspace();
if(!
InitializeNetworkAndMap(FeatureDataset))
Console.WriteLine("
打开network出错"
//关闭工作空间
privatevoidCloseWorkspace()
m_ipGeometricNetwork=null;
m_ipPoints=null;
m_ipPointToEID=null;
m_ipEnumNetEID_Junctions=null;
m_ipEnumNetEID_Edges=null;
m_ipPolyline=null;
//初始化几何网络和地图
privateboolInitializeNetworkAndMap(IFeatureDatasetFeatureDataset)
IFeatureClassContaineripFeatureClassContainer;
IFeatureClassipFeatureClass;
IGeoDatasetipGeoDataset;
ILayeripLayer;
IFeatureLayeripFeatureLayer;
IEnvelopeipEnvelope,ipMaxEnvelope;
doubledblSearchTol;
INetworkCollectionipNetworkCollection=FeatureDatasetasINetworkCollection;
intcount=ipNetworkCollection.GeometricNetworkCount;
//获取第一个几何网络工作空间
m_ipGeometricNetwork=ipNetworkCollection.get_GeometricNetwork(0);
INetworkipNetwork=m_ipGeometricNetwork.Network;
if(m_ipMap!
=null)
ipFeatureClassContainer=m_ipGeometricNetworkasIFeatureClassContainer;
count=ipFeatureClassContainer.ClassCount;
for(inti=0;
i<
count;
i++)
ipFeatureClass=ipFeatureClassContainer.get_Class(i);
ipFeatureLayer=newFeatureLayerClass();
ipFeatureLayer.FeatureClass=ipFeatureClass;
for(intj=0;
j<
m_ipMap.LayerCount;
j++)
if(m_ipMap.get_Layer(j).Name.ToUpper()==ipFeatureLayer.Name.ToUpper())
continue;
count=m_ipMap.LayerCount;
ipMaxEnvelope=newEnvelopeClass();
ipLayer=m_ipMap.get_Layer(i);
ipFeatureLayer=ipLayerasIFeatureLayer;
ipGeoDataset=ipFeatureLayerasIGeoDataset;
ipEnvelope=ipGeoDataset.Extent;
ipMaxEnvelope.Union(ipEnvelope);
m_ipPointToEID=newPointToEIDClass();
m_ipPointToEID.SourceMap=m_ipMap;
m_ipPointToEID.GeometricNetwork=m_ipGeometricNetwork;
doubledblWidth=ipMaxEnvelope.Width;
doubledblHeight=ipMaxEnvelope.Height;
if(dblWidth>
dblHeight)
dblSearchTol=dblWidth/100;
dblSearchTol=dblHeight/100;
m_ipPointToEID.SnapTolerance=dblSearchTol;
returntrue;
//返回路径的几何体
publicIPolylinePathPolyLine()
IEIDInfoipEIDInfo;
IGeometryipGeometry;
if(m_ipPolyline!
=null)returnm_ipPolyline;
m_ipPolyline=newPolylineClass();
IGeometryCollectionipNewGeometryColl=m_ipPolylineasIGeometryCollection;
//引用传递
ISpatialReferenceipSpatialReference=m_ipMap.SpatialReference;
IEIDHelperipEIDHelper=newEIDHelper();
ipEIDHelper.GeometricNetwork=m_ipGeometricNetwork;
ipEIDHelper.OutputSpatialReference=ipSpatialReference;
ipEIDHelper.ReturnGeometries=true;
IEnumEIDInfoipEnumEIDInfo=ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges);
intcount=ipEnumEIDInfo.Count;
ipEnumEIDInfo.Reset();
string[]info;
info=newstring[count];
ipEIDInfo=ipEnumEIDInfo.Next();
ipGeometry=ipEIDInfo.Geometry;
ipNewGeometryColl.AddGeometryCollection(ipGeometryasIGeometryCollection);
info[i]=m_ipPolyline.Length.ToString();
returnm_ipPolyline;
publicboolSolvePathGan(stringWeightName)
try
intintJunctionUserClassID;
intintJunctionUserID;
intintJunctionUserSubID;
intintJunctionID;
IPointipFoundJunctionPoint;
ITraceFlowSolverGENipTraceFlowSolver=newTraceFlowSolver()asITraceFlowSolverGEN;
INetSolveripNetSolver=ipTraceFlowSolverasINetSolver;
if(m_ipGeometricNetwork==null)
returnfalse;
ipNetSolver.SourceNetwork=ipNetwork;
INetElementsipNetElements=ipNetworkasINetElements;
if(m_ipPoints==null)
{MessageBox.Show("
请选择点!
intintCount=m_ipPoints.PointCount;
//这里的points有值吗?
////定义一个边线旗数组
//*********最近点***************//////////
IJunctionFlag[]pJunctionFlagList=newJunctionFlag[intCount];
intCount;
INetFlagipNetFlag=newJunctionFlag()asINetFlag;
IPointipJunctionPoint=m_ipPoints.get_Point(i);
//查找输入点的最近的网络点
m_ipPointToEID.GetNearestJunction(ipJunctionPoint,outintJunctionID,outipFoundJunctionPoint);
ipNetElements.QueryIDs(intJunctionID,esriElementType.esriETJunction,outintJunctionUserClassID,outintJunctionUserID,outintJunctionUserSubID);
ipNetFlag.UserClassID=intJunctionUserClassID;
ipNetFlag.UserID=intJunctionUserID;
ipNetFlag.UserSubID=intJunctionUserSubID;
IJunctionFlagpTemp=(IJunctionFlag)(ipNetFlagasIJunctionFlag);
pJunctionFlagList[i]=pTemp;
ipTraceFlowSolver.PutJunctionOrigins(refpJunctionFlagList);
INetSchemaipNetSchema=ipNetworkasINetSchema;
INetWeightipNetWeight=ipNetSchema.get_WeightByName(WeightName);
INetSolverWeightsipNetSolverWeights=ipTraceFlowSolverasINetSolverWeights;
ipNetSolverWeights.FromToEdgeWeight=ipNetWeight;
//开始边线的权重
ipNetSolverWeights.ToFromEdgeWeight=ipNetWeight;
//终止边线的权重
object[]vaRes=newobject[intCount-1];
//通过findpath得到边线和交汇点的集合
ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected,
esriShortestPathObjFn.esriSPObjFnMinSum,outm_ipEnumNetEID_Junctions,outm_ipEnumNetEID_Edges,intCount-1,refvaRes);
m_dblPathCost=0;
vaRes.Length;
doublem_Va=(double)vaRes[i];
m_dblPathCost=m_dblPathCost+m_Va;
catch(Exceptionex)
Console.WriteLine(ex.Message);
#endregion
privatevoidaxMapControl1_OnMouseDown(objectsender,IMapControlEvents2_OnMouseDownEvente)
if(clicked!
=true)
IPointipNew;
m_ipPoints=newMultipoint();
ipNew=m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x,e.y);
objecto=Type.Missing;
m_ipPoints.AddPoint(ipNew,refo,refo);
IElementelement;
ITextElementtextelement=newTextElementClass();
element=textelementasIElement;
clickedcount++;
textelement.Text=clickedcount.ToString();
element.Geometry=m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x,e.y);
3.4实验结果
在得到的窗口中加载“甘地的个人地理数据库”(在压缩包中有)中的几何网络“road_Net”,将几何网络地图加载到地图显示窗口中,如下图所示:
点击图标
添加起始点,效果如下图:
然后点击图标
,计算最短路径,效果如下图:
最后点击图标
得到最短路径的缩