OD Cost Matrix Different results between ArcMap and Python

2812
16
09-24-2015 06:07 AM
Highlighted
Occasional Contributor

Hi,

I am working on automating OD cost matrix runs and am trying to figure out why running the data in arcpy gives a significantly different result then when run in arcmap. I have checked every setting (i believe) and they all seem to be the same.  It uses the same network and the same origins and destinations.

At first i thought it might have been a projection issue and i have tested the runs with everything in the same projection and still the results are different.

Does anyone have any idea on why this would be?

Thanks,

Matt

Tags (2)
Reply
0 Kudos
16 Replies
Highlighted
Regular Contributor II

Would you be able to upload a small sample of your data, a map document with your solved od cost matrix layer,  and script that I can use to take a closer look at this?

Reply
0 Kudos
Highlighted
Occasional Contributor

I am sorry but I can't for this data.  The only other variable i can think if is the data is being run is a query layer.

Reply
0 Kudos
Highlighted
Regular Contributor II

I would assume that there is something different between your solver in ArcMap and your solver in your standalone python application. I would suggest running your standalone code in the python window of a new blank session of ArcMap so that you can verify the data in the same environment.

Reply
0 Kudos
Highlighted
Occasional Contributor

I have never done python in the python window.  Would what you are suggesting just be a copy paste and run?

Thanks,
Matt

Reply
0 Kudos
Highlighted
Occasional Contributor

HI Freddie,

I did as you suggested and ran the script standalone, in the python window and in arcmap and it seems it may not be the solver.  ArcMap loads and finds a few more destinations then when the loading happens in python.

Thanks,

Matt

Reply
0 Kudos
Highlighted
Esri Regular Contributor

I'm guessing that the problem is most likely one of the following:

- In your python code, when you run arcpy.na.MakeODCostMatrixLayer(), you aren't feeding it exactly the same parameters as the layer you have in ArcMap (where many of the parameters are set to defaults).  So maybe you have a different impedance attribute, or some restrictions are toggled differently.

- When you add your origins and destinations, maybe the field mapping isn't working the same as it is in ArcMap.  In ArcMap, it's super easy to use the field mapping control on the Load Locations dialog.  In python, you need to use either a correctly formatted text string or an arcpy.na.NAClassFieldMappings() object.

I know you can't upload your data, but can you upload a snippet of your python code?  Otherwise, it's virtually impossible to diagnose this problem.

Reply
0 Kudos
Highlighted
Occasional Contributor

Hi Melinda,

here is the make OD cost matrix code -

/****************************/

    #Sets the location of the network dataset and the name of the OD Cost Matrix

    inNetworkDataset = "Drive:\NetworkAnalysisTesting\Network_w_Time_NAD83.gdb\Updated_LenMin_ND\Streets_Updated_LenMin_ND_ND"

    outNALayerName = "OD_Cost_Matrix"

    impedanceAttribute = "Length_Miles_Recalc"

    searchTolerance = "5000 Meters"

    odOrigins = "Origins"

    #Create a new OD cost matrix analysis layer. For this scenario, the default

    #value for all the remaining parameters satisfies the analysis requirements

    print "I am about to make an OD Layer"

    outNALayer = arcpy.na.MakeODCostMatrixLayer(inNetworkDataset, outNALayerName,

                                   impedanceAttribute,"",3,"Length_Miles_Recalc;Minutes_recalc","ALLOW_UTURNS","Oneway")

here is the load locations code

/*******************************************/

            #Load origins as destinations    

            print "I am about to load the destinations - " + inDestinationName

            arcpy.na.AddLocations(outNALayer,destinationsLayerName,inDestinationFeatures,"Name UniqueRecordID #", searchTolerance,"UniqueRecordID","Streets_Updated_LenMin SHAPE;Streets_Updated_LenMin_ND_ND_Junctions NONE","MATCH_TO_CLOSEST","CLEAR","NO_SNAP","#","INCLUDE")

            print "Load Destinations complete"

           

            #Load origins

            print "I am about to load the Origins - " + inOriginName

            arcpy.na.AddLocations(outNALayer,originsLayerName,inOriginFeatures,"Name UniqueID #",searchTolerance,"UniqueID","Streets_Updated_LenMin SHAPE;Streets_Updated_LenMin_ND_ND_Junctions NONE","MATCH_TO_CLOSEST","CLEAR","NO_SNAP","#","INCLUDE")

            print "Load Origins complete"

   

Thanks,

Matt

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hmm, well, none of that looks problematic.

Can you describe the differences you're seeing between the python results and ArcMap?  Is one showing considerably longer distances than the other, or are the results just different all over the place?  Are the results in ArcMap identical each time you run Solve in ArcMap, and are the results in python identical every time you run Solve in python?

Reply
0 Kudos
Highlighted
Occasional Contributor

Melinda,

At the end of the process i split the name at the dash and join up other data based on the ID.  Then I take the first destination and find all records that were within 5, 15 miles and 12 and 35 minutes and get a count.  These counts are different between python and ArcMap.  If i input the same origins and destinations i would expect that the distances returned would be the same.

Yes i get the same answer with different runs in python using the same data. I haven't checked this in ArcMap but based on past runs i believe i do.

Also not sure if you caught that i wrote when i load the data in python there are some records that are not located on the network but when i load them in arcmap they are located.  This leads me to lean towards there being something with the add locations but i am not sure.

Thanks,

Matt

Reply
0 Kudos