Definition Query in ModelBuilder

10761
7
09-20-2013 07:18 AM
RobertBorchert
Frequent Contributor III
In an mxd session one can create a definition query for a particular feature by simply creating it in the Table Of Contents

What I would like to do is create a definition query in model builder for a particular feature class that is used as a selection feature for the rest of the model.

Thanks,
Tags (2)
0 Kudos
7 Replies
NeilAyres
MVP Alum
Robert, wouldn't you do this with the "Make Feature Layer" tool from the toolbox.
There you can add a sql expression. Will do the same thing as a definition in the properties. Only the selected data is passed on to the next process.
You can probably copy your selection text from the dialog you do manually in ArcMap.
Cheers,
Neil
0 Kudos
deleted-user-RUEqqvNTOoQf
New Contributor II

Neil,

I tried to use definition query on a table in my file geodatabase, so i used "make table view" which is similiar to "make feature layer". but it wouldn't work. I set the model environment to be the geodatabse all my data are in, but it still says it cannot find the table which is the result of "make table view". I am wondering if I am missing something. Do you have an example script I could refer to?

Thank you for any help.

Sunny

0 Kudos
RobertBorchert
Frequent Contributor III
Thanks,

I knew it would be something simple.

I am going to plug it in and give it a test.



Robert, wouldn't you do this with the "Make Feature Layer" tool from the toolbox.
There you can add a sql expression. Will do the same thing as a definition in the properties. Only the selected data is passed on to the next process.
You can probably copy your selection text from the dialog you do manually in ArcMap.
Cheers,
Neil
0 Kudos
RobertBorchert
Frequent Contributor III
Sadly it did not work.  I think if I had a more simple model it may have worked but I wanted to use the parameter as the beginning of 23 different sub operations.

I don't really need the solution I just want it.  The model works fine IF I do the definition query to the Feature Class before running the model.  And as I won't have to run it to many times I can just remember to define the data first.

If anyone else has any suggestions I would love to try them out.

My model takes Transmission lines that are distinguished by Line Name (180 unique) Segment (23 different segments) and Circuit number (2 unique).  I then have 65000 poles some of which straddle segments and circuits.   What I am doing is extracting those poles and creating a new feature that segregates into grouping the structures by which line it is on and which segment and circuit.  and for those that straddle multiple segments and circuits it will create multiple structures. 

Long story short I have the model working perfectly if I define circuit 1 or 2 and then run the model twice.  However, as I am doing this and finding drawing errors and fixing them and running it again etc etc... I was just looking for a way to streamline my process.  Not that it is a pain, I just want to know how at this point.
0 Kudos
andysp
by
New Contributor III

Have you looked at using an iterator? Seems like you could iterate the values of your Circuit field and that might do the trick.

http://resources.arcgis.com/en/help/main/10.2/index.html#//00400000000t000000

0 Kudos
MichaelStead
Occasional Contributor III
Here's a Dan Patterson script that I learned how to do this from (thanks Dan). Look what he does starting on line 199. The % sign is used to do a substitution to get around the problem caused with required quotations for the query. I have read that Python has a new way to do the equivalent, but this works for me.
0 Kudos
MichaelHeirendt
New Contributor

What I have done in the past is use the "Make Feature Layer tool" with this you can include a definition query, and it can also be dynamic if you are using an iterator.

0 Kudos