Why isn't my model iterating for all features (2 iterators using sub models)

639
2
10-11-2022 08:41 PM
LindsayRaabe_FPCWA
Occasional Contributor III

I have built a Model (with 2 sub-models) that is meant to follow the following logic for preparing data for use in Network Analysis route solving (Stops):

- 2 input point feature classes (Origin points and Destination points)

- For each Origin (i.e. A/B/C/D) and Destination (i.e. W/X/Y/Z) point combination, generate a Route Name (i.e. A_W, A_X, A_Y, A_Z). Each Origin point goes to many destinations and needs to be copied with the unique Route Name applied to each copy to match a destination point that gets the same Route Name applied. 

- Append all Origin and Destination points to an output feature class (Stops)

The final table will have what was originally 4 Origins copied in 4 times each with the unique route name to each Destination, plus each destination point copied in 4 times to pair with each origin location (A_W, A_X, A_Y, A_Z, B_W, B_X, ..., D_Y, D_Z). 

Graphics below show the main model which has input parameters for selecting the Origin and Destination feature classes, then a sub-model which iterates through each Origin location, and that has within it another sub-model which iterates through each Destination location to achieve the required value creation and data copying. 

LindsayRaabe_FPCWA_0-1665545603524.png

LindsayRaabe_FPCWA_7-1665546039627.png

LindsayRaabe_FPCWA_3-1665545726612.png

LindsayRaabe_FPCWA_5-1665545975273.png

The issue I've found is that whilst the model works as expected for the first Origin point, generating unique Origin/Destination combinations for all destinations, it doesn't then continue on to do the same for the next Origin location (the point of the first sub-model/iterator), resulting in the output FC only having a portion of the data required. 

Sorry if this is very wordy, but couldn't figure out how to write it any more clearly. Ultimately, I'm trying to create the required data for generating multiple routes in one hit using Network Analyst. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
2 Replies
LindsayRaabe_FPCWA
Occasional Contributor III

No ideas? Suggestions? 

I tried moving the steps in the 1st sub model preceding the iteration into the main model to reduce unnecessary processing. No discernable difference on my sample dataset (same results). 

I also tried using Collect Values on the iterator outputs to pass back to the main model, but I just ended up with 14 copies of the last point processed. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
Occasional Contributor III

So in lieu of finding a solution to this direct issue (of nested submodels and iterators), I came up with an alternate plan (that I believe works better anyway). I have now separated my model into the following 3 sections:

  • Main Model (selects input data and parameters, fills out basic field calculations and gets the initial count of records from my 2 input datasets)
OIDDataset 1 OIDDataset 2
     
1Bunbury 1Perth
2Collie 2Busselton
3Manjimup 3Kojonup
4Albany 4Geraldton
   5Kalgoorlie
     
 Count = 4  Count = 5

 

  • Sub-Model 1 (inside Main Model which replicates the first dataset to match A*B (i.e. A=4 & B=5 then C=20) by repeatedy appending a copy of the input dataset to itself until it has 20 total records (5 times in this example)). 
OIDDataset 1
  
1Bunbury
2Collie
3Manjimup
4Albany
5Bunbury
6Collie
7Manjimup
8Albany
9Bunbury
10Collie
11Manjimup
12Albany
13Bunbury
14Collie
15Manjimup
16Albany
17Bunbury
18Collie
19Manjimup
20Albany
  
 Count = 20

 

  • Sub-Model 2 (also inside Main Model and NOT Sub-Model 1 like in my first attempt. This does the same as the 1st Sub-Model except on the second dataset, appending a copy of the 2nd dataset to the input dataset until it has reached 20 records total (4 times in this example)). 
OIDDataset 2
  
1Perth
2Busselton
3Kojonup
4Geraldton
5Kalgoorlie
6Perth
7Busselton
8Kojonup
9Geraldton
10Kalgoorlie
11Perth
12Busselton
13Kojonup
14Geraldton
15Kalgoorlie
16Perth
17Busselton
18Kojonup
19Geraldton
20Kalgoorlie
  
 Count = 20

 

The main model then sorts the first replicated dataset output by Sub-Model 1 by a name field which groups all spatially colocated features together in the table with new ObjectID's. 

OIDUnsorted>>>>>OIDSorted
     
1Bunbury 1Albany
2Collie 2Albany
3Manjimup 3Albany
4Albany 4Albany
5Bunbury 5Albany
6Collie 6Bunbury
7Manjimup 7Bunbury
8Albany 8Bunbury
9Bunbury 9Bunbury
10Collie 10Bunbury
11Manjimup 11Collie
12Albany 12Collie
13Bunbury 13Collie
14Collie 14Collie
15Manjimup 15Collie
16Albany 16Manjimup
17Bunbury 17Manjimup
18Collie 18Manjimup
19Manjimup 19Manjimup
20Albany 20Manjimup

 

It then joins it to the 2nd dataset by ObjectID. This join means that for each copy of a record in a group of records in dataset 1, it has a unique matching record from dataset 2. Field calculations are then done to preserve the attributes from dataset 2, the join removed and the final data exported to a new feature class. 

OIDJoinedDataset
   
1AlbanyPerth
2AlbanyBusselton
3AlbanyKojonup
4AlbanyGeraldton
5AlbanyKalgoorlie
6BunburyPerth
7BunburyBusselton
8BunburyKojonup
9BunburyGeraldton
10BunburyKalgoorlie
11ColliePerth
12CollieBusselton
13CollieKojonup
14CollieGeraldton
15CollieKalgoorlie
16ManjimupPerth
17ManjimupBusselton
18ManjimupKojonup
19ManjimupGeraldton
20ManjimupKalgoorlie

 

LindsayRaabe_FPCWA_0-1665994760401.png

LindsayRaabe_FPCWA_1-1665994808767.pngLindsayRaabe_FPCWA_2-1665994839284.png

Another small tip - use "memory " as the output location for working data instead of a .gdb (including %scratchgdb%) - it works so much faster!

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos