<?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 by Layer by Location Returns Different Values between Pro and Python in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-layer-by-location-returns-different/m-p/1368851#M77255</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you are counting the entire feature in line 28 and also using it to run the calculate field in line 33.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try to make a feature layer and use it to select and calculate:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import sys, arcpy, traceback
try:
    # set workspace
    arcpy.env.workspace = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb"

    # set variables
    snow_routes = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\LOCAL_Snow_Routes"
    snow_plows = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\LOCAL_Verizon_Vehicles"
    export_class = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\SnowPlows_Export"

    # check if export class exists
        #if exists delete
    print("Checking for existing export class...")
    if arcpy.Exists(export_class):
        arcpy.Delete_management(export_class)
        print("Existing export class deleted.")

    # export points from snow plow class
    # arcpy.conversion.ExportFeatures(in_features, out_features, {where_clause}, {use_field_alias_as_name}, {field_mapping}, {sort_field})
    expression = "plowname IS NOT NULL"
    print("Running export on Snow Plow feature class...")
    arcpy.conversion.ExportFeatures(snow_plows, export_class, expression)
    print("Export completed.")
    
    # Make a Feature Layer
    arcpy.management.MakeFeatureLayer(snow_routes, "snow_routes_lyr")

    # run intersect on exported points w/ center lines
    print("Checking intersections...")
    arcpy.management.SelectLayerByLocation("snow_routes_lyr", "INTERSECT", export_class, '', 'NEW_SELECTION')
    theCount = int(arcpy.GetCount_management("snow_routes_lyr").getOutput(0))
    print(f"{theCount} features selected.")

    # calculate field of selected center lines
    print("Calculating field in the Snow Routes layer...")
    arcpy.management.CalculateField("snow_routes_lyr", "PlowStatus", 1, "PYTHON_3")
    print("Field calculated.")

    # delete export class
    arcpy.Delete_management(export_class)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jan 2024 17:07:56 GMT</pubDate>
    <dc:creator>PedroCoutinhoMendonça</dc:creator>
    <dc:date>2024-01-11T17:07:56Z</dc:date>
    <item>
      <title>Select by Layer by Location Returns Different Values between Pro and Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-layer-by-location-returns-different/m-p/1367543#M77102</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am currently working on writing a script that works in conjunction with a layer that tracks the locations of snow plows during snowy weather. For this we have a point feature class for the snow plows and a line feature class for streets. The basic idea is that the script will run a Select by Location, with the overlap type set to intersect, to select the street lines and run a Calculate Field to change the symbology. The main issue I'm dealing with currently is that the script returns a different number of selected features than what I get when I do a manual Select by Location. It seems that the script selects all of the features within the streets class and gives a result of 1,496. Whenever I do it by hand I get the correct number of 6. I am currently using local copies of both feature classes for testing purposes so I know that only 6 features should be selected. I am at a loss for why the script would be picking up all of the line features with the selection and any help would be appreciated.&amp;nbsp; Here is my script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import sys, arcpy, traceback
try:
    # set workspace
    arcpy.env.workspace = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb"

    # set variables
    snow_routes = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\LOCAL_Snow_Routes"
    snow_plows = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\LOCAL_Verizon_Vehicles"
    export_class = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\SnowPlows_Export"

    # check if export class exists
        #if exists delete
    print("Checking for existing export class...")
    if arcpy.Exists(export_class):
        arcpy.Delete_management(export_class)
        print("Existing export class deleted.")

    # export points from snow plow class
    # arcpy.conversion.ExportFeatures(in_features, out_features, {where_clause}, {use_field_alias_as_name}, {field_mapping}, {sort_field})
    expression = "plowname IS NOT NULL"
    print("Running export on Snow Plow feature class...")
    arcpy.conversion.ExportFeatures(snow_plows, export_class, expression)
    print("Export completed.")

    # run intersect on exported points w/ center lines
    print("Checking intersections...")
    arcpy.SelectLayerByLocation_management(snow_routes, "INTERSECT", export_class)
    theCount = int(arcpy.GetCount_management(snow_routes).getOutput(0))
    print(f"{theCount} features selected.")

    # calculate field of selected center lines
    print("Calculating field in the Snow Routes layer...")
    arcpy.management.CalculateField(snow_routes, "PlowStatus", 1, "PYTHON_3")
    print("Field calculated.")

    # delete export class
    arcpy.Delete_management(export_class)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 18:57:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-by-layer-by-location-returns-different/m-p/1367543#M77102</guid>
      <dc:creator>RemyShipman</dc:creator>
      <dc:date>2024-01-08T18:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Layer by Location Returns Different Values between Pro and Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-layer-by-location-returns-different/m-p/1367573#M77105</link>
      <description>&lt;P&gt;Does the ArcToolbox tools's&amp;nbsp; code (save as script) have anything different when compared to your version?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 19:54:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-by-layer-by-location-returns-different/m-p/1367573#M77105</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-01-08T19:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Layer by Location Returns Different Values between Pro and Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-layer-by-location-returns-different/m-p/1368851#M77255</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you are counting the entire feature in line 28 and also using it to run the calculate field in line 33.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try to make a feature layer and use it to select and calculate:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import sys, arcpy, traceback
try:
    # set workspace
    arcpy.env.workspace = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb"

    # set variables
    snow_routes = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\LOCAL_Snow_Routes"
    snow_plows = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\LOCAL_Verizon_Vehicles"
    export_class = r"G:\Projects\SnowPlow\SnowPlow\SnowPlow.gdb\SnowPlows_Export"

    # check if export class exists
        #if exists delete
    print("Checking for existing export class...")
    if arcpy.Exists(export_class):
        arcpy.Delete_management(export_class)
        print("Existing export class deleted.")

    # export points from snow plow class
    # arcpy.conversion.ExportFeatures(in_features, out_features, {where_clause}, {use_field_alias_as_name}, {field_mapping}, {sort_field})
    expression = "plowname IS NOT NULL"
    print("Running export on Snow Plow feature class...")
    arcpy.conversion.ExportFeatures(snow_plows, export_class, expression)
    print("Export completed.")
    
    # Make a Feature Layer
    arcpy.management.MakeFeatureLayer(snow_routes, "snow_routes_lyr")

    # run intersect on exported points w/ center lines
    print("Checking intersections...")
    arcpy.management.SelectLayerByLocation("snow_routes_lyr", "INTERSECT", export_class, '', 'NEW_SELECTION')
    theCount = int(arcpy.GetCount_management("snow_routes_lyr").getOutput(0))
    print(f"{theCount} features selected.")

    # calculate field of selected center lines
    print("Calculating field in the Snow Routes layer...")
    arcpy.management.CalculateField("snow_routes_lyr", "PlowStatus", 1, "PYTHON_3")
    print("Field calculated.")

    # delete export class
    arcpy.Delete_management(export_class)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 17:07:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-by-layer-by-location-returns-different/m-p/1368851#M77255</guid>
      <dc:creator>PedroCoutinhoMendonça</dc:creator>
      <dc:date>2024-01-11T17:07:56Z</dc:date>
    </item>
  </channel>
</rss>

