<?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: XY Coordinates to Structured NumPy Array in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45655#M3625</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the following, its truly appreciated, I had not idea it would be that easy to create the Structured NumPy Array. I'm going to be using the following a lot in the future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Peter Wilson&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Mar 2015 07:30:57 GMT</pubDate>
    <dc:creator>PeterWilson</dc:creator>
    <dc:date>2015-03-13T07:30:57Z</dc:date>
    <item>
      <title>XY Coordinates to Structured NumPy Array</title>
      <link>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45653#M3623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Background:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've used the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00080000001q000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Near Analysis&lt;/A&gt; tool which has added the following fields:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;NEAR_X (X Coordinate)&lt;/LI&gt;&lt;LI&gt;NEAR_Y (Y Coordinate)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to use the following fields from the output of using the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00080000001q000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Near Analysis&lt;/A&gt; tool to generate a &lt;A href="http://docs.scipy.org/doc/numpy/user/basics.rec.html" rel="nofollow noopener noreferrer" target="_blank"&gt;Structured NumPy Array&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;HydroID (Unique ID: Long Integer)&lt;/LI&gt;&lt;LI&gt;NEAR_X (X Coordinate)&lt;/LI&gt;&lt;LI&gt;NEAR_Y (Y Coordinate)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've read through the ESRI online help documentation on:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="http://resources.arcgis.com/en/heLP/MAIN/10.2/index.html#//002z00000028000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Working with NumPy in ArcGIS&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="http://resources.arcgis.com/en/heLP/MAIN/10.2/index.html#//018w00000018000000" rel="nofollow noopener noreferrer" target="_blank"&gt;TableToNumPyArray&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;, and I'm unable to figure out how to generate a &lt;EM&gt;Structured NumPy Array&lt;/EM&gt; that I can use as input to &lt;A href="http://resources.arcgis.com/en/heLP/MAIN/10.2/index.html#//018w0000001n000000" rel="nofollow noopener noreferrer" target="_blank"&gt;NumPyArrayToFeatureClass&lt;/A&gt;. The &lt;EM&gt;Structured NumPy Array&lt;/EM&gt; format that is required as input to &lt;EM&gt;NumPyArrayToFeatureClass&lt;/EM&gt; is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="n"&gt;array&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;numpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;array&lt;/SPAN&gt;&lt;SPAN class="p"&gt;([(&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mf"&gt;471316.3835861763&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="mf"&gt;5000448.782036674&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)),&lt;/SPAN&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;2&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mf"&gt;470402.49348005146&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="mf"&gt;5000049.216449278&lt;/SPAN&gt;&lt;SPAN class="p"&gt;))],&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;numpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dtype&lt;/SPAN&gt;&lt;SPAN class="p"&gt;([(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'idfield'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="n"&gt;numpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;int32&lt;/SPAN&gt;&lt;SPAN class="p"&gt;),(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'XY'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'&amp;lt;f8'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;2&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)]))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From what I gathered the coordinates are stored as &lt;A href="http://www.tutorialspoint.com/python/python_tuples.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;tuples&lt;/A&gt; within the &lt;EM&gt;Structured NumPy Array&lt;/EM&gt;. I'm still learning to code so any assistance in how to covert my data into a &lt;EM&gt;Structured NumPy Array&lt;/EM&gt; that I may use as input into &lt;EM&gt;NumPyArrayToFeatureClass&lt;/EM&gt; will be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PeterW&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:46:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45653#M3623</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2021-12-10T21:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: XY Coordinates to Structured NumPy Array</title>
      <link>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45654#M3624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc =&amp;nbsp; #feature class with NEAR_X and NEAR_Y fields
idfield = #an identifier field

nearList = []
with arcpy.da.SearchCursor(fc, [idfield, "NEAR_X", "NEAR_Y"]) as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for id, x, y in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nearList.append((id, (x, y)))

dtype = numpy.dtype([(idfield,numpy.int32),('XY', '&amp;lt;f8', 2)])
narr = numpy.array(nearList, dtype)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can add extra fields, or drop the idfield, if you want. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:46:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45654#M3624</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T21:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: XY Coordinates to Structured NumPy Array</title>
      <link>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45655#M3625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the following, its truly appreciated, I had not idea it would be that easy to create the Structured NumPy Array. I'm going to be using the following a lot in the future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Peter Wilson&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Mar 2015 07:30:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45655#M3625</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2015-03-13T07:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: XY Coordinates to Structured NumPy Array</title>
      <link>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45656#M3626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter, you can use &lt;A href="http://resources.arcgis.com/en/heLP/MAIN/10.2/index.html#//018w00000015000000"&gt;FeatureClassToNumPyArray&lt;/A&gt; as well...It just handles the messy job of checking for nulls etc in attribute fields and truncating fieldnames so that they are compliant with shapefiles or featureclass should the need to have them brought back to Arc* be required.&lt;/P&gt;&lt;P&gt;Also, check out &lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson"&gt;my blog&amp;nbsp; &lt;/A&gt;there are some useful tips there. I now work almost exclusively with numpy arrays since most of the work I do is with geometry.&amp;nbsp; A post on &lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2014/09/28/hidden-gemsworking-with-shapefiles-and-structured-arrays"&gt;recfunctions and structured arrays &lt;/A&gt;may be of particular interest peaking since it adds the capabilities of appending columns to arrays without the need for the&lt;A href="http://resources.arcgis.com/en/heLP/MAIN/10.2/index.html#/ExtendTable/018w0000000m000000/"&gt; ExtendTable &lt;/A&gt;function in arcpy's data access module.&amp;nbsp; If you work with data that has null values/nodata in the columns, you should do some reading on masked arrays which is nothing more than a subclass of the ndarray category.&amp;nbsp; There are also a few tips on maintaining the input array structure to enable you to maintain column references as well as their named counter parts, but I won't go into that here.&amp;nbsp; I should also mention that if bringing shapefiles/featureclass data proves problematic in some circumstances, I have exported their contents out to delimited textfiles and brought them in using numpy's various array reading capabilities, which handle tons of capabilities to handle the most difficult of data maintainence issues.&amp;nbsp; enjoy your evolution from Pythonista to NumPythonista &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Mar 2015 08:31:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45656#M3626</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-03-13T08:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: XY Coordinates to Structured NumPy Array</title>
      <link>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45657#M3627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;FeatureClassToNumpyArray, nah, that would be too easy. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&amp;nbsp; I got tunnel vision on showing the mechanics of building the numpy array, but FeatureClassToNumPyArray is the more ArcPy approach.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Mar 2015 14:04:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45657#M3627</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-03-13T14:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: XY Coordinates to Structured NumPy Array</title>
      <link>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45658#M3628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;but it does show how two kids can play nice &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Mar 2015 17:03:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/xy-coordinates-to-structured-numpy-array/m-p/45658#M3628</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-03-13T17:03:44Z</dc:date>
    </item>
  </channel>
</rss>

