<?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: Create pairs of points in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730515#M56672</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Brilliant! That makes the code much simpler. Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Jun 2012 21:18:36 GMT</pubDate>
    <dc:creator>AdamForknall</dc:creator>
    <dc:date>2012-06-05T21:18:36Z</dc:date>
    <item>
      <title>Create pairs of points</title>
      <link>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730511#M56668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to create pairs of point features from a point dataset. I'm not really sure on how to get my for loops working to create only 1 instance of each pair.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; For example if I have points &lt;/SPAN&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;STRONG&gt; B&lt;/STRONG&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;STRONG&gt; C&lt;/STRONG&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;STRONG&gt;D&lt;/STRONG&gt;&lt;SPAN&gt;, the final pairs would be &lt;/SPAN&gt;&lt;STRONG&gt;AB&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;AC&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;AD&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;BC&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;BD &lt;/STRONG&gt;&lt;SPAN&gt;&amp;amp; &lt;/SPAN&gt;&lt;STRONG&gt;CD&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; My script in its current state is below - this will print all pairs twice except for those containing the first point in the list, which are only printed once. (I hope that makes sense!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The ultimate aim is to create a table with XY co-ordinates or geometries of each pair, but at this stage I'm just printing the pairs to screen for checking. I'm a complete python (and programming in general) novice and I'd be really grateful if someone could give me so tips on how to make this happen.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Adam&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; infc =r"D:\POINTS.shp"&amp;nbsp; #identify geometry field desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName&amp;nbsp; #Create primary Search Cursor rows = arcpy.SearchCursor(infc)&amp;nbsp; pointsList = []&amp;nbsp;&amp;nbsp; count = 0 #iterator counter for testing&amp;nbsp; #create a list of the points for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; feat = row.getValue(shapefieldname) &amp;nbsp;&amp;nbsp;&amp;nbsp; point = feat.getPart() &amp;nbsp;&amp;nbsp;&amp;nbsp; pointsList.append(point)&amp;nbsp; count = 0&amp;nbsp; for point1 in pointsList: &amp;nbsp;&amp;nbsp;&amp;nbsp; #print point1.X &amp;nbsp;&amp;nbsp;&amp;nbsp; for point2 in pointsList[1:]: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if point1 != point2: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print (point1,point2)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 Jun 2012 23:14:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730511#M56668</guid>
      <dc:creator>AdamForknall</dc:creator>
      <dc:date>2012-06-03T23:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create pairs of points</title>
      <link>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730512#M56669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Modify the last loop as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# make a duplicate of the original point list
tempPointList = pointList[:]

for point1 in pointsList:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # remove the current point from the temp list
&amp;nbsp;&amp;nbsp;&amp;nbsp; tempPointList.remove(point1)

&amp;nbsp;&amp;nbsp;&amp;nbsp; for point2 in tempPointList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # point1 and point2 to make a pair
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print (point1.X, point2.X)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:11:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730512#M56669</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2021-12-12T07:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create pairs of points</title>
      <link>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730513#M56670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Genius!&lt;/STRONG&gt;&lt;SPAN&gt; Thanks Nobbir!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jun 2012 21:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730513#M56670</guid>
      <dc:creator>AdamForknall</dc:creator>
      <dc:date>2012-06-04T21:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create pairs of points</title>
      <link>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730514#M56671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Looks like a simpler and better solution already exists in the standard module (pointed out by Jason Scheirer of Esri Geoprocessing team).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# itertools standard module's combinations function does it clearly import itertools&amp;nbsp; for point1, point2 in itertools.combinations(pointsList, 2): &amp;nbsp;&amp;nbsp; print point1.X, point2.X&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is no need to create a duplicate list and iterate over two lists.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2012 05:55:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730514#M56671</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2012-06-05T05:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create pairs of points</title>
      <link>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730515#M56672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Brilliant! That makes the code much simpler. Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2012 21:18:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-pairs-of-points/m-p/730515#M56672</guid>
      <dc:creator>AdamForknall</dc:creator>
      <dc:date>2012-06-05T21:18:36Z</dc:date>
    </item>
  </channel>
</rss>

