Does anyone know if you can add an SQL query that applies to multiple features in modelbuilder?
No I am not using the Select by Attributes tool, should I be?
On a similar note and using "Select by Attributes", as Dan suggested that you can use a python script to build further complexity. Following is an example of a script that I used in a model to build a where clause to get a one to many related records .... hope this helps (it is crude but it gets the job done... I am a vb programmer not python) ....
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os <SPAN class="comment token"># Local Variables</SPAN> OriginTable <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Sign Support --> Make Table View</SPAN> DestinationTable <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Sign Panels ---> Make Table View</SPAN> PrimaryKeyField <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#SupportID /Sign Support</SPAN> ForiegnKeyField <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#SupportID /Sign Panels</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">buildWhereClauseFromList</SPAN><SPAN class="punctuation token">(</SPAN>OriginTable<SPAN class="punctuation token">,</SPAN> PrimaryKeyField<SPAN class="punctuation token">,</SPAN> valueList<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""Takes a list of values and constructs a SQL WHERE clause to select those values within a given PrimaryKeyField and OriginTable."""</SPAN> fieldDelimited <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddFieldDelimiters<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>OriginTable<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">,</SPAN> PrimaryKeyField<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Determine field type</SPAN> fieldType <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>OriginTable<SPAN class="punctuation token">,</SPAN> PrimaryKeyField<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>type <SPAN class="comment token"># Add DBMS-specific field delimiters</SPAN> <SPAN class="comment token"># Add single-quotes for string field values</SPAN> <SPAN class="keyword token">if</SPAN> str<SPAN class="punctuation token">(</SPAN>fieldType<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">'String'</SPAN><SPAN class="punctuation token">:</SPAN> valueList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"'%s'"</SPAN> <SPAN class="operator token">%</SPAN> value <SPAN class="keyword token">for</SPAN> value <SPAN class="keyword token">in</SPAN> valueList<SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># Format WHERE clause in the form of an IN statement</SPAN> whereClause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"%s IN(%s)"</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>fieldDelimited<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">', '</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">,</SPAN> valueList<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#arcpy.AddMessage(whereClause)</SPAN> <SPAN class="keyword token">return</SPAN> whereClause <SPAN class="keyword token">def</SPAN> <SPAN class="token function">selectRelatedRecords</SPAN><SPAN class="punctuation token">(</SPAN>OriginTable<SPAN class="punctuation token">,</SPAN> DestinationTable<SPAN class="punctuation token">,</SPAN> PrimaryKeyField<SPAN class="punctuation token">,</SPAN> ForiegnKeyField<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""Defines the record selection from the record selection of the OriginTable and apply it to the DestinationTable using a SQL WHERE clause built in the previous definition"""</SPAN> <SPAN class="comment token"># Set the SearchCursor to look through the selection of the OriginTable</SPAN> sourceIDs <SPAN class="operator token">=</SPAN> set<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>OriginTable<SPAN class="punctuation token">,</SPAN> PrimaryKeyField<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Establishes the where clause used to select records from DestinationTable</SPAN> whereClause <SPAN class="operator token">=</SPAN> buildWhereClauseFromList<SPAN class="punctuation token">(</SPAN>DestinationTable<SPAN class="punctuation token">,</SPAN> ForiegnKeyField<SPAN class="punctuation token">,</SPAN> sourceIDs<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Process: Select Layer By Attribute</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>DestinationTable<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> whereClause<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Process: Select related records between OriginTable and DestinationTable</SPAN> selectRelatedRecords<SPAN class="punctuation token">(</SPAN>OriginTable<SPAN class="punctuation token">,</SPAN> DestinationTable<SPAN class="punctuation token">,</SPAN> PrimaryKeyField<SPAN class="punctuation token">,</SPAN> ForiegnKeyField<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#output same as Destination Table</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
do you currently do that using the Select By Attributes tool?
Yes all the tools I am using are in ArcToobox. Basically I would like a SQL and/or drop-down to select the appropriate county across several feature classes.
If it uses a tool in ArcToolbox and you can do the process using only the tools in arctoolbox, then yes. If it gets fancier, then you can incorporate scripts in the model. It may be easier in that case to simply script what you need.
Perhaps if you can show what it is that you are trying to do, other specific suggestions might come forward.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.