ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Add Field to Analysis Layer

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Adds a field to a sublayer of a network analysis layer.

Usage

  • The tool is mostly used along with the Add Locations tool to transfer fields from the input features to the sublayers. For example, if you want to transfer a field called UniqueID from your input features into the Facilities sublayer of the Service Area layer, use this tool to first add the UniqueID field to the Facilities sublayer, and then use the field mappings in the Add Locations tool to provide input values for the UniqueID field.

  • Fields can be added to any of the sublayers of the network analysis layers.

Syntax

arcpy.na.AddFieldToAnalysisLayer(in_network_analysis_layer, sub_layer, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable})
ParameterExplanationData Type
in_network_analysis_layer

The network analysis layer to which the new field will be added.

Network Analyst Layer
sub_layer

The sublayer of the network analysis layer to which the new field will be added.

String
field_name

The name of the field that will be added to the specified sublayer of the network analysis layer.

String
field_type

The field type used in the creation of the new field.

  • LONG — Whole numbers between -2,147,483,648 and 2,147,483,647.
  • TEXT —Any string of characters.
  • FLOAT — Fractional numbers between -3.4E38 and 1.2E38.
  • DOUBLE — Fractional numbers between -2.2E308 and 1.8E308.
  • SHORT — Whole numbers between -32,768 and 32,767.
  • DATE —Date and/or time.
  • BLOB —Long sequence of binary numbers. You need a custom loader or viewer or a third-party application to load items into a BLOB field or view the contents of a BLOB field.
String
field_precision
(Optional)

The number of digits that can be stored in the field. All digits are counted regardless of which side of the decimal they are on.

The parameter value is only valid for numeric field types.

Long
field_scale
(Optional)

The number of decimal places stored in a field. This parameter is only used in float and double data field types.

Long
field_length
(Optional)

The length of the field being added. This sets the maximum number of allowable characters for each record of the field. This parameter is only applicable to fields of type text.

Long
field_alias
(Optional)

The alternate name given to the field name. This name is used to describe cryptic field names. This parameter only applies to geodatabases.

String
field_is_nullable
(Optional)

Specifies whether the field can contain null values. Null values are different from zero or empty fields and are only supported for fields in a geodatabase.

  • NON_NULLABLE —The field will not allow null values.
  • NULLABLE —The field will allow null values. This is the default.
Boolean

Derived Output

NameExplanationData Type
output_layer

The updated network analysis layer.

Network Analyst Layer

Code sample

AddFieldToAnalysisLayer example 1 (Python window)

The following Python window script demonstrates how to add a UniqueID field to the Facilities sublayer of the Service Area network analysis layer.

arcpy.na.AddFieldToAnalysisLayer("Service Area", "Facilities", "UniqueID",
                                    "LONG")
AddFieldToAnalysisLayer example 2 (workflow)

The following stand-alone Python script demonstrates how the AddFieldToAnalysisLayer function can be used to transfer the StationID field from the input fire station features to the 2-, 3-, and 5-minute service area polygon features calculated from a service area analysis. The StationID field can be used to join other attributes from the fire station features to the service area polygon features.

# Name: AddFieldToAnalysisLayer_Workflow.py
# Description: Transfers the Address field from the input fire station 
#              features to the 2-,3-, and 5-minute service area polygon features
#              calculated from a service area analysis. The Address field can 
#              be used to join other attributes from the fire station features 
#              to the service area polygon features.
# Requirements: Network Analyst Extension 

#Import system modules
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 = "FireStationsCoverage"
    impedanceAttribute = "TravelTime"
    defaultBreakValues = "2 3 5"   
    fieldName = "Address"
    fieldType = "TEXT"
    inFeatures = "Analysis/FireStations"
    searchTolerance = "2 Miles"
    outFeatures = outNALayerName + "Area"
    saFacilities = "Facilities"
    saPolygons = "SAPolygons"
    
    #Create a new service area analysis layer. For this scenario, the default 
    #value for all the remaining parameters statisfies the analysis requirements
    outNALayer = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
                                               impedanceAttribute,"",
                                               defaultBreakValues)
    
    #Get the layer object from the result object. The service layer can now be
    #referenced using the layer object.
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the service area layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    facilitiesLayerName = subLayerNames[saFacilities]
    polygonLayerName = subLayerNames[saPolygons]
    
    #Get the layer objects for all the sublayers within the service area layer
    #The first layer returned by ListLayers is the Service area layer itself
    #which we don't want to use.
    subLayers = {}
    for layer in arcpy.mapping.ListLayers(outNALayer)[1:]:
        subLayers[layer.datasetName] = layer
    #Store the layer objects that we will use later
    facilitiesLayer = subLayers[saFacilities]
    polygonLayer = subLayers[saPolygons]
    
    #Add a Address field to the Facilities sublayer of the service area layer.
    #This is done before loading the fire stations as facilities so that the 
    #Address values can be transferred from the input features to the 
    #Facilities sublayer. The service area layer created previously is 
    #referred by the layer object.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer,facilitiesLayerName,fieldName,
                                     fieldType)
    
    #Add the fire station features as Facilities and map the Name and the 
    #Address properties from the Name and Address fields from fire station
    #features using the field mappings.
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, facilitiesLayerName)
    fieldMappings['Name'].mappedFieldName = "Name"
    fieldMappings['Address'].mappedFieldName = "Address"
    arcpy.na.AddLocations(outNALayer,facilitiesLayerName,inFeatures,
                          fieldMappings, searchTolerance)
    
    #Solve the service area layer
    arcpy.na.Solve(outNALayer)
    
    #Transfer the Address field from Facilities sublayer to Polygons sublayer 
    #of the service area layer since we wish to export the polygons. The 
    #FacilityID field in Polygons sub layer is related to the ObjectID field in
    #the Facilities sub layer. 
    arcpy.management.JoinField(polygonLayer, "FacilityID",facilitiesLayer,
                               "ObjectID", fieldName)
    
    #Export the Polygons sublayer to a feature class on disk.
    arcpy.management.CopyFeatures(polygonLayer, outFeatures)
    
    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 occurred on line %i" % tb.tb_lineno
    print str(e)

Environments

  • Current Workspace

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics

  • An overview of the Analysis toolset

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal