最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Arcgis做路徑規(guī)劃方式(使用python腳本調(diào)用)

 更新時(shí)間:2024年12月20日 08:50:59   作者:子裳  
本文介紹了如何使用ArcGIS和Python來解決鐵路路徑規(guī)劃問題,通過配置ArcGIS、導(dǎo)入路網(wǎng)數(shù)據(jù)和列車行駛點(diǎn)數(shù)據(jù)、處理線要素、構(gòu)建拓?fù)浣Y(jié)構(gòu),可以使用Network?Analyst工具進(jìn)行路徑分析,最后,通過Python腳本自動(dòng)化處理大量數(shù)據(jù),生成最優(yōu)路徑

場景

如何在全部的鐵路線路數(shù)據(jù)中找到點(diǎn)到點(diǎn)的路徑,并且點(diǎn)與點(diǎn)之前的路線可能跨越其它點(diǎn)-也就是路徑規(guī)劃的問題。

須知

  • argis: “計(jì)算機(jī)制圖”應(yīng)用,包含了全球范圍內(nèi)的底圖、地圖數(shù)據(jù)、應(yīng)用程序,以及可配置的應(yīng)用模板和開發(fā)人員使用的 GIS 工具和 API,可用于創(chuàng)建 Web 地圖、發(fā)布GIS服務(wù)、共享地圖、數(shù)據(jù)和應(yīng)用程序
  • 路徑規(guī)劃:根據(jù)起始出發(fā)點(diǎn)和到達(dá)點(diǎn)(可設(shè)置途經(jīng)點(diǎn)和障礙點(diǎn)),在已確定的路網(wǎng)數(shù)據(jù)中找到最優(yōu)路線(最短路程,最低時(shí)間)

工具

  • argis10.2 
  • python2(建議使用arcgis自帶python)

數(shù)據(jù)

以鐵路數(shù)據(jù)為例: 

  • 路網(wǎng)數(shù)據(jù)(全國鐵路線路shp文件) 
  • 列車行駛中所有的點(diǎn)到點(diǎn)的列表數(shù)據(jù)(shp文件形式,可用cvs轉(zhuǎn)成shp)

步驟

argis配置

配置好argis,在argis客戶端計(jì)算出一次路徑分析,保證argis可執(zhí)行

配置允許進(jìn)行網(wǎng)絡(luò)數(shù)據(jù)集操作

點(diǎn)擊菜單customize->extensions,勾選network analyst

點(diǎn)擊菜單customize->toolbar,勾選network analyst

數(shù)據(jù)導(dǎo)入

1.打開ArcCatalog,找到文件樹后右鍵新建“File Geodatabase”,隨后在新建的gdb上右鍵新建“feature dataset ”,之后在dataset上右鍵,選擇“Import”–>“Feature Class”導(dǎo)入你的路網(wǎng)數(shù)據(jù)

創(chuàng)建dataset時(shí)需要選擇對應(yīng)的投影和地理坐標(biāo)系

結(jié)果如下:

2.線處理:進(jìn)行線要素的處理 

  • 相交線打斷。在arcToolBox的data management tools —>features—>featuretoline。
  • 在點(diǎn)要素處打斷線。在arcToolBox的data management tools —>features—>split line at point。

3.構(gòu)建拓?fù)浣Y(jié)構(gòu):在數(shù)據(jù)集dataset上右鍵,New —> Network Dataset…

結(jié)果如下:

4.新建一次分析:network analyst —> New Route

結(jié)果如下,左側(cè)為本次分析的數(shù)據(jù)集界面:

5.增加途經(jīng)點(diǎn):Stops 右鍵 -> Load Locations…

選擇途經(jīng)點(diǎn)圖層導(dǎo)入途經(jīng)點(diǎn) 

結(jié)果如下:

6.分析路徑:

點(diǎn)擊 solve

結(jié)果如下:

左側(cè)下的Routes就是我們需要的數(shù)據(jù)

python執(zhí)行準(zhǔn)備

腳本:以下代碼

前面配置的網(wǎng)絡(luò)數(shù)據(jù)集

火車站數(shù)據(jù)以出發(fā)點(diǎn),結(jié)束點(diǎn)兩個(gè)點(diǎn)為一組,全部路線數(shù)據(jù)(shp),如下圖所示,相同的sort為一組:

執(zhí)行腳本

PS: 數(shù)據(jù)量多時(shí),可同時(shí)執(zhí)行多個(gè)腳本,但是執(zhí)行的參數(shù)需要錯(cuò)開,并且網(wǎng)絡(luò)數(shù)據(jù)集需要每個(gè)腳本一個(gè),避免出現(xiàn)操作文件是出現(xiàn)沖突,導(dǎo)致異常。

#調(diào)用argis接口 根據(jù)點(diǎn)查找路徑,并將路徑保存到shp文件中
import arcpy
from arcpy import env

try:
    #Check out the Network Analyst extension license
    arcpy.CheckOutExtension("Network")

    #Set environment settings  配置argis的當(dāng)前基礎(chǔ)數(shù)據(jù)的數(shù)據(jù)文件地址
    env.workspace = "C:/Documents/ArcGIS/routeana0.gdb"
        env.overwriteOutput = True
    
    #Set local variables  配置好的網(wǎng)絡(luò)數(shù)據(jù)集(NetworkDataset)位置  即基礎(chǔ)數(shù)據(jù)
    inNetworkDataset = "train/train_ND"
    #輸出的經(jīng)過點(diǎn)的圖層名稱
    outNALayerName = "StationRoute"
    impedanceAttribute = "Length"
    inAddressLocator = "train_station_copy"
    #所有經(jīng)過點(diǎn)的圖層位置
    allinFeatures = "s2sdis"
    #輸入經(jīng)過點(diǎn)數(shù)據(jù)表位置
    inAddressTable = "G:/ArcGIS/python/StopAddresses.csv"
    #輸入經(jīng)過點(diǎn)數(shù)據(jù)表 字段
    inAddressFields = "Name Name VISIBLE NONE"
    #輸出經(jīng)過點(diǎn)圖層名稱
    outStops = "GeocodedStops"
    #輸出經(jīng)過點(diǎn)圖層保存地址
    outLayerFile = "G:/ArcGIS/python" + "/" + outNALayerName + ".lyr"
    searchTolerance = "3000 Meters"
    
    #Create a new Route layer. For this scenario, the default value for all the
    #remaining parameters statisfies the analysis requirements
    outNALayer = arcpy.na.MakeRouteLayer(inNetworkDataset, outNALayerName,
                                         impedanceAttribute)
    
    #Get the layer object from the result object. The route layer can now be
    #referenced using the layer object.  得到輸出圖層集
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the route layer.
    #得到輸出圖層名稱
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later  根據(jù)名稱獲取對應(yīng)圖層
    stopsLayerName = subLayerNames["Stops"]
    routesLayerName = subLayerNames["Routes"]
    
    #需要分析多次 篩選多批次的經(jīng)過點(diǎn)  數(shù)據(jù)量大時(shí)可分批執(zhí)行
    for i in range(int(start),int(end)) :
        篩選當(dāng)前批次的經(jīng)過點(diǎn)到臨時(shí)圖層station2station0
        inFeatures = arcpy.Select_analysis(allinFeatures, "station2station0", '"sort" = '+str(i))
        
        #Load the geocoded address locations as stops mapping the address field from
        #geocoded stop features as Name property using field mappings.
        #網(wǎng)絡(luò)數(shù)據(jù)集中清除原來的點(diǎn),并加入輸出經(jīng)過點(diǎn)圖層中的點(diǎn)
        arcpy.na.AddLocations(outNALayer, stopsLayerName, inFeatures, "Name Name #",
                                  searchTolerance, append = "CLEAR",exclude_restricted_elements = "EXCLUDE")
    
        #Solve the route layer, ignore any invalid locations such as those that
        #can not be geocoded
        #執(zhí)行查找路徑方法  可能存在找不到路徑的情況 捕捉異常,不打斷循環(huán)
        try:
            result = arcpy.na.Solve(outNALayer,"SKIP")
        except Exception as e:
            # If an error occurred, print line number and error message
            import traceback, sys
            tb = sys.exc_info()[2]
            print "An error occured on line %i" % tb.tb_lineno
            # 刪除臨時(shí)圖層,避免下次創(chuàng)建圖層時(shí)出錯(cuò)
            arcpy.Delete_management("station2station0")
            print str(e)
            print str(i)
            continue
    
        # 刪除臨時(shí)圖層,避免下次創(chuàng)建圖層時(shí)出錯(cuò)
        arcpy.Delete_management("station2station0")
        #Get the polygons sublayer from the service area layer
        #獲取結(jié)果中路徑的圖層
        routes_sublayer = arcpy.mapping.ListLayers(outNALayer,
                                            routesLayerName)[0]
        #將獲得的路徑匯總到時(shí)s2s的shp中
        arcpy.Append_management([routes_sublayer], "s2s", "TEST")

    print("Script completed successfully")

except Exception as e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print ("An error occured on line %i" % tb.tb_lineno)
    print (str(e))

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

营山县| 泾川县| 鹰潭市| 桦南县| 阿拉善盟| 随州市| 琼结县| 霍山县| 多伦县| 冕宁县| 南涧| 金山区| 镇赉县| 宜良县| 定结县| 新干县| 饶河县| 绥中县| 泰顺县| 朝阳县| 米泉市| 苍梧县| 阳谷县| 池州市| 南郑县| 英德市| 康平县| 绥江县| 龙山县| 方正县| 图木舒克市| 南漳县| 乌拉特前旗| 万年县| 承德县| 遂宁市| 黄骅市| 鸡西市| 寻乌县| 嘉黎县| 阳原县|