How to use local network dataset with ArcGIS API for Python (generate_origin_destination_cost_matrix)

619
3
07-25-2020 03:24 AM
MerrishaFrancis
New Contributor II

I am working on a script to calculate the distances from a warehouse to all stores belonging to that warehouse. I have done this successfully in the past using arcpy and "Make OD Cost Matrix Analysis Layer". The network dataset used sits locally in a FGDB. I now need to achieve the same result, but the script needs to run in an environment without arcpy. Our organisation does have access to ArcGIS Enterprise but we are not permitted to publish our network dataset due to licensing restrictions on the data.

I would like to use the ArcGIS API for Python and generate_origin_destination_cost_matrix to do my calculations, but without having a publish routing/network service. Is there a way to use the API with a local network dataset in a FGDB?

The sample notebook on the developers guide site indicates that "generate origin destination cost matrix can be associated with a local network dataset" but I cannot seem to find any documentation that explains this further.

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

At some stage/level, a license will be required for the network analyst extension.  Since it is a tool in arctoolbox, arcpy will be required.  Running on a local machine with local data isn't the issue if the local machine doesn't have Pro installed

Make OD Cost Matrix Analysis Layer—ArcGIS Pro | Documentation 


... sort of retired...
MerrishaFrancis
New Contributor II

Hi Dan,

Thanks for the feedback.

My organisation does have a network dataset in a FGDB which was then used to publish routing services on our Portal. However, it turned out that the usage restrictions on the data do not allow us to publish it, and can only be used on local machines. So now I have rewritten the script without arcpy, using the ArcGIS API for Python using 

arcgis.network.analysis.generate_origin_destination_cost_matrix (using this guide: Guide to Network Analysis (Part 5 - Generate OD Cost Matrix) | ArcGIS for Developers ).

This works fine without arcpy, however I can no longer use the routing service I published, it had to be removed. The Guide to Network Analysis link above indicated that Generate Origin Destination Cost matrix can be associated with a local network dateset OR a hosted service. So my question is more about how is this "association" done? Or am I misunderstanding the guide?

0 Kudos
NicolasMarecos
Esri Contributor

Hi Merrisha,

From what I can tell the OD Matrix function in the Python API requires 2 FeatureSets (one for origins, another for destinations), this is most easily created from a arcgis.features.Feature object in a hosted GIS Portal(whether this is ArcGIS Online or Portal.) The feature sets could be generated from data not hosted from these datatypes, however the challenge would be converting the data to the required formats from the FGDB.

I hope this is helpful,

Nico

0 Kudos