<?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: Select Layer by Location works in ArcGIS Pro Python window but not standalone in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114084#M62901</link>
    <description>&lt;P&gt;Interesting...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Nov 2021 15:02:09 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2021-11-04T15:02:09Z</dc:date>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113755#M62881</link>
      <description>&lt;P&gt;I'm assuming there is a feature class &lt;EM&gt;Test_Points&lt;/EM&gt; in the gdb. This is a feature class, not a layer.&lt;/P&gt;&lt;P&gt;If you want to do selections on it, you need to create a new layer in memory from it using the Make Feature Layer tool.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When running the script in Pro I am assuming there is a layer in the currently active map named &lt;EM&gt;Test_Points&lt;/EM&gt; and also a feature class in your gdb; the layer takes precedence which is why it works in a pro window.&lt;/P&gt;&lt;P&gt;By the way I also recommend using the arcpy.da cursors instead, they are&amp;nbsp;&lt;EM&gt;dramatically&amp;nbsp;&lt;/EM&gt;more efficient than the (older) arcpy cursors.&lt;/P&gt;&lt;P&gt;NOTE: original post is below in the thread&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 20:11:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113755#M62881</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-11-03T20:11:37Z</dc:date>
    </item>
    <item>
      <title>Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113753#M62883</link>
      <description>&lt;P&gt;I have run into a weird problem where a bit of code I have will run correctly in the ArcGIS Pro Python window, but not as standalone code.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = r'C:\Users\jsint\UTAProject\Get_UTA_Buffers\Get_UTA_Buffers.gdb'
arcpy.env.overwriteOutput = True 

all_points = arcpy.management.SelectLayerByAttribute('Test_Points', 'NEW_SELECTION')

cursor1 = arcpy.SearchCursor(all_points)
for row1 in cursor1:
    print("Point ",row1.getValue("OBJECTID"))
    intersecting_nodes = arcpy.management.SelectLayerByLocation('Test_Breakpoints','INTERSECT',row1.getValue('Shape'),'','NEW_SELECTION')
    a,b,c = intersecting_nodes

    # c should not = 0 if intersection works correctly
    print(a,b,c,sep = ', ')

    cursor2 = arcpy.UpdateCursor(intersecting_nodes)
    for row2 in cursor2:
        print("Iterating selected nodes")
        row2.setValue('Is_Bus_Stop',1)
        row2.setValue('Dist_to_Bus',0)
        cursor2.updateRow(row)

    print()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have followed the ArcGIS instructions on running standalone scripts given here: &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/using-conda-with-arcgis-pro.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/using-conda-with-arcgis-pro.htm&lt;/A&gt;.&amp;nbsp; Despite this, the output does not give what I would expect.&amp;nbsp; I believe I have narrowed down the issue to something related to the Select Layer by Location function: as you can see, each iteration returns 0 selected items, giving cursor2 nothing to read.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;C:\Users\jsint\UTA Project\Get_UTA_Buffers&amp;gt;c:\Progra~1\ArcGIS\Pro\bin\Python\scripts\propy.bat Make_Buffers_v2.py
Point  1
Test_Breakpoints_Layer2, Test_Breakpoints_Layer2, 0

Point  2
Test_Breakpoints_Layer5, Test_Breakpoints_Layer5, 0

Point  3
Test_Breakpoints_Layer8, Test_Breakpoints_Layer8, 0

Point  4
Test_Breakpoints_Layer11, Test_Breakpoints_Layer11, 0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Is there a reason why this would work in the ArcGIS Python window, but not standalone?&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 19:30:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113753#M62883</guid>
      <dc:creator>JonathonRobert</dc:creator>
      <dc:date>2021-11-03T19:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113767#M62882</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1325"&gt;@curtvprice&lt;/a&gt;&amp;nbsp;Curtis- where is the rest of this post?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 19:56:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113767#M62882</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-11-03T19:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113790#M62884</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1325"&gt;@curtvprice&lt;/a&gt;Thank you for the suggestions.&amp;nbsp; I've tried using the Make Feature Layer tool like you mentioned, but I am still having the same issue&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = r'C:\Users\jsint\UTA Project\Get_UTA_Buffers\Get_UTA_Buffers.gdb'
arcpy.env.overwriteOutput = True

point_lyr = arcpy.management.MakeFeatureLayer('Test_Points','Test_Points_lyr') 
breakpoint_lyr = arcpy.management.MakeFeatureLayer('Test_Breakpoints','Test_Breakpoints_lyr') 

# all_points = arcpy.management.SelectLayerByAttribute('Test_Points_lyr', 'NEW_SELECTION')
all_points = arcpy.management.SelectLayerByAttribute(point_lyr, 'NEW_SELECTION')

cursor1 = arcpy.da.SearchCursor(all_points)
for row1 in cursor1:
    print("Point ",row1.getValue("OBJECTID"))
    
    intersecting_nodes = arcpy.management.SelectLayerByLocation(breakpoint_lyr,'INTERSECT',row1.getValue("Shape"),'','NEW_SELECTION')
    a,b,c = intersecting_nodes
    print(a,b,c,sep = ', ')

    cursor2 = arcpy.da.UpdateCursor(intersecting_nodes)
    for row2 in cursor2:
        print("Iterating selected nodes")
        row2.setValue('Is_Bus_Stop',1)
        row2.setValue('Dist_to_Bus',0)
        cursor2.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;I have tried using both a variable for the new layer and the string name (e.g. 'Test_Points_lyr') but the output is the exact same.&amp;nbsp; Is there an issue with how I am calling the MakeFeatureLayer method?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 20:45:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113790#M62884</guid>
      <dc:creator>JonathonRobert</dc:creator>
      <dc:date>2021-11-03T20:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113791#M62885</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1325"&gt;@curtvprice&lt;/a&gt;&amp;nbsp;addressed that above;&amp;nbsp; when you are working in a stand alone script, you need to use the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/make-feature-layer.htm" target="_self"&gt;make feature layer method&lt;/A&gt; in arcpy.&amp;nbsp; ArcGIS Pro presents the data in that form for you so you are able to interact with it, hence, when you refer to the data in you TOC it's a feature layer.&amp;nbsp; But when you run a stand alone script, you need to do what ArcGIS Pro does.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
arcpy.env.workspace = r'C:/path/to/data.gdb'
fc = 'MyFeatureClass'
arcpy.MakeFeatureLayer_management(fc, "MyLayer")
select = 'OBJECTID = 1'
arcpy.management.SelectLayerByAttribute('MyLayer', 'NEW_SELECTION', select)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 03 Nov 2021 20:48:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113791#M62885</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-11-03T20:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113806#M62886</link>
      <description>&lt;P&gt;I also think that the setup is incorrect for arcpy.da cursors -- the syntax setup is different, usually using a "with" statement. See the help.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 21:37:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113806#M62886</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-11-03T21:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113808#M62887</link>
      <description>&lt;P&gt;I wish the old search/update/insert cursors would just go away so you get a syntax error instead of some jacked up result.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 21:40:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1113808#M62887</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-11-03T21:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114054#M62892</link>
      <description>&lt;P&gt;I believe I have found the problem.&amp;nbsp;&amp;nbsp; It actually does not seem that it is necessary to convert the feature class to a feature layer.&amp;nbsp; However, what &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3374"&gt;@JoeBorgione&lt;/a&gt; mentioned about needing to do what ArcGIS does was in fact the problem.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It appears that, when running the script inside ArcGIS, ArcGIS was using the on-the-fly projection of one of the classes.&amp;nbsp; I neglected to check that the spatial references were all the same before running the standalone script, which does not use on-the-fly projection.&lt;/P&gt;&lt;P&gt;tldr; I had to project all classes to the same spatial reference before selecting by location&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 14:05:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114054#M62892</guid>
      <dc:creator>JonathonRobert</dc:creator>
      <dc:date>2021-11-04T14:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114062#M62894</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/534507"&gt;@JonathonRobert&lt;/a&gt;&amp;nbsp;- I'm confused here: are you saying you did or did not use MakeFeatureLayer() in your stand alone script?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 14:18:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114062#M62894</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-11-04T14:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114067#M62895</link>
      <description>&lt;P&gt;After making sure everything was projected to the same spatial reference, I did run it with the MakeFeatureLayer() method in the standalone script, and it worked.&amp;nbsp; I then ran it again without calling the MakeFeatureLayer() method, and got the same (working) output.&amp;nbsp; So it appears to me that the issue was non-matching spatial references&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 14:31:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114067#M62895</guid>
      <dc:creator>JonathonRobert</dc:creator>
      <dc:date>2021-11-04T14:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114083#M62900</link>
      <description>&lt;P&gt;Thanks for sharing all the details Jonathon, this is useful info!&lt;/P&gt;&lt;P&gt;I think it is the case in ArcMap that these tools will not work at all correctly unless you have the inputs in the same coordinate system, and have always taught my students to have the inputs in the same CS before doing a Select Layer By Location.&lt;/P&gt;&lt;P&gt;If you are up to trying something else, I wonder if setting the arcpy.env.outputCoordinateSystem would help with your standalone script if your inputs are different coordinate systems. I think I'd rather take your approach though to avoid surprises. (Sometimes we should not tempt fate.)&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 15:02:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114083#M62900</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-11-04T15:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Location works in ArcGIS Pro Python window but not standalone</title>
      <link>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114084#M62901</link>
      <description>&lt;P&gt;Interesting...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 15:02:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/re-select-layer-by-location-works-in-arcgis-pro/m-p/1114084#M62901</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-11-04T15:02:09Z</dc:date>
    </item>
  </channel>
</rss>

