ArcGIS Desktop

  • 文档
  • 支持

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

GetSolverProperties

  • 摘要
  • 说明
  • 语法
  • 代码示例

摘要

根据指定为参数的网络分析图层类型返回 Network Analyst 求解程序属性对象。求解程序属性对象被用于更新图层的分析属性。

说明

当修改网络分析图层的分析属性时,GetSolverProperties 用作主入口点。它根据网络分析图层返回单独的求解程序属性对象。有以下六种求解程序属性对象类型:RouteSolverProperties、ClosestFacilitySolverProperties、ServiceAreaSolverProperties、ODCostMatrixSolverProperties、VehicleRoutingProblemSolverProperties 和 LocationAllocationSolverProperties。每个求解程序属性对象都提供了对特定于某个网络分析图层的分析属性的读/写访问权限。

语法

GetSolverProperties (network_analyst_layer)
参数说明数据类型
network_analyst_layer

A variable that references a layer object obtained from a network analysis layer. It can be derived from existing layers in a map document or by specifying the catalog path to the network analysis layer file as an argument to the Layer class. The isNetworkAnalystLayer property on the layer object can be used to identify whether a given layer object is a network analysis layer.

Layer

返回值

数据类型说明
Object

与网络分析图层类型对应的求解程序属性对象。

代码示例

GetSolverProperties 示例

该示例显示如何使用 GetSolverProperties 访问网络分析图层的求解程序属性对象,以及如何使用该求解程序属性对象更新分析设置。

# Name: GetSolverProperties_01.py
# Description: Generate 3-minute service areas around fire stations at several
#               times of day to compare coverage differences due to varying
#               traffic conditions. Use GetSolverProperties to access the
#               Service Area layer's solver properties object, and update the
#               time of day property prior to each solve.
# Requirements: Network Analyst Extension

#Import system modules
import datetime
import arcpy
from arcpy import env

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

    #Set environment settings
    env.workspace = "C:/Data/SanFrancisco.gdb"
    env.overwriteOutput = True

    #Set local variables
    inNetworkDataset = "Transportation/Streets_ND"
    outNALayerName = "FireStationCoverage"
    outSAFC = "Analysis/outSAPolys"
    impedanceAttribute = "TravelTime"
    inFacilities = "Analysis/FireStations"
    timelist = [datetime.datetime(2013, 8, 23, 7, 0, 0),
                datetime.datetime(2013, 8, 23, 12, 30, 0),
                datetime.datetime(2013, 8, 23, 17, 30, 0),
                datetime.datetime(2013, 8, 23, 21, 0, 0)]

    #Create a new service area layer.
    outSAResultObject = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
                                  impedanceAttribute, "TRAVEL_FROM", "3",
                                  "DETAILED_POLYS", "NO_MERGE",
                                  hierarchy = "NO_HIERARCHY")

    #Get the layer object from the result object. The service area layer can
    #now be referenced using the layer object.
    outNALayer = outSAResultObject.getOutput(0)

    #Get the names of all the sublayers within the service area layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Store the layer names that we will use later
    facilitiesLayerName = subLayerNames["Facilities"]
    polygonsLayerName = subLayerNames["SAPolygons"]

    #The input data has a field for FireStationID that we want to transfer to
    #our analysis layer. Add the field, and then use field mapping to transfer
    #the values.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, facilitiesLayerName,
                                                    "FireStationID", "TEXT")
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer,
                                                    facilitiesLayerName)
    fieldMappings["FireStationID"].mappedFieldName = "FireStationID"

    #Load the fire stations as facilities.
    arcpy.na.AddLocations(outNALayer, facilitiesLayerName, inFacilities,
                            fieldMappings, "",
                            exclude_restricted_elements = "EXCLUDE")

    #Get sublayers we will want to work with later
    FacilitiesSubLayer = arcpy.mapping.ListLayers(outNALayer,
                                                    facilitiesLayerName)[0]
    PolygonsSubLayer = arcpy.mapping.ListLayers(outNALayer,
                                                    polygonsLayerName)[0]

    # Add fields to the output Polygons sublayer. We will fill the values later.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, polygonsLayerName,
                                        "FireStationID", "TEXT")
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, polygonsLayerName,
                                        "TimeOfDay", "TEXT")

    #Get the Service Area Layer's solver properties. This will allow us to
    #set individual properties later without re-creating the layer.
    SA_SolverProperties = arcpy.na.GetSolverProperties(outNALayer)

    #Solve the Service Area for each time of day in our time list
    for t in timelist:

        print "Now solving for time of day: " + t

        #Use the solver properties to set the time of day for the solve
        SA_SolverProperties.timeOfDay = t

        #Solve the service area layer
        arcpy.na.Solve(outNALayer)

        #Transfer the FireStationID field from the input Facilities to the
        #output Polygons
        arcpy.management.AddJoin(PolygonsSubLayer, "FacilityID",
                                        FacilitiesSubLayer, "ObjectID")
        arcpy.management.CalculateField(PolygonsSubLayer, "FireStationID",
                                        "!Facilities.FireStationID!", "PYTHON")
        arcpy.management.RemoveJoin(PolygonsSubLayer)

        #Populate the TimeOfDay field
        expression = '"' + t + '"'
        arcpy.management.CalculateField(PolygonsSubLayer, "TimeOfDay",
                                            expression, "PYTHON")

        #Append the polygons to the output feature class. If this was the first
        #solve, create the feature class.
        if not arcpy.Exists(outSAFC):
            arcpy.management.CopyFeatures(PolygonsSubLayer, outSAFC)
        else:
            arcpy.management.Append(PolygonsSubLayer, outSAFC)

    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)

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • 内部人员博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
© Copyright 2016 Environmental Systems Research Institute, Inc. | 隐私政策 | 法律声明