<?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: Spatial Join in Model Builder (Field Map) in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23305#M802</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Dan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that doesn´t sound very promising. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you solve your problem with a python script? If yes, could you please provide a sample?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Unforntunately I´m just a beginner in python programming.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Dec 2011 04:38:02 GMT</pubDate>
    <dc:creator>MartinScheiber</dc:creator>
    <dc:date>2011-12-08T04:38:02Z</dc:date>
    <item>
      <title>Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23303#M800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey everybody,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a problem, I need some help with. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to create an automated process in Model Builder that, beside other things, does a spatial join from a point to a polygon dataset. Once it´s finished, I want it to run with different datasets specified by the user.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the Spatial Join tool I want to pre-specify a field map with join features. I want to calculate the MEAN and the STANDARD DEVIATION of point data fields. The process works fine, as long as I have input datasets specified. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that once I create Variables and Model Parameters and remove the original input datasets, the field map in the Spatial Join tool is getting deleted. Is there any possbility to keep the pre-defined field map?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please refer to the attached screenshots for further information.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Dec 2011 08:30:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23303#M800</guid>
      <dc:creator>MartinScheiber</dc:creator>
      <dc:date>2011-12-07T08:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23304#M801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: DanEvans83&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've had the same problem and asked about it several times here without a reply &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think it can only be done in a python script. Bit crap really.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Dec 2011 09:41:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23304#M801</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-12-07T09:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23305#M802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Dan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that doesn´t sound very promising. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you solve your problem with a python script? If yes, could you please provide a sample?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Unforntunately I´m just a beginner in python programming.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2011 04:38:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23305#M802</guid>
      <dc:creator>MartinScheiber</dc:creator>
      <dc:date>2011-12-08T04:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23306#M803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: DanEvans83&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Martin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I never did get it working in Python. All the documentation and tutorials for ArcGIS scripting seem to assume you're already a master programmer unfortunately. I'm not completely inexperienced in programming (started with BASIC when I was about 7, done bits and pieces of C++ on and off over the years, and worked as a web developer using PHP for over a year) but I just haven't found a good way in to this Python scripting stuff.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the idea is roughly that you'd create and populate a fieldmappings object programmatically and pass that as a parameter to the spatial join command... But I never quite got my head around how to set things up right (like environment settings) so that it'll work with any appropriate input, how to check for invalid inputs, how to correctly program the paths to the intermediate data so it'll work properly wherever the data is located....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I'd had more time I might have got it, but the process in question is only done once or twice a year. I think in the end I split the process into three parts and ran a model with specified inputs for each part, which saved a bit of time compared to doing it all manually.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Very frustrating.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2011 07:44:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23306#M803</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-12-08T07:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23307#M804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dan: Thank you very much for your answer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could someone from ESRI please help clarifying if there is an easier solution, or maybe provide a script example in case there isn´t?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be highly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Dec 2011 04:33:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23307#M804</guid>
      <dc:creator>MartinScheiber</dc:creator>
      <dc:date>2011-12-12T04:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23308#M805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: Clockwise&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the script tool attached below will allow you to do this. If not I hope it will help you figure out how to get what you are looking for. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(I've also put inserted the code for the script below)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From your description I have assumed that the preset field names are not going to be changing for your inputs and that they don't need to be changed in the model. However, you can change them in the script itself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The script is also written for ArcMap 10. If you are using an older version of ArcMap the code will probably have to be changed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you download the script most of it is already setup. The script and toolbox just need to be extracted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Or you can copy the code and setup the tool yourself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the script, prior to use, you will have to change the outputFields list to tell the script which field names you want in your output. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;outputFields = ("fieldname1","fieldname2")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I tested the script I noticed the output seemed to add some general join information to the attribute table too. I didn't set the code up to remove the fields because I wasn't sure if you wanted that information or not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once you set up your list you should be able to add the tool to your model and use it like any other tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps. : )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

# Manually specify the desired fieldnames here
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

outputFields = ("fieldname1","fieldname2")

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#Get input parameters from user/model 
targetFeature = arcpy.GetParameterAsText(0)
joinFeature = arcpy.GetParameterAsText(1)
outputFeature = arcpy.GetParameterAsText(2)

#Create Fieldmappings and add tables from input
tempMappings = arcpy.FieldMappings()
tempMappings.addTable(targetFeature)
tempMappings.addTable(joinFeature)

#Create new fieldmappings using the listed fields, from the current(temp) fieldmappings.&amp;nbsp; 
fieldMappings = arcpy.FieldMappings()
for field in outputFields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMappings.addFieldMap(tempMappings.getFieldMap(tempMappings.findFieldMapIndex(field)))

#Process: Spatial Join
#(note: you can change how the join works on this line)
arcpy.SpatialJoin_analysis(targetFeature, joinFeature, outputFeature, "JOIN_ONE_TO_ONE", "KEEP_ALL", fieldMappings, "INTERSECT")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:57:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23308#M805</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-10T20:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23309#M806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Benjamin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that sounds promising. Thanks a lot for the Python Script. I´ll give it a try.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Feb 2012 07:18:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23309#M806</guid>
      <dc:creator>MartinScheiber</dc:creator>
      <dc:date>2012-02-03T07:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join in Model Builder (Field Map)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23310#M807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jmork045&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This script works well, but is there any way that you can extract field names as params and then use them for FieldMappings? I have tried to set outputFields to these params, but it will not work with the tool. I am not sure exactly how the list of fields is converted into text, so it is difficult to work with them. Ideally, if i could use all of the fields that the user selects as params and put them into the outputFields in the same format as in the script that would be great. Any help would be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2012 17:15:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/spatial-join-in-model-builder-field-map/m-p/23310#M807</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2012-10-23T17:15:40Z</dc:date>
    </item>
  </channel>
</rss>

