<?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: Add Spatial Join using Python in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1626100#M96822</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thank you, but the features are always directly connected.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jun 2025 09:57:41 GMT</pubDate>
    <dc:creator>Luca_Schikowski</dc:creator>
    <dc:date>2025-06-24T09:57:41Z</dc:date>
    <item>
      <title>Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624565#M96727</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I am currently trying to work with python in ArcGIS Pro and I am stuck with the "Add Spatial Join"-Tool.&lt;/P&gt;&lt;P&gt;I got point-features (households) and lines (ducts) connected to them. I want to transfer some of the attributes from the households to the ducts feature class.&lt;/P&gt;&lt;P&gt;So first, I need to da a spatial join, right?&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;P&gt;#code starts&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import sys&lt;BR /&gt;&lt;BR /&gt;def main():&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;BR /&gt;&lt;BR /&gt;ducts = arcpy.GetParameterAsText(0)&lt;BR /&gt;houses = arcpy.GetParameterAsText(1)&lt;BR /&gt;&lt;BR /&gt;try:&lt;BR /&gt;arcpy.AddMessage(f"Add Spatial Join:\n - Target-Layer: {ducts}\n - Join-Layer: {houses}")&lt;BR /&gt;&lt;BR /&gt;arcpy.management.AddSpatialJoin(&lt;BR /&gt;target_features=ducts,&lt;BR /&gt;join_features=houses,&lt;BR /&gt;join_operation='JOIN_ONE_TO_ONE',&lt;BR /&gt;join_type='KEEP_ALL',&lt;BR /&gt;field_mapping='CID',&lt;BR /&gt;match_option='INTERSECT'&lt;BR /&gt;)&lt;BR /&gt;arcpy.AddMessage("Spatial Join Added successfully.")&lt;BR /&gt;except Exception as e:&lt;BR /&gt;arcpy.AddError(f"Error at 'Add Spatial Join': {e}")&lt;BR /&gt;if __name__ == "__main__":&lt;BR /&gt;main()&lt;/P&gt;&lt;P&gt;#code ends&lt;/P&gt;&lt;P&gt;When running this code, I get all the messages correctly and the tool finishes successfully but there is no spatial join added to my feature class. Is there an error in my code?&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 07:07:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624565#M96727</guid>
      <dc:creator>Luca_Schikowski</dc:creator>
      <dc:date>2025-06-18T07:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624569#M96728</link>
      <description>&lt;P&gt;Hi Luca,&lt;/P&gt;&lt;P&gt;Unless your point features are exactly on the line features they won't intersect. I would try changing the match option from INTERSECT to CLOSEST. eg.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bryan_bsc_0-1750231989783.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134549iEDDE28A6736B9B3C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bryan_bsc_0-1750231989783.png" alt="Bryan_bsc_0-1750231989783.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Bryan&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 07:33:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624569#M96728</guid>
      <dc:creator>Bryan_bsc</dc:creator>
      <dc:date>2025-06-18T07:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624570#M96729</link>
      <description>&lt;P&gt;Is the first parameter to the tool (&lt;SPAN&gt;ducts) a layer in pro or a FC on disk?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It must be a layer in Pro since the spatial join is on a layer and not on the real data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can always use the Gp tool once and then copy the code from the History window.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 07:33:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624570#M96729</guid>
      <dc:creator>ModyBuchbinder</dc:creator>
      <dc:date>2025-06-18T07:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624786#M96740</link>
      <description>&lt;P&gt;Whenever you do anything involving a join or a selection on data, you need to make it a variable. otherwise, all the work gets done and then thrown into the ether.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;This is my code:

#code starts

import arcpy
import sys

def main():
arcpy.env.overwriteOutput = True

ducts = arcpy.GetParameterAsText(0)
houses = arcpy.GetParameterAsText(1)

try:
arcpy.AddMessage(f"Add Spatial Join:\n - Target-Layer: {ducts}\n - Join-Layer: {houses}")

sjoin = arcpy.management.AddSpatialJoin(
target_features=ducts,
join_features=houses,
join_operation='JOIN_ONE_TO_ONE',
join_type='KEEP_ALL',
field_mapping='CID',
match_option='INTERSECT'
)
arcpy.AddMessage("Spatial Join Added successfully.")
except Exception as e:
arcpy.AddError(f"Error at 'Add Spatial Join': {e}")
if __name__ == "__main__":
main()

#code ends&lt;/LI-CODE&gt;&lt;P&gt;You might have to add some lines telling it to actually add to the map, but I'd start with naming it and see what happens.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 19:27:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1624786#M96740</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-06-18T19:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1626099#M96821</link>
      <description>&lt;P&gt;Hi, thank you!&lt;BR /&gt;&lt;BR /&gt;When running your code, an error occurs:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Luca_Schikowski_0-1750757678771.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/134914iFE62A71EC7326961/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Luca_Schikowski_0-1750757678771.png" alt="Luca_Schikowski_0-1750757678771.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I could not find the reason for this error. After some research it seems to be a syntax error. But why?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2025 09:55:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1626099#M96821</guid>
      <dc:creator>Luca_Schikowski</dc:creator>
      <dc:date>2025-06-24T09:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1626100#M96822</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thank you, but the features are always directly connected.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2025 09:57:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1626100#M96822</guid>
      <dc:creator>Luca_Schikowski</dc:creator>
      <dc:date>2025-06-24T09:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1626101#M96823</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;so the code will only work, when the feature classes are actually added to the map in arc gis pro, right?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2025 10:04:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1626101#M96823</guid>
      <dc:creator>Luca_Schikowski</dc:creator>
      <dc:date>2025-06-24T10:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1629532#M97000</link>
      <description>&lt;P&gt;Hi Luca&lt;/P&gt;&lt;P&gt;I'm not sure you managed to solve your spatial join problem? But what i do if i have a tool which doesn't work in a Python script is:&lt;/P&gt;&lt;P&gt;1: Find the tool e.g. Spatial Join, in the &lt;EM&gt;Geoprocessing&lt;/EM&gt; pane&lt;/P&gt;&lt;P&gt;2: Run the tool using my inputs that I wish to pass into it from my Python script.&lt;/P&gt;&lt;P&gt;This generates a &lt;EM&gt;History item.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;3: Display the &lt;EM&gt;History&lt;/EM&gt; pane and locate your successful execution of the tool.&lt;/P&gt;&lt;P&gt;4: Double click the tool to display the tool's geoprocessing pane containing the parameter choices you made which ensured the successful run.&lt;/P&gt;&lt;P&gt;5: Click the dropdown arrow to the right of the pane's Run button and choose Copy Python Snippet.&lt;/P&gt;&lt;P&gt;This copies the Python code which ran the tool.&lt;/P&gt;&lt;P&gt;6: Paste the Python snippet into your script.&lt;/P&gt;&lt;P&gt;7: Change the hard-coded values generated by the Python snippet for your inputs, matching the data types.&lt;/P&gt;&lt;P&gt;Hopefully that should do the trick!&lt;/P&gt;&lt;P&gt;Have a look here for a more indepth discussion about various techniques you can use to get ArcGIS Pro to wrute Python code for you:&lt;/P&gt;&lt;P&gt;&lt;A href="https://epjmorris.wordpress.com/2025/05/29/a-simple-way-to-get-arcgis-pro-to-write-arcpy-geoprocessing-python-code/" target="_blank" rel="noopener"&gt;A simple way to get ArcGIS Pro to write arcpy geoprocessing python code&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps you out.&lt;/P&gt;&lt;P&gt;Let me know how you get on.&lt;/P&gt;&lt;P&gt;thanks ed&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 17:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1629532#M97000</guid>
      <dc:creator>EdMorris</dc:creator>
      <dc:date>2025-07-02T17:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add Spatial Join using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1630678#M97053</link>
      <description>&lt;P&gt;Oh, that's my fault, sorry.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#code starts

import arcpy
import sys

def main():
    arcpy.env.overwriteOutput = True

    ducts = arcpy.GetParameterAsText(0)
    houses = arcpy.GetParameterAsText(1)

try:
    arcpy.AddMessage(f"Add Spatial Join:\n - Target-Layer: {ducts}\n - Join-Layer: {houses}")

    sjoin = arcpy.management.AddSpatialJoin(
    target_features=ducts,
    join_features=houses,
    join_operation='JOIN_ONE_TO_ONE',
    join_type='KEEP_ALL',
    field_mapping='CID',
    match_option='INTERSECT'
    )
    arcpy.AddMessage("Spatial Join Added successfully.")
except Exception as e:
    arcpy.AddError(f"Error at 'Add Spatial Join': {e}")
if __name__ == "__main__":
    main()

#code ends&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Any time you have a colon, the next lines have to be indented.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 15:07:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/add-spatial-join-using-python/m-p/1630678#M97053</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-07-07T15:07:28Z</dc:date>
    </item>
  </channel>
</rss>

