ArcEngine中最短路徑的實現(xiàn)_第1頁
ArcEngine中最短路徑的實現(xiàn)_第2頁
ArcEngine中最短路徑的實現(xiàn)_第3頁
ArcEngine中最短路徑的實現(xiàn)_第4頁
ArcEngine中最短路徑的實現(xiàn)_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、ArcEngine中最短路徑的實現(xiàn)最短路徑分析屬于ArcGIS的網(wǎng)絡(luò)分析范疇。而ArcGIS的網(wǎng)絡(luò)分析分為兩 類,分別是基于幾何網(wǎng)絡(luò)和網(wǎng)絡(luò)數(shù)據(jù)集的網(wǎng)絡(luò)分析。它們都可以實現(xiàn)最短路徑功能。 下面先介紹基于幾何網(wǎng)絡(luò)的最短路徑分析的實現(xiàn)。以后會陸續(xù)介紹基于網(wǎng)絡(luò)數(shù)據(jù)集的 最短路徑分析以及這兩種方法的區(qū)別。幾何網(wǎng)絡(luò)是一種特殊的特征要素類,由一系列不同類別的點要素和線要素(可以度 量并能圖形表達)組成的,可在FeatureDataset下面創(chuàng)建,可進行圖形與屬 性的 編輯。包括流向分析和追蹤分析兩大功能。主要接口是ITraceFlowSolver。我們先 在一幅地圖上做出一個幾何網(wǎng)絡(luò)才能進行最短路徑分析。下

2、面是主要的一些步驟:1、打開ArcCatalog ,連接到包含地圖的文件夾。2、在空白處,右鍵新建一個“ Personal GeoDatabase ”。3、在生成的 Personal GeoDatabase 上右鍵新建一個 feature dataset o4、雙擊 Personal GeoDatabase jfii,找到剛才 new 出的 feature dataset ,右鍵 Import導(dǎo)入Feature Class (Single),選擇要建立幾何網(wǎng)絡(luò)的圖層或者shape文 件。5、然后再右鍵新建一個Geometric Network ,選擇從已存在的圖元中建立幾何 網(wǎng) 絡(luò)。6 打開

3、ArcMap,把剛才建立的 “ Personal GeoDatabase Feature Class ” 添加 到地 圖中,這樣幾何網(wǎng)絡(luò)就建立好了。這樣我們就建立好一個幾何網(wǎng)絡(luò)了。我們現(xiàn)在要通過編程來實現(xiàn)最短路徑,用到 的接口主要有 INetworkCollection , IGeometricNetwork , IPointT。日D , ITraceFlowSolverGEN (它實現(xiàn) 了 ITraceFlowSolver 的接口),INetSchema, EIDHelpero主要步驟如下:1、獲取幾何網(wǎng)絡(luò)工作空間2、定義一個邊線旗數(shù)組,把離點串最近的網(wǎng)絡(luò)元素添加進數(shù)組3、設(shè)置開始和結(jié)束邊線

4、的權(quán)重4、進行路徑分析5、得到路徑分析的結(jié)果上次介紹了用幾何網(wǎng)絡(luò)實現(xiàn)的“最短路徑”,這次用網(wǎng)絡(luò)數(shù)據(jù)集實現(xiàn)真正的最短 路徑功能,跟上次一樣,先處理下數(shù)據(jù)。1、先打開ArcCatalog,連接到目標(biāo)文件夾,假定該文件下有一個名為road的道路圖層。Cgtents Previ ew Met ad ata INameml Adm_iAjrea_regi on shp "2"AdmALandm ark_p 01 nt r slip AAGreenBel t_regi oxi. shp.inAdLandm ark_point. shp Landus e j> olyl i na.

5、 shp Landnse_r egi on. Ahp o ad_p olyl i ne. whp Ar.lFOI point, shphl Rai 1W SUH 01yLi P-g-B hp繪數(shù)據(jù)集I Typg Shape file Shape: £il * Shapefile Map document Shapefile Shap&file!ShapefileShap&fileShapefile Sh 斗 p e: "總2、在road圖層上右鍵新建一個網(wǎng)絡(luò)數(shù)據(jù)集,并按照其默認(rèn)設(shè)置直至完成庵 CopyX DelateCtrl+CRenameF2Create

6、La2er. .ExportNew Network Dataset.IdrContents Previ ew Metadata U4JH4lAl Adni_Are=a_regi on wh* 2LJ AdirALandm ark_p 0 i nt. shpGrt_regi©n. shp JlAhefei. mxdI Landm ark point, shp " Landus e_p olyl i ne a shp 03 Landus ®_r 皂 on. mhp adjpolyline, shp A*IFOI j>oint. shp ”八Tl Rai 1 Wa

7、y_polylin 電.shp 耳Jir og-uhpProperties.I Type ShapefileShapefileShape file Map DocumentShapefi 1 色Shapefile ShapefileShapefile ShapefileShape filer oad ND. MD網(wǎng)絡(luò)數(shù)據(jù)集 Shap&file Network Dataset siiavfiid3、打開該地圖的工作空間,把剛才新建的網(wǎng)絡(luò)數(shù)據(jù)集添加工作空間中Add DataLook in:,最短路徑網(wǎng)絡(luò)數(shù)據(jù)集3但I葡I后蠢圈Iroad_ND NDAdni_Area_regi on. shp

8、Adm_Landmark_point. shpGreeriEelt_region. shpMroad. shp圓Iroad ND Junctions. shpLandmark point. shprHLandus«_polyline. shpLanduse_regi on. shp mainroad_polyline shp|P0I point. shpZJ"1 Railway polyline, shpName:|road_ND.NDShow M type: |Datasets and Layers4、在網(wǎng)絡(luò)分析菜單中選擇新建最近設(shè)施點Geastati stical Ar

9、ualystGr aphi cLabeling7 LayoutNAp CacheMyToolb&rPubliEh&rRaster PaintiiigR«preseikt&ti onRo-ute E di tingSmpl 電 Ex tens! on ToolbarS chemati cNew gouteNew Servi ce AreaNew Closest Facili tyMew OD Cost H&trixNew Conne 匚OptI OTLE.hefei.axd - Arclap - ArcinfoFile Edi t Vi ew Inser

10、t Selection Tools Window Help田國昌/鼬第x|也通eNetwork Analyst .1:3,411':Q :.sJ U44 H<4Network Dataset:X金五里墩郵江淮儀表廠Jj3 0c 回回眄因園E3團舊團|iow jJ I 0Closest Facility最短路徑分析圖層Facilities Error 。Located?O Unlocated 0 Incidents1 ErrorBB Located ?| |Unlocated 0 BarriersO ErrorLocated? Unlocated-0 Routes Routesro

11、ad_ND JunctionsP0I_pointAdm_L«indm w k_p 01ntLandm arkoint roadroad_NDEdgesRailWay-polyline lay>mainro ad_p olyl i neroad_polyline layerLanduse_polyli neGreenBelt_regi onLanduse_region layerAdm Ayaa r finNJ >Display I Source Selection |Drawing 五里量三I |10 二JB Z U 4 8這時在工作空間里,可以看到多了一個名為“ Clo

12、sest Facility "的圖層。它下面還有4個子圖層,名字分別為 “Facilities ","Incidents ",“ Barriers ",“ Routesv Facilities ”就是設(shè)施點圖層,也就是目的點,uIncidents ”的意思就是出發(fā)點,“ Barriers n是障礙點,意思就是地圖某條道 路附近有一個障礙點,如果障礙點與道路距離在容限范圍內(nèi),則表示此道路不通,“Routes”就是最終的結(jié)果。這樣我們編程實現(xiàn)最短路徑的思路就出現(xiàn)了 :1、 添加出發(fā)點。2、 添加目的點。3、生成最優(yōu)路徑,獲取結(jié)果百。3 ©

13、 :; : a Q射 卜0 添加 晦 刷新 平移M賒最短路及安徽省醫(yī)藥學(xué)校這里的添加出發(fā)點或者目的點,是往“ Facilities "或"Incidents ”圖層上添 加元素。獲取結(jié)果也是從“ Routes"中獲取Polyline。往“ Facilities "或“In cide nts ”圖層上添加元素用到的主要方法是INALocator的QueryLocationByPoint函數(shù),生成路徑主要接口是INASolver和它的Solve方 法。獲取結(jié)果是按屬性查找,因為“ Routes ”類其實就是一個圖層類,只不過只是存在于內(nèi)存。1 CMapCon

14、trolDefaultm_map;2 IPointCollectionPtr mJpPointCollection;33 ILayerPtr ipLayer = m_map.GetLayer(O);/ 網(wǎng)絡(luò)數(shù)據(jù)集4 INALayerPtr ipNaLayer = ipLayer;5 if (NULL = ipNaLayer)6 7 return;8 )1011 INAContextPtr ipNaContext;12 HRESULT hr = ipNaLayer->get_Context(&ipNaContext);13 INACIassLoaderPtr ipNACIassLo

15、ader(CLSID_NACIassLoader);14 INALocatorPtr ipNALocator = NULL;15 hr = ipNaContext->get_Locator(&ipNALocator);16 ipNALocator->put_SnapToleranceUnits(esriMeters);17 ipNALocator->put_SnapT olerance(200);18 ipNaContext;19 hr = ipNACIassLoader->putref_Locator(ipNALocator);2020 INamedSetPt

16、r ipNamedSet = NULL;21 ipNaContext->get_NACIasses(&ipNamedSet);2322 CString szName = "Facilities"23 BSTR bstrName = szName.AllocSysString();24 INACIassPtr ipNAFacilitiesClass = NULL;25 hr = ipNamedSet->get_ltemByName(bstrName,(IUnknown*)&ipNAFacilitiesClass);26 szName = "

17、;Incidents”;27 bstrName = szName. AllocSysString();28 INACIassPtr ipNAIncidentsClass = NULL;29 hr = ipNamedSet->get_ltemByName(bstrName,(IUnknown*)&ipNAIncidentsClass);30 szName = nCFRoutesH;31 bstrName = szName. AllocSysString();32 INACIassPtr ipNARoutesClass = NULL;33 hr = ipNamedSet->ge

18、t_ltemByName(bstrName,(IUnknown*)&ipNARoutesClass);3634 INALocationPtr ipNALocationl (CLSID_NALocation);35 INALocationPtr ipNALocation2(CLSID_NALocation);36 ipNACIassLoader->get_Locator(&ipNALocator);37 IPointPtr ipBeginPoint(CLSID_Point);38 m_ipPointCollection->get_Point(0, &ipBeg

19、inPoint);39 IPointPtr ipEndPoint(CLSID_Point);40 mJpPointCollection->get_Point(1, &ipEndPoint);41 IPointPtr ipPointl (CLSID_Point);42 IPointPtr ipPoint2(CLSID二Point);&ipNALocation1,&ipNALocation2,43 double dbLVal = 0.0;44ipNALocator->QueryLocationByPoint(ipBeginPoint,&ipPoint1,

20、 &dbLVal);45ipNALocator->QueryLocationByPoint(ipEndPoint,&ipPoint2, &dbLVal);4950 INALocationObjectPtr ipNALocationObject = NULL;51 IFeatureClassPtr ipFeatureClass = ipNAIncidentsClass;52 IFeaturePtr ipFeature = NULL;53 ipFeatureClass->CreateFeature(&ipFeature);54 IRowSubtypesP

21、tr ipRowSubtypes = ipFeature;55 ipRowSubtypes->lnitDefaultValues();56 ipFeature->putref_Shape(ipBeginPoint);57 ITablePtr ipTable = NULL;58 ipFeature->get_T able(&ipT able);59 long nlndex = 0;60 szName = "Sequence"61 bstrName = szName.AllocSysString();62 ipTable->FindField(b

22、strName, &nlndex);63 VARIANT varjnt;64 varJVal = 1;65 varjnt.vt = VTJNT;66 ipFeature->put_Value(nlndex, varjnt);67 szName = "Name"68 bstrName = szName. AllocSysString();69 ipTable->FindField(bstrName, &nlndex);70 ipFeature->put_Value(nlndex, COIeVariant(nStart Point&

23、quot;);71 ipNALocationObject = ipFeature;72 ipNALocationObject->put_NALocation(ipNALocation1);73 ipFeature->Store();74 IFieldsPtr ipFields(CLSID_Fields);75 hr = ipTable->get_Fields(&ipFields);76 long nFieldCount = 0;77 hr = ipFields->get_FieldCount(&nFieldCount);78 for (int k = 0

24、; k < nFieldCount; k+)79 80 IFieldPtr ipField(CLSID_Field);81 ipFields->get_Field(k, &ipField);82 BSTR bstrFieldName;83 ipField->get_Name(&bstrFieldName);84 CString szFieldName = bstrFieldName;85 8687 ipFeatureClass = ipNAFacilitiesClass;88 ipFeatureClass->CreateFeature(&ipFe

25、ature);89 ipRowSubtypes = ipFeature;90 ipRowSubtypes->lnitDefaultValues();91 ipFeature->putref_Shape(ipEndPoint);92 ipTable = NULL;93 ipFeature->get_T able(&ipT able);94 nlndex = 0;95 szName = "Sequence”;96 bstrName = szName. AllocSysString();97 ipTable->FindField(bstrName, &

26、;nlndex);98 varJVal = 2;99 ipFeature->put_Value(nlndex, varjnt);100 szName = "Name"101 bstrName = szName. AllocSysString();102 ipTable->FindField(bstrName, &nlndex);103 ipFeature->put_Value(nlndex, COIeVariant("End Point1');104 ipNALocationObject = ipFeature;105

27、 ipNALocationObject->put_NALocation(ipNALocation2);106 ipFeature->Store();107108 INACIosestFacilitySolverPtr ipNACFSolver = NULL;109 INASolverPtr ipNASolver = NULL;110 ipNaContext->get_Solver(&ipNASolver);111112 IGPMessagesPtr ipGPM(CLSID_GPMessages);113 ITrackCancelPtr ipTrackCancel(CL

28、SID TrackCancel);114 VARIANT_BOOL blsPartialSolution;115 ipNASolver->Solve(ipNaContext, ipGPM, ipTrackCancel,&blsPartialSolution);116117 szName = nCFRoutes"118 bstrName = szName.AllocSysString();119 ipNARoutesClass = NULL;120 hr = ipNamedSet->getJtemByName(bstrName,(IUnknown*)&ipN

29、ARoutesClass);121122 IFeatureClassPtr ipFeatureClassRoutes = ipNARoutesClass;IFeatureCursorPtr ipFCursor = NULL;IQueryFilterPtr ipQueryFilter(CLSID_QueryFilter);CString szQueryFilter("ObjectlD > 0n);BSTR bstr_QueryFilter = szQueryFilter.AllocSysString();ipQueryFilter->put_WhereClause(bstr_QueryFilter); VARIANT_BOOL bCycle =VARIANT_FALSE;try ipFeatureClassRoutes

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論