<?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: Issue with basic field mappings for spatial join in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446896#M35066</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would avoid using mdbs at all costs. You will run into nothing but trouble unless you need them for a very specific purpose. That may or may not be the cause of your current issues but it is a good place to start.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Sep 2013 14:31:26 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2013-09-10T14:31:26Z</dc:date>
    <item>
      <title>Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446890#M35060</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;My script is working except the field mappings. When I remove that parameter from the spatial join, it runs fine (but doesn't include the desired field in the output). When I add the fieldMappings parameter to the spatial join, the script throws the beloved ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thus, I know the problem isolated to how I am imputing the fieldMappings parameter which also makes me believe it is a basic misunderstanding on my part regarding how to utilize field mappings. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a code snippet of the issue:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
mapFields = ["ITEM_ID", "PRIME_GEO"]
fieldMappings = arcpy.FieldMappings()
for mapField in mapFields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap = arcpy.FieldMap()
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap.addInputField(aoi, mapField)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMappings.addFieldMap(fieldMap)

arcpy.SpatialJoin_analysis(aoi, "buildingLyr", buildingOutput, "JOIN_ONE_TO_ONE", "KEEP_COMMON", fieldMappings, "COMPLETELY_WITHIN", "", "")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS. Of the two tables involved in the join, I only really need to retain the ITEM_ID (and resulting count) field after the join. If there is a better way to do this than field mapping, please share your idea!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 13:26:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446890#M35060</guid>
      <dc:creator>DanielGermroth</dc:creator>
      <dc:date>2013-09-10T13:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446891#M35061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have to admit I have never done a spatial join with field mapping but looking at the &lt;/SPAN&gt;&lt;STRONG&gt;Help&lt;/STRONG&gt;&lt;SPAN&gt; file it appears you create a fieldMappings object then add the tables. In your code you are not doing this, may be this is the source of the error?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 13:41:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446891#M35061</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2013-09-10T13:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446892#M35062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the input! I also have never used field mappings before which is why I have a hunch I am making a laughably simple mistake. I have scoured every help file and blog post relating to the subject and still have come up empty.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;addTable was a good tip, but I am still getting the 999999 error. Back to the drawing board for me!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 14:08:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446892#M35062</guid>
      <dc:creator>DanielGermroth</dc:creator>
      <dc:date>2013-09-10T14:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446893#M35063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your code works for me. Are you sure the two fields exist in your source table?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 14:10:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446893#M35063</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-09-10T14:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446894#M35064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If it helps, here is how my fields come mapped out of model builder:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
##arcpy.SpatialJoin_analysis(AOI, BUILDING_P_-_StructurePnt, v_CC__AOI_build, "JOIN_ONE_TO_ONE", "KEEP_COMMON", "ITEM_ID \"ITEM_ID\" true true false 150 Text 0 0 ,First,#,C:\\Users\\\\Documents\\Units.mdb\\AOI,ITEM_ID,-1,-1", "INTERSECT", "", "")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:57:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446894#M35064</guid>
      <dc:creator>DanielGermroth</dc:creator>
      <dc:date>2021-12-11T19:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446895#M35065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Your code works for me. Are you sure the two fields exist in your source table?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wow- after reading your post, I closed down ArcMap and my python editor, reopened Arc, ran it and it worked. And even better, it worked as desired! Normally I like to follow up with what fixed the issue, but I don't think I can in this case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you all for taking the time to read the thread.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 14:30:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446895#M35065</guid>
      <dc:creator>DanielGermroth</dc:creator>
      <dc:date>2013-09-10T14:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446896#M35066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would avoid using mdbs at all costs. You will run into nothing but trouble unless you need them for a very specific purpose. That may or may not be the cause of your current issues but it is a good place to start.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 14:31:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446896#M35066</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-09-10T14:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446897#M35067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is the complete section of code just in case it helps anyone in the future:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

#Create field map for spatial joins
arcpy.AddMessage("Mapping fields for future use in iteration")
mapFields = ["ITEM_ID", "PRIME_GEO"]
fieldMappings = arcpy.FieldMappings()
for mapField in mapFields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap = arcpy.FieldMap()
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap.addInputField(aoi, mapField)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMappings.addFieldMap(fieldMap)


#Begin iterations for each country
arcpy.AddMessage("Beginning loop")
for country in countries:
&amp;nbsp;&amp;nbsp;&amp;nbsp; cc = str(countries&lt;N&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Feed in featureclasses
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Reading input featureclasses into in-memory layers")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(countryGdbLTDS + "/StructurePnt", "buildingLyr", dqBuilding)&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; #define output location for temp building tables
&amp;nbsp;&amp;nbsp;&amp;nbsp; buildingOutput = scratch + "/" + cc + "_AOI_Building"


&amp;nbsp;&amp;nbsp;&amp;nbsp; #Spatially join buildings
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Testing for existing building output files. Any found will be deleted")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(buildingOutput):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(buildingOutput)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Deleted")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Performing Spatial join on Building points")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SpatialJoin_analysis(aoi, "buildingLyr", buildingOutput, "JOIN_ONE_TO_ONE", "KEEP_COMMON", fieldMappings,"INTERSECT", "", "")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("None Found to delete")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Performing Spatial join on Building points")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SpatialJoin_analysis(aoi, "buildingLyr", buildingOutput, "JOIN_ONE_TO_ONE", "KEEP_COMMON", fieldMappings, "INTERSECT", "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; appendList.append(buildingOutput)

&lt;/N&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:58:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446897#M35067</guid>
      <dc:creator>DanielGermroth</dc:creator>
      <dc:date>2021-12-11T19:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with basic field mappings for spatial join</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446898#M35068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I would avoid using mdbs at all costs. You will run into nothing but trouble unless you need them for a very specific purpose. That may or may not be the cause of your current issues but it is a good place to start.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I agree completely. Unfortunately my company for uses them far too much for data storage and querying (and haven't upgraded the old data to gdbs) so I have to adapt to it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 14:37:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-basic-field-mappings-for-spatial-join/m-p/446898#M35068</guid>
      <dc:creator>DanielGermroth</dc:creator>
      <dc:date>2013-09-10T14:37:17Z</dc:date>
    </item>
  </channel>
</rss>

