Definition Query in ModelBuilder

1726
3
Jump to solution
07-25-2013 06:29 AM
PeterHugger
New Contributor
Is is possible to create and apply a definition query in ModelBuilder?

The model would be the same as in the attached screenshot except that the tool would be "Definition Query" not "Select Layer By Attribute".

[ATTACH=CONFIG]26204[/ATTACH]

I feel like this should be easy to do.

Any help is appreciated.

Thanks.

pbh
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
Thanks for your reply.

I am having trouble getting this to work. The Make Feature Layer tool doesn't seem apply it's query/expression to the input layer (it creates a separate (temporary) layer). I think your solution would work if I needed to create a new layer or temporary layer to be processed further. This is not what I am trying to do. Basically I am trying to simplify the application of a definition query. For example: Instead of having the users [right click > properties > definition query > create SQL query] they would [double click tool > specify the expression value]. Once applied the definition query will only show the features that meet the expression criteria (this is incredibly useful when editing in an area with many features).

Perhaps this cannot be done in ModelBuilder.

Thanks anyways.


Python could do it more easily than Model Builder, except Model Builder has some SQL validation support for the end users that Python doesn't have without custom programming.  Nonetheless, getting a particular layer in a map and settings its definition query based on user input would be a pretty straight forward script.  A Python Add-In button would probably let the users launch it.  Check the Python forum for examples of setting layer definition queries.

View solution in original post

0 Kudos
3 Replies
RichardFairhurst
MVP Honored Contributor
Is is possible to create and apply a definition query in ModelBuilder?

The model would be the same as in the attached screenshot except that the tool would be "Definition Query" not "Select Layer By Attribute".

[ATTACH=CONFIG]26204[/ATTACH]

I feel like this should be easy to do.

Any help is appreciated.

Thanks.

pbh


Use the Make Feature Layer tool with the query option specified.  That is the definition query of the layer as far as I know.  A layer without a query can feed a layer with one, but not the other way around as far as I know.
0 Kudos
PeterHugger
New Contributor
Thanks for your reply.

I am having trouble getting this to work. The Make Feature Layer tool doesn't seem apply it's query/expression to the input layer (it creates a separate (temporary) layer). I think your solution would work if I needed to create a new layer or temporary layer to be processed further. This is not what I am trying to do. Basically I am trying to simplify the application of a definition query. For example: Instead of having the users [right click > properties > definition query > create SQL query] they would [double click tool > specify the expression value]. Once applied the definition query will only show the features that meet the expression criteria (this is incredibly useful when editing in an area with many features).

Perhaps this cannot be done in ModelBuilder.

Thanks anyways.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Thanks for your reply.

I am having trouble getting this to work. The Make Feature Layer tool doesn't seem apply it's query/expression to the input layer (it creates a separate (temporary) layer). I think your solution would work if I needed to create a new layer or temporary layer to be processed further. This is not what I am trying to do. Basically I am trying to simplify the application of a definition query. For example: Instead of having the users [right click > properties > definition query > create SQL query] they would [double click tool > specify the expression value]. Once applied the definition query will only show the features that meet the expression criteria (this is incredibly useful when editing in an area with many features).

Perhaps this cannot be done in ModelBuilder.

Thanks anyways.


Python could do it more easily than Model Builder, except Model Builder has some SQL validation support for the end users that Python doesn't have without custom programming.  Nonetheless, getting a particular layer in a map and settings its definition query based on user input would be a pretty straight forward script.  A Python Add-In button would probably let the users launch it.  Check the Python forum for examples of setting layer definition queries.
0 Kudos