1

I like to build a Toolbox for the ArcGIS Network Analyst that takes a network and given addresses of a shapefile to calculate the best route.

Right now I am using the network-data of the [ArcGIS Network Analyst extension tutorial][1].

I have a shapefile with 1000 addresses, but I want to limit one route at one calculation with a maximum of 6 addresses.

Do I have to extract the addresses from the shapefile first before using the "Solve"-Tool or is there a better way?

In the end, I would like create an ArcGIS-Toolbox to have the possibility to choose the addresses with a drop-down menu for various address-lists and networks.

Right now I have the output of the Model Builder, Stores are my Addresses:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Python.py
# Created on: 2017-02-16 10:11:54.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: Python <Routes> 
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Script arguments
Routes = arcpy.GetParameterAsText(0)
if Routes == '#' or not Routes:
    Routes = "Route1\\Routes" # provide a default value if unspecified

# Local variables:
Streets_ND = "F:\\Streets_ND"
Route1 = "Route1"
Route1__3_ = Route1
Pizzaladen = "Pizzaladen"
Route1__4_ = Route1__3_
Stores = "F:\\Stores"
Routes__3_ = Stores
Route__3_ = Route1__4_
Solve_Succeeded = "true"
output5_shp = "F:\\output5.shp"

# Process: Make Route Layer
arcpy.MakeRouteLayer_na(Streets_ND, "Route1", "TravelTime", "FIND_BEST_ORDER", "PRESERVE_BOTH", "USE_TIMEWINDOWS", "", "ALLOW_UTURNS", "Oneway;RestrictedTurns", "USE_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "")

# Process: Add Locations (2)
arcpy.AddLocations_na(Route1, "Stops", Pizzaladen, "", "5000 Meters", "", "Streets SHAPE;Streets_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Streets #;Streets_ND_Junctions #")

# Process: Add Locations
arcpy.AddLocations_na(Route1__3_, "Stops", Stores, "Name Name #;Attr_Minutes ServiceTime 0", "5000 Meters", "", "Streets SHAPE;Streets_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Streets #;Streets_ND_Junctions #")

# Process: Solve
arcpy.Solve_na(Route1__4_, "SKIP", "TERMINATE", "")

# Process: Select Data
arcpy.SelectData_management(Route__3_, "Routes")

# Process: Copy Features
arcpy.CopyFeatures_management(Routes, output5_shp, "", "0", "0", "0")

# Process: Select Data (2)
arcpy.SelectData_management(Stores, "Routes")

Is it possible to make a selection of 6 Stores/addresses among these Tools?

  • 4
    All geoprocessing tools honour selections so it may be as simple as having the points selected before you run the solve tool? – Hornbydd Feb 15 '17 at 15:05
  • 2
    What have you tried? Please edit your question to include detail about what you've tried, and what happens when you try it. Are you trying to create a python toolbox or script tool to do this? Include any code you've tried. – Midavalo Feb 15 '17 at 15:53
1

I was able to extract files with the Select(Analysis) tool. For the start of my route is determinded, I started my 'where_clause' (-->Expression) with a fixed address.

#Input
Addresses = arcpy.GetParameterAsText(0)
#Output
Select_shp = arcpy.GetParameterAsText(1)

Expression = "Name = 'Address_22'" + arcpy.GetParameterAsText(2) + arcpy.GetParameterAsText(3) + arcpy.GetParameterAsText(4)+ arcpy.GetParameterAsText(5)+ arcpy.GetParameterAsText(6)+ arcpy.GetParameterAsText(7)

# Process: Select
arcpy.Select_analysis(Addresses, Select_shp, Expression)

See this help topic for more information on the script tool parameters that I used in the script properties.

Now, I have a dropdown-menue to choose of the adresses I defined before and am able to extract the shapefiles as I wanted.

  • there is an even more elegant way here – GISbert Feb 22 '17 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.