Select to view content in your preferred language

Inline Variable Substitution in ModelBuilder Question

1949
4
Jump to solution
09-07-2012 11:18 AM
EldredAllen
New Contributor II
I am using a Feature Class Iterator in ModelBuilder to iterate through shapefiles I created from KML files in Google Earth.  I try and use the inline variable substitution %Name% to get the name of the feature class on each iteration however my issue is each feature class has the same name.  As they were created form KML files they all are named Placemarks_polygon.  When I use the %Name% variable substitution it overwrites each of the previous iterations with the one it completed last (ie. I have over 100 Placemarks_polygon feature classes and it only keeps the last one and not all of them).

My question is, is there any method during the inline variable substitution of %Name% to add a unique number as well, ie. the first iteration would be Placemarks_polygon1, then Placemarks_polygon2, etc so that they do not overwrite each other?

Thanks for the help.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KevinHibma
Esri Regular Contributor
I believe you can use %n% to grab the iteration number. I just tried it and it works.

So my final output looks like: c:\temp\f.gdb\%Name%_%n%

Alternatively, take a look at the 2nd code sample at the bottom of the KML to layer page.
It demonstrates converting a bunch of KMLs into featureclasses, then pulling each featureclass out of their respective GDB, and into a single GDB and assigns them the name from the GDB they came from (not placemark). This sounds similar to what you're trying to do.
http://resources.arcgis.com/en/help/main/10.1/index.html#//00120000004w000000

View solution in original post

0 Kudos
4 Replies
KevinHibma
Esri Regular Contributor
I believe you can use %n% to grab the iteration number. I just tried it and it works.

So my final output looks like: c:\temp\f.gdb\%Name%_%n%

Alternatively, take a look at the 2nd code sample at the bottom of the KML to layer page.
It demonstrates converting a bunch of KMLs into featureclasses, then pulling each featureclass out of their respective GDB, and into a single GDB and assigns them the name from the GDB they came from (not placemark). This sounds similar to what you're trying to do.
http://resources.arcgis.com/en/help/main/10.1/index.html#//00120000004w000000
0 Kudos
EldredAllen
New Contributor II
Thanks very much Kevin, using the %Name%_%n% added the iteration number to the name and now I get all of the outputs and not just the last one.

I like the thought of the second suggestion using the Python code but alas my Python coding is not very strong.  This is my situation: Currently I have a folder and it contains a separate file geodatabase for each of the KMLs I created in GE and each of those file geodatabases has the correct name from the KML.  Inside each file geodatabase is a file geodatabase feature dataset and inside that dataset is the Placemarks_polygon feature class for that respective geodatabase.  So each file geodatabase has the correct name, but then the feature class inside each of the over 100 geodatabases has the same Placemarks_polygon name and so when I run the model I get Placemarks_polygon_1, etc. but then I have to rename each of those outputs to correspond to the name of the geodatabase, redundant and I'm sure un-needed using ArcGIS.

So, I was using ModelBuilder to iterate through these feature classes, re-projecting them all to my UTM zone but I don't have the knowledge to get it done as efficiently as I know it probably can be.  The final product I would like is a single feature class or dataset that contains each of the over 100 feature classes and each one to have the appropriate name.  I am creating a feature class of building footprints that have the owners name as the name of the feature class.  As I have over 100 buildings I want them all contained in a single feature class with owners listed.

Sorry for the length of the post but I am trying to add as much detail to get the best help possible, thanks.
0 Kudos
KevinHibma
Esri Regular Contributor
I understand you reluctance to get into Python scripting - you can do this in a model, but will need to put some python code into Calculate Value to get the result you want. So for this particular problem, no matter how you crack it, you'll need to write either a little code, or a "little more than a little".

Heres how I was able to do it using a model and a little bit of Python code:

-Iterator over featureclasses
-Parse Path (model only tool) which gets the full path to the featureclass you're working with
-Calc Value (which is where the Python code will be used to "find" the featureclass name")
-FeatureClass to Featureclass to copy the features into your single GDB
[ATTACH=CONFIG]17572[/ATTACH]

Here you can see the code inside calc value. Theres 100x different ways to parse a path in Python, this is just one way (kind of the long way, but I wanted to make the example clear).
[ATTACH=CONFIG]17573[/ATTACH]

expression
getName('%Value%')

code block
import os
def getName(inPath):

  sName = inPath.split(os.sep)
  gdbName = sName[len(sName) - 2]

  finalName = gdbName.strip('.gdb')
  
  return finalName

data type
String

I hope this helps.
0 Kudos
JagathJayanath
New Contributor
As far as the final product is concerned, following will do the trick.

1. Create a folder in GE My places.
2. Put all the polygon features into that folder and save folder as a kml/kmz instead of saving 100 individual kmls/kmzs.
3. Run KML to Layer tool.
4. Export Layer data [polygons] into a feature class [which will contain attributes of original polygons created in GE].
5. Project feature class into whatever coordinate system you wish.
0 Kudos