Model builder iterator

2720
8
02-20-2020 06:03 AM
ErikÖhrner
Emerging Contributor

I have a shapefile of thousands of lines that I want to make each record in the attribute table its own unique shapefile and then buffer each and every one of those lines and also run Euclidean distance on the unique shapefiles.

I think I can do this using Model Builder and working with iterators but I can't seem to find out which iterators I should use.

In the image you can see the progress right now and the tools I want to use. I think the iterator is the correct one but I'm not sure.

Basically the formula is like this: Master shapefile -> Extract each record and make it its own shapefile(s) - > Create buffer on these new shapefile(s) - > Run Euclidean Distance (with Buffers as extent) on the new shapefile(s).

This is manageable to do on a few shapefiles but I thought using Model Builder would speed up this process a lot by using iterators, however I struggle to find how to do it. Any help appreciated!

Tags (2)
0 Kudos
8 Replies
ShaneMiles
Esri Contributor

Hi Erik Öhrner‌,

There are few ways you could go about this, but the Iterator you have selected Iterate feature classes will achieve the result you are after. Please note that only one Iterator can be used per model Iterators—ArcGIS Pro | Documentation. This may mean that if you wanted to run through your features again for the Euclidean Distance you may have to look at Batch options or a second model. 

Alternatively you may be able to run the buffer on the initial master shapefile with no dissolve type Buffer—Help | Documentation , then extract each record into its own shapefile. This would leave the iterator to be used within the Euclidean Distance aspect of your model. I hope this has helped answer your question.

Shane

ErikÖhrner
Emerging Contributor

Hi Shane

Thanks for trying to help.

I like your alternative approach. It seems easier to produce one giant buffer and then use Split by attributes on that and then have several buffers.

However, I'm not sure if it is still possible to use extent in iterators. That seem to be one problem I have. I will research a bit more and edit this reply if I find something out.

0 Kudos
DuncanHornby
MVP Notable Contributor

If you do in fact have a single shapefile with thousands of lines then I would say you are using the WRONG iterator, yes you could do it your way but it is very inefficient, for example your split by attribute tool will execute as many times as the iterator loops which makes no sense.

You want to be stepping over each feature in the shapefile. So you want to be using the Feature Selection iterator, you will also need to understand and must use inline-variable substitution to ensure a unique output file name. 

An alternative, probably smarter approach, is to buffer your lines (with no dissolve) and then iterate over the buffers, this would avoid the cost of having to run buffer tool thousands of times...

ErikÖhrner
Emerging Contributor

Hello Duncan,

Thanks for trying to explain how I could solve my problem. However, I've been trying these last couple of days but it won't work for me at all.

The iterator doesn't seem to work like intended. Down below is my model right now. I have the big shapefile on the left and then I use the iterator and the buffer tool. This however, only produces one buffer file instead of one buffer for each line. In the iterator I have used a unique ID as "Group By Fields".

The next including Euclidean Distance I don't know how to solve either. Since that involves using the lines as input features and the buffers as extents.

0 Kudos
DuncanHornby
MVP Notable Contributor

Sounds like you are not using inline variable substitution in the buffer output file name? If not check the helpfile to understand what that is.

0 Kudos
ErikÖhrner
Emerging Contributor

When I use %name% it says I'm using invalid characters. I don't know if it makes a difference if I use a geodatabase or not. I will research this.

0 Kudos
DuncanHornby
MVP Notable Contributor

Almost there! the variable name comes from your iterator, looking at your model you have left it as the default which is Value. You can either rename the variable or replace %name% with %value%. If you had renamed it to Erik then you would use %Erik%.

0 Kudos
ErikÖhrner
Emerging Contributor

Aha. That option is "greyed out" for me though.Do you know why that might be the case? I know if you use a geodatabase some things can be different, but not sure on this. I have used %name% before but sometimes it can be a little confusing.

0 Kudos