Iteration with closest facility analysis

3518
2
11-30-2015 06:58 PM
CathrynHunt
New Contributor

I am using closest facility analysis, in model builder, to find the closest grocery store and farmer’s market (facilities) to each apartment building (incident) in a neighborhood. The farmer’s markets and grocery stores are in separate shape files, and I want to somehow iterate within closest facility so that first it searches for the closest grocery store to each apartment, then finds the closest farmers market to each apartment. I am able to get this to work when there is only one facility (grocery store), but when I try to add in a second facility, the model gets stuck in an infinite loop. I am not sure first of all how to iterate (what operation to use- for loop? while loop?), and secondly, where the iteration should come in the model.  Below is

a screenshot of the model so far, where I've used a While loop, but I haven't been able to get it to work. In the model, apartments is the input labeled "Petworth_Apt". Any help is much appreciated, thanks!

image.png

0 Kudos
2 Replies
JoeBorgione
MVP Emeritus

This is just a liitle bit out of my comfort zone, but the while block probably ought to be replaced with one of the new iterator tools.

That should just about do it....
0 Kudos
ChrisDonohue__GISP
MVP Alum

Some ideas:

With Iterators, all the processes will get run each time it iterates.  So the solution here is typically to break the functions up into separate models and then link them with another model.

  • The Build Network probably only needs to be run once, so break that out into a separate model (Model 1).
  • Based on what you are trying to accomplish, the iteration looks like it should be run against the apartment shapefile.   Most of the processes will be in this model (Model 2).
  • Not sure with your specific tests, but if you find that running the Solve for each apartment to then find both the closest farmers market and the closest grocery store doesn't work in a single model, one solution may be to create two models - one that iterates apartments to find closest farmers markets and then a separate model that iterates apartments to find closest grocery stores (so maybe Model 3 besides Model 2).  Caveat - if there is a correlation that I am not seeing where the closest grocery store influences in some way the closest farmers market chosen for the apartment searched, then there may be additional changes needed.
  • To tie multiple models together, you can create another model - the "main run model".  When in Edit mode in Modelbuilder, drag in the existing models into this model from ArcCatalog.  Then connect them.  Make the inputs and outputs Parameters so the information will be "share-able" between the models.  Preconditions can be set to ensure they trigger in the correct order.  Once you have all this set up, to run the process you would run this "main model run", which will then run all the other models (Main Run Model).

Integrating a model within a model—Help | ArcGIS for Desktop

Modelbuilder Iterator Examples

ArcGIS Desktop

Some questions so folks can further understand your process:

  • What version of ArcGIS are you using?
  • Which language are you using for coding the While loop?  Or is a Modelbuilder Iterator being employed?

Chris Donohue, GISP