<?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 - looping with arcpy - order issues of join_count fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565939#M44340</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you get the same results saving to a feature class rather than geometry objects? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Feb 2016 17:02:39 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2016-02-16T17:02:39Z</dc:date>
    <item>
      <title>Spatial Join - looping with arcpy - order issues of join_count fields</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565936#M44337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I developed a python script where the user can enter&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;a polygon shapefile&lt;/LI&gt;&lt;LI&gt;multiple point shapefiles&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;and within the script the polygon shapefile is divided into 1000mx1000m grid cells and then the point shapefiles are joined to the polygon within a for loop, where the intersecting points per cell are counted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tested the code and everything was fine, but now I detected a huge issue. The order of the added join count fields (Join_Count, Join_Cou_1, Join_Cou_2, etc.) does not correspond to the order in which the point shapefiles were entered. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below the input order and output order can be seen. I tried it multiple times, but it seems there is no logic behind the order, so not alphabetical, Input order, reverse order, or anything. It seems like it would be ordered randomly. &lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Bank -&amp;gt; Join_Count (Bank)&lt;/LI&gt;&lt;LI&gt;Kino -&amp;gt; Join_Cou_1 (Post)&lt;/LI&gt;&lt;LI&gt;Park -&amp;gt; Join_Cou_2 (Park)&lt;/LI&gt;&lt;LI&gt;Post -&amp;gt; Join_Cou_3 (Kino)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why can this happen? Shouldn't the first point shapefile which is joined first, get the Join_Count field, the second point shapefile that is joined next, the Join_Cou_1 field and so on?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="kwd"&gt;import&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy
studyarea &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;GetParameterAsText&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; 
inputPoints &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;GetParameterAsText&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
outputLocation &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;GetParameterAsText&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;2&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; 

arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;GridIndexFeatures_cartography&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str"&gt;'in_memory\studyarea_grid'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; studyarea&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'INTERSECTFEATURE'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'NO_USEPAGEUNIT'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;"#"&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;1000&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;1000&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
studyAreaGrid &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;Clip_analysis&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str"&gt;'in_memory\studyarea_grid'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; studyarea&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;Polygon&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;

inputPoints_set &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; inputPoints&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;split&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str"&gt;';'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; 

spatialJoin &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; studyAreaGrid
&lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;for&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; pointShp &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;in&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; inputPoints_set&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; spatialJoin &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;SpatialJoin_analysis&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;spatialJoin&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; pointShp&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;Polygon&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'JOIN_ONE_TO_ONE'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'KEEP_ALL'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;''&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'INTERSECT'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&lt;/SPAN&gt;&lt;/CODE&gt;
&lt;SPAN class="pln"&gt;&lt;/SPAN&gt;
&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;a&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;rcpy&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;CopyFeatures_management&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;spatialJoin&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; outputLocation&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:23:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565936#M44337</guid>
      <dc:creator>MilenaKocher</dc:creator>
      <dc:date>2021-12-12T00:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join - looping with arcpy - order issues of join_count fields</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565937#M44338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just taking a stab here. It's possible this is incorrect, i'm not familiar with using a arcpy.polygon as an output.&lt;/P&gt;&lt;P&gt;Is it possible you are overwriting your output with each iteration rather than adding to it? Wouldn't you need the output of the first iteration to become the input of the second and so on.. to me it doesnt look like this is happening. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, i could be wrong. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ben&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Feb 2016 13:43:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565937#M44338</guid>
      <dc:creator>BenjaminMittler</dc:creator>
      <dc:date>2016-02-16T13:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join - looping with arcpy - order issues of join_count fields</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565938#M44339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/python/mapping-fields.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/analyze/python/mapping-fields.htm"&gt;Mapping input fields to output fields—Help | ArcGIS for Desktop&lt;/A&gt; to create your own fields you could then do your counts&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Feb 2016 13:54:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565938#M44339</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-02-16T13:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join - looping with arcpy - order issues of join_count fields</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565939#M44340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you get the same results saving to a feature class rather than geometry objects? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Feb 2016 17:02:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565939#M44340</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2016-02-16T17:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join - looping with arcpy - order issues of join_count fields</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565940#M44341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;random order in the appearance, suggests that the results are being stored in a dictionary rather than in a list.&amp;nbsp; Unless there is some key in the dictionary to guarantee first-in-first out, then sorting this will be difficult/awkward.&amp;nbsp; Note the order of the dictionary outputs is not the same as the inputs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ie&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; d = {"a": 1, "b": 2, "c": 3}
&amp;gt;&amp;gt;&amp;gt; d
{'b': 2, 'a': 1, 'c': 3}
&amp;gt;&amp;gt;&amp;gt; d.keys()
dict_keys(['b', 'a', 'c'])
&amp;gt;&amp;gt;&amp;gt; d.items()
dict_items([('b', 2), ('a', 1), ('c', 3)])
&amp;gt;&amp;gt;&amp;gt; d.values()
dict_values([2, 1, 3])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:23:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565940#M44341</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T00:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join - looping with arcpy - order issues of join_count fields</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565941#M44342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The OP's script isn't copying the results into a list of geometry objects, it is creating in-memory feature classes.&amp;nbsp; I will elaborate in a comment to the OP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Feb 2016 19:59:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565941#M44342</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-02-17T19:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join - looping with arcpy - order issues of join_count fields</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565942#M44343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't mind me asking, what do you think the use of &lt;SPAN style="font-family: courier new,courier;"&gt;arcpy.Polygon&lt;/SPAN&gt; is accomplishing in this script?&amp;nbsp; If the goal is to have the tool create a unique path and name for the output, the standard or best practice is to use either &lt;SPAN style="font-family: courier new,courier;"&gt;"#"&lt;/SPAN&gt; or &lt;SPAN style="font-family: courier new,courier;"&gt;None&lt;/SPAN&gt; (See &lt;A href="http://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/using-tools-in-python.htm#ESRI_SECTION1_4BF92292703248F09479E3D45CB23904"&gt;Tool Output &lt;/A&gt;section in &lt;A href="http://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/using-tools-in-python.htm"&gt;Using tools with Python&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even though the output from the &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/clip.htm"&gt;Clip &lt;/A&gt;tool can be a Python list of geometry objects (using &lt;SPAN style="font-family: courier new,courier;"&gt;arcpy.Geometry()&lt;/SPAN&gt; , not &lt;SPAN style="font-family: courier new,courier;"&gt;arcpy.Geometry&lt;/SPAN&gt;) , I don't know whether doing so will work for later processing in the script.&amp;nbsp; So, I recommend staying with feature classes as the outputs and using one of the standard methods for auto generating unique names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have you tried using &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/getparameter.htm"&gt;GetParameter &lt;/A&gt;instead of &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/getparameterastext.htm"&gt;GetParameterAsText&lt;/A&gt;?&amp;nbsp; I don't know why it should/would make a difference but maybe getting the parameters back as objects might be more predictable than what you are seeing getting them back as text.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Feb 2016 20:25:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-looping-with-arcpy-order-issues-of/m-p/565942#M44343</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-02-17T20:25:01Z</dc:date>
    </item>
  </channel>
</rss>

