Synthèse
An ArcPy class for performing a service area analysis.
Discussion
A service area analysis allows you to calculate the area reachable from one or more facilities within a designated time or distance limit.
Syntaxe
ServiceArea (in_network)
Paramètre | Explication | Type de données |
in_network | The network dataset or service that will be used for the network analysis. The argument can be specified using the catalog path to the network dataset, a network dataset layer object, the string name of the network dataset layer, or a portal URL for a network analysis service. The network must have at least one travel mode. To use a portal URL, you must be signed in to the portal with an account that has routing privileges. Solving an analysis will consume credits when the object uses ArcGIS Online as the in_network. For more information, see Service Credits Overview | String |
Propriétés
Propriété | Explication | Type de données |
accumulateAttributeNames (Lecture et écriture) | A list of cost attributes to be accumulated during analysis. These accumulated attributes are for reference only; the solver only uses the cost attribute used by your designated travel mode when solving the analysis. The default is an empty list. | String |
allowAutoRelocate (Lecture et écriture) | Specifies whether inputs with existing network location fields can be automatically relocated at solve time to ensure valid, routable location fields for the analysis. If the value is True, points located on restricted network elements and points affected by barriers will be relocated to the closest routable location. If the value is False, network location fields will be used as is, even if the points are unreachable, and this may cause the solve to fail. Even if the value is False, inputs with no location fields or incomplete location fields will be located at solve time. The default is True. This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method. Learn more about network location fields and how inputs are located on the network Setting this property returns an error if the network data source is ArcGIS Online, an ArcGIS Enterprise portal that does not support using network location fields, or a portal running a version of ArcGIS Enterprise older than 11.0. | Boolean |
allowSaveLayerFile (Lecture et écriture) | Specifies whether to permit saving the analysis result as a layer file using the saveAsLayerFile method on the result object. A value of True indicates that you can save a layer file. A value of False indicates that you cannot save a layer file. The default is True if the analysis references a network dataset and False if it references a portal service. Saving a layer file may slow down the analysis when the analysis references a portal service. | Boolean |
defaultImpedanceCutoffs (Lecture et écriture) | The extent of the service area to be calculated. The service area output shows the area reachable from the starting facility within this impedance cutoff. The default is an empty list, but at least one cutoff must be specified prior to solving the service area. If the travel mode used in the analysis uses a time-based impedance attribute, the defaultImpedanceCutoffs values are interpreted in the units specified in the timeUnits property. If the travel mode used in the analysis uses a distance-based impedance attribute, the defaultImpedanceCutoffs values are interpreted in the units specified in the distanceUnits property. If the travel mode's impedance attribute is neither time based nor distance based, the defaultImpedanceCutoffs values are interpreted in the units of the impedance attribute. The default is [5, 10, 15]. The values can be overridden on a per-facility basis by specifying individual cutoff values in the Facilities input data type. The defaultImpedanceCutoffs can be overridden on a per-facility basis using the Breaks field in the input facilities. | Double |
distanceUnits (Lecture et écriture) | The units to use when reporting the travel distance in the analysis output. Regardless of the units of the cost attributes in the network dataset, the output will be transformed to and reported in the units set in this property. The property is returned and set as a member of the DistanceUnits enumeration. The default is DistanceUnits.Kilometers. | Object |
excludeSourcesFromPolygonGeneration (Lecture et écriture) | The list of network dataset edge sources exclude when generating polygons. Learn more about excluding edge sources from service area polygon generation. The property is returned and set as a list of strings where each list item is the name of the network edge source. The default is an empty list, which means that no edge sources are excluded from polygon generation. | String |
geometryAtCutoff (Lecture et écriture) | Controls the behavior of the output polygons for a single facility when multiple values are specified in the defaultImpedanceCutoffs property. The property is returned and set as a member of the ServiceAreaPolygonCutoffGeometry enumeration. The default is ServiceAreaPolygonCutoffGeometry.Rings. | Object |
geometryAtOverlap (Lecture et écriture) | Controls the behavior of the service area output from multiple facilities in relation to one another. The property is returned and set as a member of the ServiceAreaOverlapGeometry enumeration. The default is ServiceAreaOverlapGeometry.Overlap. | Object |
ignoreInvalidLocations (Lecture et écriture) | Specifies whether invalid input locations will be ignored. A value of True indicates that invalid input locations will be ignored so that the analysis will succeed using only valid locations. A value of False indicates that invalid locations will not be ignored and will cause the analysis to fail. Héritage :Routing services based on portals running versions of ArcGIS Enterprise older than 10.9 always ignore invalid input locations. The method returns a ValueError exception if you set ignoreInvalidLocations to False and the service does not support this option. | Boolean |
networkDataSource (Lecture seule) | The full catalog path to the network dataset used for the analysis. | String |
outputType (Lecture et écriture) | The type of output to be generated for the analysis. Choose whether to generate polygons, lines, or both. The property is returned and set as a member of the ServiceAreaOutputType enumeration. The default is ServiceAreaOutputType.Polygons. | Object |
overrides (Lecture et écriture) | Remarque :This property is for internal use only. | String |
polygonBufferDistance (Lecture et écriture) | Distance de découpage des polygones de la zone de desserte. La distance de découpage des polygones correspond à la distance d’extension du polygone de la zone de desserte à partir de la route, lorsqu’aucune autre route accessible ne se trouve à proximité. Elle fonctionne de la même manière qu’une taille de zone tampon de lignes. Cette option est utile lorsque le réseau est clairsemé et que vous ne voulez pas que la zone de desserte couvre de larges surfaces sur lesquelles il n’y a aucune entité. The units for the buffer distance value are specified in the polygonBufferDistanceUnits property. The default is 100. | Double |
polygonBufferDistanceUnits (Lecture et écriture) | The units for the polygonBufferDistance property. The property is returned and set as a member of the DistanceUnits enumeration. The default is DistanceUnits.Meters. | Object |
polygonDetail (Lecture et écriture) | Specifies the desired level of detail for the output polygons. Learn more about polygon detail level. The property is returned and set as a member of the ServiceAreaPolygonDetail enumeration. The default is ServiceAreaPolygonDetail.Standard. | Object |
searchQuery (Lecture et écriture) | Héritage :This property has been superseded by the searchSources property, which was introduced at ArcGIS Pro 3.0. The searchQuery property continues to work to maintain backward compatibility with existing scripts, but it is recommended that new scripts use the searchSources property instead.When locating inputs on the network, specifies a query to restrict the search to a subset of the features within a source feature class. This is useful if you don't want to find features that may be unsuited for a network location. For example, if you don't want to locate on highway ramps, you can define a query to exclude them. The parameter value is specified as a list with nested lists, with one entry per network source. Each inner list is composed of two values indicating the name of the network source and the SQL expression used as the query for that source. An empty string, "", indicates no query for a particular source. For example, the value [["Streets", "ROAD_CLASS <> 3"], ["Streets_ND_Junctions", ""]] specifies an SQL expression for the Streets source feature class and no expression for the Streets_ND_Junctions source feature class. If a network source is not included in the list, it is interpreted to have no query. The value [["Streets", "ROAD_CLASS <> 3"]] is equivalent to [["Streets", "ROAD_CLASS <> 3"], ["Streets_ND_Junctions", ""]]. By default, no query is used for any source. Learn more about locating inputs on the network For more information on SQL syntax, see SQL reference for query expressions used in ArcGIS. Setting this property returns an error if the network data source is ArcGIS Online or a portal running a version of ArcGIS Enterprise older than 11.0. | List |
searchSources (Lecture et écriture) | When locating inputs on the network, specifies the list of network sources to be used, and, optionally, a query to restrict the search to a subset of the features within a source feature class. The default value is to locate on all network sources except system junctions and override junctions created by running the Dissolve Network tool. By default, no query is used for any source. The parameter value is specified as a list with nested lists, with at most one entry per network source. Each inner list is composed of two values indicating the name of the network source and the SQL expression used as the query for that source. Possible values for the network source component are the string feature class names of edge and junction sources that participate in the network. Sources in the list will be used for locating, and sources not in the list will not. Queries are useful if you don't want to find features that may be unsuited for a network location. For example, if you don't want to locate on highway ramps, you can define a query to exclude them. For the query component, see SQL reference for query expressions used in ArcGIS for correct syntax. An empty string, "", indicates no query for a particular source. For example, the value [["Streets", "ROAD_CLASS <> 3"], ["Streets_ND_Junctions", ""]] specifies that inputs can be located on both the Streets and Streets_ND_Junctions sources. A SQL expression for the Streets source feature class forbids inputs from locating on streets where the ROAD_CLASS field has a value of 3. No query is used for the Streets_ND_Junctions source feature class. A value of [["Streets", "ROAD_CLASS <> 3"]] indicates that only the Streets source feature class should be used for locating, and Streets_ND_Junctions should not. Additionally, a query is applied to Streets. This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method. Learn more about locating inputs on the network Setting this property returns an error if the network data source is ArcGIS Online or a portal running a version of ArcGIS Enterprise older than 11.0. | String |
searchTolerance (Lecture et écriture) | The maximum search distance to use when locating the input features on the network. The property is returned and set as a double, and the units of this value are accessed through the searchToleranceUnits property. The default is 5000. This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method. Learn more about locating inputs on the network Héritage :Setting this property returns an error if the network data source is a portal running a version of ArcGIS Enterprise older than 11.0. | Double |
searchToleranceUnits (Lecture et écriture) | The units of the searchTolerance property. The property is returned and set as a member of the DistanceUnits enumeration. The default is DistanceUnits.Meters. This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method. Héritage :Setting this property returns an error if the network data source is a portal running a version of ArcGIS Enterprise older than 11.0. | Object |
timeOfDay (Lecture et écriture) | The date and time of day to use for the analysis. The property is specified using a datetime object. For example, to specify that travel should begin at 5:00 p.m. on March 29, 2022, specify the parameter value as datetime.datetime(2022, 3, 29, 17, 0, 0). Instead of using a particular date, a day of the week can be specified using the following dates:
For example, to specify that travel should begin at 5:00 p.m. on Tuesday, specify the parameter value as datetime.datetime(1900, 1, 2, 17, 0, 0). The default is None, which indicates that the analysis will be time neutral. The property will have no impact if the analysis' travel mode's impedance attribute has no time-dependent properties, such as traffic or public transit. | DateTime |
timeUnits (Lecture et écriture) | The units to use when reporting the travel time in the analysis output. Regardless of the units of the cost attributes in the network dataset, the outputs will be transformed to and reported in the units set in this property. The property is returned and set as a member of the TimeUnits enumeration. The default is TimeUnits.Minutes. | Object |
timeZone (Lecture et écriture) | Indicates whether the time specified in the timeOfDay property will be interpreted as the local time at the input locations or as coordinated universal time (UTC). The property is returned and set as a member of the TimeZoneUsage enumeration and is applicable only when the timeOfDay property is not None. The default is TimeZoneUsage.LocalTimeAtLocations. | Object |
travelDirection (Lecture et écriture) | The direction of travel with respect to the facilities. The property is returned and set as a member of the TravelDirection enumeration. The default is TravelDirection.FromFacility. If the travel direction is TravelDirection.FromFacility, the timeOfDay is interpreted to mean the departure time from the facility. If the travel direction is TravelDirection.ToFacility, the timeOfDay is interpreted to mean the arrival time at the facility. | Object |
travelMode (Lecture et écriture) | The travel mode to use for the analysis. The value is returned and set as an arcpy.nax.TravelMode object, but it can also be set using the string name of the travel mode or a string containing the valid JSON representation of a travel mode. The default is the default travel mode defined on the network dataset used for the analysis. | Object |
Vue d’ensemble des méthodes
Méthode | Explication |
addFields (input_type, field_description) | Adds custom fields to the designated input class. These fields will be included in the field mapping dictionary created by the fieldMappings method and will also be available for use with the insertCursor method. |
count (input_type) |
Returns the number of rows added for an input type. |
fieldMappings (input_type, {use_location_fields}, {list_candidate_fields}) | Generates an NAClassFieldMappings dictionary that maps the field names of the input type to arcpy.nax.NAClassFieldMap objects that allow you to map fields from your input data to the properties of the solver. The dictionary can be used as input to the load method's field_mappings argument. |
fieldNames (input_type, {use_location_fields}) | Get a list of field names supported by the specified input type. |
insertCursor (input_type, field_names, {append}) | Establishes a write cursor on the specified input type. This cursor can be used to add rows directly to the input. |
load (input_type, features, {field_mappings}, {append}, {max_features}) | Set input features to use for the analysis. |
setLocateSettingsOverrides (input_type, {search_sources}, {allow_auto_relocate}, {search_tolerance}, {search_tolerance_units}) | Set locate settings for a designated input class, overriding the default locate settings specified for the analysis. This is useful if you want to use different rules to locate different inputs. For example, in an OD cost matrix analysis, you can use a search query that applies to the input origins only, if that query should not apply to the input destinations and barriers. Using this method, you can override the values of the searchSources, allowAutoRelocate, searchTolerance, and searchToleranceUnits properties for the designated input class. |
solve () | Perform the service area analysis using the properties set on the ServiceArea object and the loaded inputs. |
Méthodes
addFields (input_type, field_description)
Paramètre | Explication | Type de données |
input_type |
The type of input to which the fields should be added. The parameter should be set using the ServiceAreaInputDataType enumeration. | Object |
field_description [field_description,...] |
The fields and their properties that will be added to the input class. The value should be constructed as a list of lists with each row containing the following items:
Available field types are as follows:
The method will return an error if the field already exists in the table or if any of the field properties are invalid. | List |
count (input_type)
Paramètre | Explication | Type de données |
input_type | The type of input features to count. The parameter should be set using the ServiceAreaInputDataType enumeration. | Object |
Type de données | Explication |
Integer | The number of rows. |
fieldMappings (input_type, {use_location_fields}, {list_candidate_fields})
Paramètre | Explication | Type de données |
input_type | The type of input for which the field mappings are returned. The parameter should be set using the ServiceAreaInputDataType enumeration. See descriptions of the fields available for each input type | Object |
use_location_fields | Indicates whether network location fields should be included in the returned field mappings dictionary. Network location fields describe the point on the network where an object is located. You can use network location fields to more precisely control how your analysis inputs locate on the network and to save time when calling the solve method because the solver will not have to calculate the location fields from the geometry of the inputs. You can calculate location fields for a feature class using the Calculate Locations tool. Learn more about network location fields and how inputs are located on the network When this argument is set to True, the returned field mappings dictionary will contain network location fields. The default is False; the field mapping dictionary will not include network location fields. (La valeur par défaut est False) | Boolean |
list_candidate_fields [list_candidate_fields,...] | Use this parameter to map additional, non-default fields from your input data into your analysis inputs. For example, if your input feature class contains a field named MyField, and you want this field to be included in your analysis inputs, pass the MyField field object to the list_candidate_fields parameter. MyField will be included in the returned field mapping dictionary and automatically mapped. When you call the load method using these field mappings, MyField will be included in the analysis inputs along with all the default fields. In many cases, these extra fields will be passed to the analysis output as well. The parameter should be specified as a list of arcpy.Field objects, which can be obtained from a given feature class or table using the arcpy.ListFields function. Learn more about best practices for setting up analysis inputs (La valeur par défaut est None) | Field |
Type de données | Explication |
Dictionary | An NAClassFieldMappings dictionary in which the keys are the field names and values are arcpy.nax.NAClassFieldMap objects. |
fieldNames (input_type, {use_location_fields})
Paramètre | Explication | Type de données |
input_type | The type of input for which the supported field names are returned. The parameter should be set using the ServiceAreaInputDataType enumeration. See descriptions of the fields available for each input type | Object |
use_location_fields | Indicates whether network location fields will be included in the returned list of field names. Network location fields describe the point on the network where an object is located. You can use network location fields to more precisely control how your analysis inputs locate on the network and to save time when calling the solve method because the solver will not have to calculate the location fields from the geometry of the inputs. You can calculate location fields for a feature class using the Calculate Locations tool. Learn more about network location fields and how inputs are located on the network When this argument is set to True, the returned list of field names will contain network location fields. The default is False; the list of field names will not include network location fields. (La valeur par défaut est False) | Boolean |
Type de données | Explication |
String | A list of field names supported by the specified input type. |
insertCursor (input_type, field_names, {append})
Paramètre | Explication | Type de données |
input_type | The type of input into which the cursor can be used to insert rows. The parameter should be set using the ServiceAreaInputDataType enumeration. | Object |
field_names [field_names,...] | A list of field names of the input type whose values you want to set when inserting rows using the cursor. You can get the names of the fields supported by an input type by using the fieldNames method. See descriptions of the fields available for each input type In addition to regular fields, you can also set the geometry of the input using one of the following geometry tokens:
The SHAPE@XY and SHAPE@XYZ tokens are only supported for point-based input types. When using the SHAPE@XY and SHAPE@XYZ tokens, the x-, y-, and z-values should be specified in the spatial reference of the network data source being used in the analysis. | String |
append | Specifies whether the features being inserted should be appended to the existing set of features for the input type. A value of True indicates that the new features should be appended; the existing features will be preserved. This is the default. A value of False indicates that any existing features for the input type should be deleted and replaced with the features currently being inserted. (La valeur par défaut est True) | Boolean |
Type de données | Explication |
Object | A SolverInsertCursor object that can be used to write features. |
load (input_type, features, {field_mappings}, {append}, {max_features})
Paramètre | Explication | Type de données |
input_type | The type of input feature to load. The parameter should be set using the ServiceAreaInputDataType enumeration. | Object |
features | The input features to load. This parameter accepts the following input types:
For layer inputs, only selected features will be loaded. If a layer has a definition query, only the subset of features visible with the definition query will be loaded. The method also honors the Extent geoprocessing environment; only features in the specified extent will be loaded. | String |
field_mappings | An NAClassFieldMappings dictionary that maps the field names of the input type to arcpy.nax.NAClassFieldMap objects representing the mapping of fields from the input features. Valid input for this parameter can be constructed using the fieldMappings method. If field mappings are not specified, all fields from the input features that have the same name as the supported fields for the input type will be mapped. (La valeur par défaut est None) | Dictionary |
append | Indicates whether the features being loaded should be appended to the existing set of features for the input type. A value of True indicates that the new features should be appended; the existing features will be preserved. This is useful if you want to load inputs from multiple feature classes or tables to use in a single analysis. This is the default. A value of False indicates that any existing features for the input type should be deleted and replaced with the features currently being loaded. (La valeur par défaut est True) | Boolean |
max_features | The maximum number of features that can be loaded into the input type. This is useful if you are creating a tool or service and want an error returned if the size of the input exceeds the available resources. The load method will return an arcpy.nax.LimitError if the number of input features exceeds the max_features limit. If a value is not specified, no limit is enforced for the count of the input features. (La valeur par défaut est None) | Integer |
setLocateSettingsOverrides (input_type, {search_sources}, {allow_auto_relocate}, {search_tolerance}, {search_tolerance_units})
Paramètre | Explication | Type de données |
input_type | The type of input for which to override default locate settings. The parameter should be set using the ServiceAreaInputDataType enumeration. | Object |
search_sources [[Source, Expression],...] | The list of network sources to be used when locating inputs of the designated type on the network, and, optionally, a query to restrict the search to a subset of the features within a source feature class. See the documentation for the searchSources property for examples of proper syntax for this parameter. Specifying a value for this parameter overrides the default searchSources property value for the designated input type. If this parameter is not specified or is set to None, the searchSources value will be used for this input type. The method returns an error if this parameter is used and the network data source is ArcGIS Online. | String |
allow_auto_relocate | Specifies whether inputs of the designated type with existing network location fields can be automatically relocated at solve time to ensure valid, routable location fields for the analysis. If the value is True, points located on restricted network elements and points affected by barriers will be relocated to the closest routable location. If the value is False, network location fields will be used as is, even if the points are unreachable, and this may cause the solve to fail. Even if the value is False, inputs with no location fields or incomplete location fields will be located at solve time. Specifying a value for this parameter overrides the default allowAutoRelocate property value for the designated input type. If this parameter is not specified or is set to None, the allowAutoRelocate value will be used for this input type. The method returns an error if the network data source is ArcGIS Online. The method returns an error if the network data source is an ArcGIS Enterprise portal that does not support using network location fields. | Boolean |
search_tolerance | The maximum search distance to use when locating inputs of the designated type on the network. Specifying a value for this parameter overrides the default searchTolerance property value for the designated input type. If this parameter is not specified or is set to None, the searchTolerance value will be used for this input type. The units of this parameter value are set using the search_tolerance_units parameter; however, if no value is set for that parameter, the search_tolerance value will be interpreted in the units specified in the searchToleranceUnits property. This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the input_type value is one of these barrier types. | Double |
search_tolerance_units | The units of the maximum search distance when locating inputs of the designated type of the network. The parameter is specified using a member of the DistanceUnits enumeration. Specifying a value for this parameter overrides the default searchToleranceUnits property value for the designated input type. If this parameter is not specified or is set to None, the searchToleranceUnits will be used for this input type. The value specified using the search_tolerance parameter is interpreted using these units. If that parameter is not specified, the value of the searchTolerance property will be interpreted using these units for the designated input type only. This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the input_type value is one of these barrier types. | Double |
solve ()
Type de données | Explication |
Object | An arcpy.nax.ServiceAreaResult object that can be used to access outputs and solver messages. |
Exemple de code
Perform service area analysis.
# An example showing how to perform service area analysis using a feature class for input facilities.
import arcpy
arcpy.CheckOutExtension("network")
nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_facilities = "C:/data/io.gdb/Facilities"
output_polygons = "C:/data/io.gdb/ServiceAreaPolygons"
# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Driving Time"]
# Instantiate a ServiceArea solver object
service_area = arcpy.nax.ServiceArea(nd_layer_name)
# Set properties
service_area.timeUnits = arcpy.nax.TimeUnits.Minutes
service_area.defaultImpedanceCutoffs = [5, 10, 15]
service_area.travelMode = travel_mode
service_area.outputType = arcpy.nax.ServiceAreaOutputType.Polygons
service_area.geometryAtOverlap = arcpy.nax.ServiceAreaOverlapGeometry.Split
# Load inputs
service_area.load(arcpy.nax.ServiceAreaInputDataType.Facilities, input_facilities)
# Solve the analysis
result = service_area.solve()
# Export the results to a feature class
if result.solveSucceeded:
result.export(arcpy.nax.ServiceAreaOutputDataType.Polygons, output_polygons)
else:
print("Solve failed")
print(result.solverMessages(arcpy.nax.MessageSeverity.All))
Vous avez un commentaire à formuler concernant cette rubrique ?