<?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: Looping through XYZ coordinats in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167912#M64415</link>
    <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; this well get the job done. I did a test and its working on the dataset.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2022 13:52:06 GMT</pubDate>
    <dc:creator>Daniel4</dc:creator>
    <dc:date>2022-04-26T13:52:06Z</dc:date>
    <item>
      <title>Looping through XYZ coordinats</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167718#M64393</link>
      <description>&lt;P&gt;Hi, I working on a road dataset and found all the roads that intersect, like the to roads below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dabrso_0-1650917273690.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/39817iB17FB0D0475CFE3F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dabrso_0-1650917273690.png" alt="dabrso_0-1650917273690.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to investigate if the z-value from the two roads are the same. I used&amp;nbsp;arcpy.FeatureVerticesToPoints_management the get the XYZ values from each road, and load them into two python list, like in the example below:&lt;/P&gt;&lt;P&gt;road1 = [(1,2,3),(3,4,5),(4,6,8)]&lt;BR /&gt;road2 = [(3,4,6),(1,2,4),(4,5,3)]&lt;/P&gt;&lt;P&gt;The first think I want to do, is to check whatever the roads share&amp;nbsp;vertices (Same XY value) and if the do, whats the difference in their z-value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried with this function:&lt;/P&gt;&lt;P&gt;def compareLineVertiex(list_orginid,list_destid):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sameXY = []&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for (x,y,z) in list_orginid:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xy = x,y&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if xy in list_destid:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sameXY.append(xyz)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return sameXY&lt;/P&gt;&lt;P&gt;I only managed to compare their XY values. I am missing the z-value (which will be difference from the two list)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 20:34:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167718#M64393</guid>
      <dc:creator>Daniel4</dc:creator>
      <dc:date>2022-04-25T20:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through XYZ coordinats</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167731#M64396</link>
      <description>&lt;P&gt;Maybe a little long but how's this&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def compare_vertices(linea, lineb):
    matches = []
    for i_idx, a in enumerate(linea):
        for b_idx, b in enumerate(lineb):
            if [a[0], a[1]] == [b[0], b[1]]:
                if a[2] - b[2] &amp;gt; 0:
                    zdiff = a[2] - b[2]
                else:
                    zdiff = b[2] - a[2]
                matches.append({
                    "Point A": {
                        "XYZ": a,
                        "Index": a_idx,
                    },
                    "Point B": {
                        "XYZ": b,
                        "Index": b_idx,
                    },
                    "Z diff": zdiff
                })
    return matches

road1 = [(1, 2, 3), (3, 4, 5), (4, 6, 8)]
road2 = [(3, 4, 6), (1, 2, 4), (4, 5, 3)]

x = compare_vertices(road1, road2)

for i in x:
    print(i)

{'Point A': {'XYZ': (1, 2, 3), 'Index': 0}, 'Point B': {'XYZ': (1, 2, 4), 'Index': 1}, 'Z diff': 1}
{'Point A': {'XYZ': (3, 4, 5), 'Index': 1}, 'Point B': {'XYZ': (3, 4, 6), 'Index': 0}, 'Z diff': 1}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only enumerated to know where the points are that match in the array, and returned as a dict because I'm fussy like that and want more info than less usually&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 21:11:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167731#M64396</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-04-25T21:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through XYZ coordinats</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167776#M64412</link>
      <description>&lt;P&gt;numpy anyone?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;road1 = np.array([(1, 2, 3), (3, 4, 5), (4, 6, 8)])
road2 = np.array([(3, 4, 6), (1, 2, 4), (4, 5, 3)])

xyz = []
for row in road1:
    x, y, z1 = row
    chk = (road2[:, :2][:, None] == row[:2]).all(-1)
    if chk.any():
        w = np.nonzero(chk)[0]
        z2 = road2[w].squeeze()
        vals = [x, y, z1, z2[-1]]
        xyz.append(vals)
    xyz1z2 = np.array(xyz)
    

xyz1z2
array([[1, 2, 3, 4],
       [3, 4, 5, 6]])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To bring it back into Pro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;dt = [('X', 'f8'), ('Y', 'f8'), ('Z1', 'f8'), ('Z2', 'f8')]

# -- do it the slow way
out = np.zeros(xyz1z2.shape[0], dtype=dt)
out['X'] = xyz1z2[:, 0]
out['Y'] = xyz1z2[:, 1]
out['Z1'] = xyz1z2[:, 2]
out['Z2'] = xyz1z2[:, 3]
out
array([(  1.00,   2.00,   3.00,   4.00), (  3.00,   4.00,   5.00,   6.00)],
      dtype=[('X', '&amp;lt;f8'), ('Y', '&amp;lt;f8'), ('Z1', '&amp;lt;f8'), ('Z2', '&amp;lt;f8')])
# --- then
arcpy.da.NumPyArrayToTable(out, path_and_tbl_name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 00:09:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167776#M64412</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-04-26T00:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through XYZ coordinats</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167912#M64415</link>
      <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; this well get the job done. I did a test and its working on the dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 13:52:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167912#M64415</guid>
      <dc:creator>Daniel4</dc:creator>
      <dc:date>2022-04-26T13:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through XYZ coordinats</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167914#M64416</link>
      <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I will try it out.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 13:55:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-xyz-coordinats/m-p/1167914#M64416</guid>
      <dc:creator>Daniel4</dc:creator>
      <dc:date>2022-04-26T13:55:21Z</dc:date>
    </item>
  </channel>
</rss>

