OD Cost Matrix Different results between ArcMap and Python

3730
16
09-24-2015 06:07 AM
MatthewCieri
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)
0 Kudos
16 Replies
MelindaMorang
Esri Regular Contributor

What you just said in your last paragraph above sounds very suspicious to me, so I'm inclined to agree that it sounds like an Add Locations problem.

Maybe it's a search_criteria syntax problem.

Your input: "Streets_Updated_LenMin SHAPE;Streets_Updated_LenMin_ND_ND_Junctions NONE"

I would have thought that syntax would be okay (because often the semi-colon-separated strings are interpreted the same way as lists in arcpy), although the doc tells you to enter it in as a list of lists.

Doc: [["Streets_Updated_LenMin","SHAPE"], ["Streets_Updated_LenMin_ND_ND_Junctions","NONE"]]

Maybe try that?

Also, are you sure that "Streets_Updated_LenMin_ND_ND_Junctions" is actually the name of your junction source, or is that a typo?

Finally, when using search_criteria in Add Locations, you have to put something for all your network dataset sources.  It's unclear what the behavior is if you have, for instance, multiple edge sources, but you only specify the behavior of one of them.  So, are all your network dataset source feature classes accounted for in the search_criteria above?  If not, put something for all of them, and see if that helps.

0 Kudos
MatthewCieri
Occasional Contributor

Melinda,

I will look into the syntax but that is the syntax that gets exported from model builder.  If I am doing something with many options i will sometimes create a sample in modelbuilder to see what the syntax should be.

I think I may have found the issue and I think it has to do with the query layers as my inputs. I exported my data as file geodatabase feature classes and ran them through both arcmap and my python code and I got the same result.  I want to try and perform this on my full datasets to confirm my results.

If this really is the case that query layers are causing the problem then this is going to add a bunch of processing time to my project.

Any thoughts on why query layers would cause a problem. They visually look good and perform pretty well in arcmap.

Thank you so much for looking into this with me.

Thanks,
Matt

0 Kudos
MelindaMorang
Esri Regular Contributor

Not sure what tool/syntax you're using for your layer query.  Can you post another python code snippet?

0 Kudos
MatthewCieri
Occasional Contributor

This is pretty simple tool to use so i don't see where there could be an issue but here it is. Also it fails if i have something wrong here like i have the database name wrong.      

inOriginName = rec

        inSQLQueryRec = "Select * from PCPToRecipRatio.dbo." + rec

        print inSQLQueryRec

        inOriginFeatures = arcpy.MakeQueryLayer_management(inOriginRecipientsFilePath,rec,inSQLQueryRec,"UniqueID","POINT")

       inDestinationName = prov

        inSQLQueryProv = "Select * from PCPToRecipRatio.dbo." + prov

        print inSQLQueryProv

        inDestinationFeatures = arcpy.MakeQueryLayer_management(inDestinationProvidersFilePath,prov,inSQLQueryProv,"UniqueRecordID","POINT")

Thanks,

Matt

0 Kudos
MelindaMorang
Esri Regular Contributor

This might still be a syntax problem.

Technically, an arcpy geoprocessing tool call produces a "Result object".  Sometimes you can pass that result object in as input for another tool, and the other tool is able to figure out what to do with it.  However, a more correct thing to do would be to retrieve the tool's actual output and pass that output as input to another tool.

Your code:

inDestinationName = prov

inSQLQueryProv = "Select * from PCPToRecipRatio.dbo." + prov

print inSQLQueryProv

inDestinationFeatures = arcpy.MakeQueryLayer_management(inDestinationProvidersFilePath,prov,inSQLQueryProv,"UniqueRecordID","POINT")

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")

Suggestion:

inDestinationFeatures = arcpy.MakeQueryLayer_management(blahblahblah).getOutput(0)

Other suggestion:

Instead of using the output layer object from MakeQueryLayer, try just passing the layer's string name. This also tends to work.

arcpy.na.AddLocations(outNALayer,destinationsLayerName,prov,...)

0 Kudos
MatthewCieri
Occasional Contributor

i will try the getOutput(0) idea but the string name doesn't work.  The passing of string name is what lead me down the query layer path when i first started this. It kept say layer was invalid (or something along those lines).

Thanks again for all your help and thoughts.

Some of these things seem so simple to implement but after running you notice issues popping up even though everything was "successful"

0 Kudos
MelindaMorang
Esri Regular Contributor

Happy to try to help.  I've never used the MakeQueryLayer tool before, so everything I said was just a guess.  If that doesn't work for you, you're best bet is to contact Support and to get one of them working on it.  I think I've about reached the limit of what I can advise on GeoNet.