Hi
thanks for the reply.
I work with shapefiles.
It looks like the expression you showed me worked well. But the output files overwrites each other. What can I do to avoid this?
Here is the Python script:
# Import system modules
import sys, string, os, arcpy
from arcpy import env
#Check out the Network Analyst extension license
arcpy.CheckOutExtension("Network")
env.workspace = r"C:\Tom\Oppdrag_2014\IPLOS"
arcpy.env.overwriteOutput = True
inNetworkDataset = r"C:\Tom\ELVEG_Nettverk_2013\ELVEG_Nettverk_2013.gdb\ELVEG_Nettverk\ELVEG_Nettverk_ND_2013"
outNALayer = "Foreldere_til_Barn"
impedanceAttribute = "Drivetime"
accumulateAttributeName = ["Minutes"]
FCForeldre = "io_1000_Shape.shp"
FCBarn = "Barn_1000_Shape.shp"
outLayerFile = r"C:\Tom\Oppdrag_2014\IPLOS" + "/" + "%outNALayer%" + ".lyr"
#Check out the Network Analyst extension license
arcpy.CheckOutExtension("Network")
rows = arcpy.SearchCursor(FCBarn)
for row in rows:
famnrNavn = row.getValue("famnr")
inDestination = "BarnLayer"
#arcpy.MakeFeatureLayer_management(FCBarn, BarnLyr)
arcpy.MakeFeatureLayer_management(FCBarn, inDestination, "famnr = '" + famnrNavn + "'")
lyrForeldere = "ForeldereLayer"
#arcpy.MakeFeatureLayer_management(FCForeldre, ForeldereLyr)
arcpy.MakeFeatureLayer_management(FCForeldre, lyrForeldere, "famnr = '" + famnrNavn + "'")
#Create a new OD Cost matrix layer.
arcpy.MakeODCostMatrixLayer_na(inNetworkDataset, outNALayer, "Minutes", "", "", "Minutes")
#Load the locations as origins.
arcpy.AddLocations_na(outNALayer, "Origins", lyrForeldere, "Name famnr #","1000 Meters", "famnr")
#Load the locations as destinations
arcpy.AddLocations_na (outNALayer, "Destinations", inDestination, "Name famnr #","1000 Meters", "famnr")
#Solve the OD cost matrix layer
arcpy.na.Solve(outNALayer,"","", "10 Meters")
#Save the solved OD cost matrix layer as a layer file on disk with relative
#paths
arcpy.SaveToLayerFile_management(outNALayer, outLayerFile,"RELATIVE")
Regards Tom Anders