<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic User-Defined Definition Query in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/user-defined-definition-query/m-p/313206#M3298</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am hoping to allow a user to modify the definition query of a layer without actually typing it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For instance, let's say I have a dataset of all of the stores in all the malls in Ohio. Each store feature has a StoreID and a MallID I would like to be able to have form (or something else) where a user can first select the MallID and then a second selection of StoreID. This would have the effect of setting the definition query so that only the 1 store displays for the user.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is this possible without major programming efforts?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Jan 2014 20:09:32 GMT</pubDate>
    <dc:creator>JonathanBotts</dc:creator>
    <dc:date>2014-01-09T20:09:32Z</dc:date>
    <item>
      <title>User-Defined Definition Query</title>
      <link>https://community.esri.com/t5/mapping-questions/user-defined-definition-query/m-p/313206#M3298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am hoping to allow a user to modify the definition query of a layer without actually typing it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For instance, let's say I have a dataset of all of the stores in all the malls in Ohio. Each store feature has a StoreID and a MallID I would like to be able to have form (or something else) where a user can first select the MallID and then a second selection of StoreID. This would have the effect of setting the definition query so that only the 1 store displays for the user.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is this possible without major programming efforts?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2014 20:09:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/user-defined-definition-query/m-p/313206#M3298</guid>
      <dc:creator>JonathanBotts</dc:creator>
      <dc:date>2014-01-09T20:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: User-Defined Definition Query</title>
      <link>https://community.esri.com/t5/mapping-questions/user-defined-definition-query/m-p/313207#M3299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would do this using a gp script tool.&amp;nbsp; The tool would have two parameters: Select Mall ID and Select Store ID.&amp;nbsp; The script tool would also have a validation script that would control:&amp;nbsp; when the script tool is first opened, only the Select Mall ID parameter would display a list of mall ids in a parameter pulldown box.&amp;nbsp; Once you select a mall id, then the validation script would display on the Store IDs for that mall.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script tool would then pass the two parameters to the calling python script that would automagically set a layer def query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a sample main python script that the script tool would call.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;mallID = arcpy.GetParameterAsText(0)&amp;nbsp; #the first parameter in script tool storeID = arcpy.GetParameterAsText(1) #the second parameter in script tool&amp;nbsp; mxd = arcpy.mapping.MapDocument("current") lyr = arcpy.mapping.ListLayers(mxd, "My Mall Layer")[0] lyr.definitionQuery = '"MallID" = ' + str(mallID) + ' AND "StoreID" = ' str(storeID) arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The validation script (a property of the script tool) would look something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def initializeParameters(self):&amp;nbsp;&amp;nbsp; #THIS IS CALLED WHEN THE SCRIPT TOOL OPENS AND AUTO POPULATES THE FIRST PARAMETER &amp;nbsp;&amp;nbsp;&amp;nbsp; """Refine the properties of a tool's parameters.&amp;nbsp; This method is &amp;nbsp;&amp;nbsp;&amp;nbsp; called when the tool is opened."""&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #Generate unique list of Mall IDs &amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") &amp;nbsp;&amp;nbsp;&amp;nbsp; mlyr = arcpy.mapping.ListLayers(mxd, "My Mall Layer") &amp;nbsp;&amp;nbsp;&amp;nbsp; fieldName = "MallID" &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(mlyr.dataSource) &amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueMallList = [] &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.getValue(fieldName) not in uniqueMallList: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueMall.append(row.getValue(fieldName)) &amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueMallList.sort() &amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[0].filter.list = uniqueMallList &amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; def updateParameters(self): #THIS IS CALLED WHEN THE FIRST PARAMETER IS SELECTED AND POPULATES 2ND PARAMETER &amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal &amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parmater &amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed.""" &amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[0].value: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Generate unique list of Store IDs &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; slyr = arcpy.mapping.ListLayers(mxd, "My Store Layer") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldName = "StoreID" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(slyr.dataSource) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueStoreList = [] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.getValue(fieldName) not in uniqueStoreList: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueStoreList.append(row.getValue(fieldName)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueStoreList.sort() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].filter.list = uniqueStoreList &amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code is untested and I'm sure has some silly typos but all the parts are here.&amp;nbsp; I hope this helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jan 2014 13:59:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/user-defined-definition-query/m-p/313207#M3299</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2014-01-10T13:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: User-Defined Definition Query</title>
      <link>https://community.esri.com/t5/mapping-questions/user-defined-definition-query/m-p/313208#M3300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jeff,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks! With a little modification, the script works really well. After testing the drop-downs, I decided to allow the user to type in the MallID, so I ended up just taking out the Initialize Parameters, but it functioned just as I hoped.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jonathan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 12:31:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/user-defined-definition-query/m-p/313208#M3300</guid>
      <dc:creator>JonathanBotts</dc:creator>
      <dc:date>2014-01-14T12:31:42Z</dc:date>
    </item>
  </channel>
</rss>

