<?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: SelectLayerByLocation returning incorrect in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/selectlayerbylocation-returning-incorrect/m-p/47067#M191</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: Wayne_Whitley&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, well, aren't you getting the point object's XY parameters at the beginning of the script as text?&amp;nbsp; The webhelp doc explicitly states you have to feed in double data types....so I think in Python you'd need to convert to float, as in (using IDLE):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; text = '123.456'
&amp;gt;&amp;gt;&amp;gt; type(text)
&amp;lt;type 'str'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; num = float(text)
&amp;gt;&amp;gt;&amp;gt; type(num)
&amp;lt;type 'float'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; # text cannot be used directly in, say, math operations:
&amp;gt;&amp;gt;&amp;gt; text + 1.0

Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;pyshell#15&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; text + 1.0
TypeError: cannot concatenate 'str' and 'float' objects
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; # However, the converted value can:
&amp;gt;&amp;gt;&amp;gt; num + 1.0
124.456
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fix that, see if it runs...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:50:08 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-10T21:50:08Z</dc:date>
    <item>
      <title>SelectLayerByLocation returning incorrect</title>
      <link>https://community.esri.com/t5/transportation-questions/selectlayerbylocation-returning-incorrect/m-p/47066#M190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: ahrensd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have been trying for some time now to create a script to extract the polygons whithin a extent, but unable to get the same result as when i use the UI manual method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe someone can see the fault of my script, have striped it down to the minimum for simplicity.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

layer = arcpy.GetParameterAsText(0)
top = arcpy.GetParameterAsText(1)
left = arcpy.GetParameterAsText(2)
bottom = arcpy.GetParameterAsText(3)
right = arcpy.GetParameterAsText(4)
outputFeature = arcpy.GetParameterAsText(5)

# Determine if Layer is a Layer
desc = arcpy.Describe(layer)
if hasattr(desc, "layer"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = layer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Parameter was layer: {0}'.format(lyr))
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.MakeFeatureLayer_management(layer,"in_memory\\source_layer")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Parameter made to layer: {0}'.format(lyr))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
sr = arcpy.CreateSpatialReference_management("",lyr,"","","","")

lowerLeft = arcpy.Point(left,bottom)
upperLeft = arcpy.Point(left,top)
upperRight = arcpy.Point(right,top)
lowerRight = arcpy.Point(right,bottom)

a = arcpy.Array([lowerLeft,lowerRight,upperRight,upperLeft,lowerLeft])
thepoly = arcpy.Polygon(a,sr)

arcpy.AddMessage('Selecting form lyr by polygon: {0}'.format(thepoly))
selection = arcpy.SelectLayerByLocation_management(lyr, "WITHIN", thepoly, "", "NEW_SELECTION")

matchcount = int(arcpy.GetCount_management(selection).getOutput(0)) 
if matchcount == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('no features matched spatial and attribute criteria')
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if matchcount &amp;lt; 1000:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(selection, outputFeature)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('{0} objects that matched criteria written to {1}'.format(matchcount, outputFeature))
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:50:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/selectlayerbylocation-returning-incorrect/m-p/47066#M190</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-10T21:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByLocation returning incorrect</title>
      <link>https://community.esri.com/t5/transportation-questions/selectlayerbylocation-returning-incorrect/m-p/47067#M191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: Wayne_Whitley&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, well, aren't you getting the point object's XY parameters at the beginning of the script as text?&amp;nbsp; The webhelp doc explicitly states you have to feed in double data types....so I think in Python you'd need to convert to float, as in (using IDLE):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; text = '123.456'
&amp;gt;&amp;gt;&amp;gt; type(text)
&amp;lt;type 'str'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; num = float(text)
&amp;gt;&amp;gt;&amp;gt; type(num)
&amp;lt;type 'float'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; # text cannot be used directly in, say, math operations:
&amp;gt;&amp;gt;&amp;gt; text + 1.0

Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;pyshell#15&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; text + 1.0
TypeError: cannot concatenate 'str' and 'float' objects
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; # However, the converted value can:
&amp;gt;&amp;gt;&amp;gt; num + 1.0
124.456
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fix that, see if it runs...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:50:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/selectlayerbylocation-returning-incorrect/m-p/47067#M191</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-10T21:50:08Z</dc:date>
    </item>
  </channel>
</rss>

