<?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 Re: Make feature layer &amp;amp; Select by attribute in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183168#M6174</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How/Where are you setting variables gwsyear &amp;amp; gweyear?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible you are setting them as a string instead of a number?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Jun 2010 15:31:22 GMT</pubDate>
    <dc:creator>RDHarles</dc:creator>
    <dc:date>2010-06-28T15:31:22Z</dc:date>
    <item>
      <title>Make feature layer &amp;amp; Select by attribute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183167#M6173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to loop and split a polygon shapefile using a list of values that i want to incorporate into my query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I cannot get the query to work properly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How can i use variable x in the query?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()
gp.overwriteoutput = 1

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Set workspace
gp.workspace = "C:\\geodata\\PRIO_GRID\\Data_Sources\\cShapes0.24\\"

# Create list
yearlist = list(range(1946, 2009))

# Process: Select Layer By Attribute...
for x in yearlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer("cshapes.shp","lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByAttribute("lyr", "new_selection", "\"gwsyear\" &amp;lt;= x AND \"gweyear\" &amp;gt;= x")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CopyFeatures("lyr", "cshapes"+x)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jun 2010 10:14:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183167#M6173</guid>
      <dc:creator>Andreas_ForøTollefsen</dc:creator>
      <dc:date>2010-06-28T10:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer &amp; Select by attribute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183168#M6174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How/Where are you setting variables gwsyear &amp;amp; gweyear?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible you are setting them as a string instead of a number?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jun 2010 15:31:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183168#M6174</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2010-06-28T15:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer &amp; Select by attribute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183169#M6175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The problem is that the geoprocessor isnt looking at that x as a variable, just a part of the query string. Build your query outside of that tool and just make the query string a variable. You dont need to escape every quote in the geoprocessing tools, its better to use string literals when making an input variable like this. You may have to convert your date into strings if they are stored as integers so that the string can concatenate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; 
Query=r'""qwsyear" &amp;lt;= ' + str(x) + r' AND "gweyear" &amp;gt;= ' + str(x) + r'"'
 
gp.SelectLayerByAttribute("lyr", "new_selection", Query)
 
 
&amp;gt;&amp;gt;&amp;gt; x=1957
&amp;gt;&amp;gt;&amp;gt; query=r'""qwsyear" &amp;lt;= ' + str(x) + r' AND "gweyear" &amp;gt;= ' + str(x) + r'"'
&amp;gt;&amp;gt;&amp;gt; query
'""qwsyear" &amp;lt;= 1957 AND "gweyear" &amp;gt;= 1957"'
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:19:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183169#M6175</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2021-12-11T09:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer &amp; Select by attribute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183170#M6176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great. That worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
gp.overwriteoutput = 1

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Set workspace
gp.workspace = "C:\\geodata\\PRIO_GRID\\Data_Sources\\cShapes0.24\\"

# Create list
yearlist = list(range(1946, 2009))

# Define emptygrid
emptygrid = "C:\\geodata\\PRIO_GRID\\Data_Sources\\EmptyGrid\\emptygrid230610_WGS.shp"

# Select cShapes year and copy each year to new shapefile
for x in yearlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp; query ="GWSYEAR &amp;lt;= " + str(x) + " " + "AND" + " " + "GWEYEAR &amp;gt;= " + str(x)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer("cshapes.shp","lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByAttribute("lyr", "new_selection", query)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CopyFeatures("lyr", "cshapes"+str(x))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del yearlist, query, x, emptygrid
print "completed"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:19:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/make-feature-layer-amp-amp-select-by-attribute/m-p/183170#M6176</guid>
      <dc:creator>Andreas_ForøTollefsen</dc:creator>
      <dc:date>2021-12-11T09:19:42Z</dc:date>
    </item>
  </channel>
</rss>

