<?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: How do you import an SQL query/view into arcgis in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381335#M30045</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;augh.&amp;nbsp; I'm getting an error I'm not sure what to do about.&amp;nbsp; I've tried a lot of different samples so my code looks a little different.&amp;nbsp; Everything works fine when I do a print for the array but I continue to have the problem below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting this error below&lt;/P&gt;&lt;P&gt;TypeError: expected a readable buffer object&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On this line:&lt;/P&gt;&lt;P&gt;npyarr = numpy.array(datArray, numpy.dtype([('storename', '|S25'), ("xCoord", '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')]))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def defAddSQLTable_CreateShapefile():&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnxn = pyodbc.connect("DSN=AR")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = cnxn.cursor()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.execute("Select STORENAME, LATITUDE, LONGITUDE FROM GISWEB.VW_MCYWEB WHERE DISTRICTID = 944")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datArray = []&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datArray.append(row)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dtype = np.dtype([('STORENAME', '|S25'), ('xCoord', '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; npyarr = np.array(datArray, dtype)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_fc = "C:/inetpub/mystores3"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.da.NumPyArrayToFeatureClass(npyarr, out_fc, ['xCoord','yCoord' ])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Oct 2014 16:50:28 GMT</pubDate>
    <dc:creator>deleted-user-Pi5x1UjkS2PY</dc:creator>
    <dc:date>2014-10-29T16:50:28Z</dc:date>
    <item>
      <title>How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381326#M30036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Have a view in SQL that I want to bring into ArcGIS using python.&amp;nbsp; It is part of a process of a longer python script.&amp;nbsp; how can I do this using python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In 9.3 I used my ODBC connection&amp;nbsp; "&lt;STRONG&gt;AR&lt;/STRONG&gt;"&amp;nbsp; to do this and then brought in my file "&lt;STRONG&gt;GISWEB.VW_MCYWEB&lt;/STRONG&gt;" as an XY Event and then exported it as a shapefile with a coordinate system of WebMercator so that I could use it in my web maps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried several things but nothing is working for me at the moment.&amp;nbsp; I'm sure this is simple but I'm not see how to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought maybe this would work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import win32api, win32con&lt;/P&gt;&lt;P&gt;import sys&lt;/P&gt;&lt;P&gt;import pyodbc&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def defAddSQLTable_CreateShapefile():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ### Works Makes a list of all tables in SQL Database for that DSN Connection ###&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnxn = pyodbc.connect("DSN=AR")&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;arcpy.env.workspace= 'C:/temp'&amp;nbsp; &lt;BR /&gt;in_Table = "AR.GISWEB.VW_MCYWEB"&amp;nbsp; &lt;BR /&gt;y_coords = "Longitude"&amp;nbsp; &lt;BR /&gt;x_coords = "Latitude"&amp;nbsp; &lt;BR /&gt;out_layer = "Stores"&amp;nbsp; &lt;BR /&gt;arcpy.env.overwriteOutput = 'true'&lt;/P&gt;&lt;P&gt;arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;defAddSQLTable_CreateShapefile()&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 14:34:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381326#M30036</guid>
      <dc:creator>deleted-user-Pi5x1UjkS2PY</dc:creator>
      <dc:date>2014-10-27T14:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381327#M30037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;AR.GISWEB.VW_MCYWEB is not a table (as in how you perceive your "in_Table" variable).&amp;nbsp; You have to issue SQL against this to fill a cursor object and then use the cursor to build your table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://code.google.com/p/pyodbc/wiki/GettingStarted" title="https://code.google.com/p/pyodbc/wiki/GettingStarted"&gt;GettingStarted - pyodbc - Quick Examples To Get You Started - Python ODBC library - Google Project Hosting&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We do something similar, but we access Oracle using cx_Oracle library.&amp;nbsp; basically once you get your cursor you can just append rows to a new list and/or numpy array which is easy to convert to a feature class with arcpy.da.NumPyArrayToFeatureClass() or arcpy.da.NumPyArrayToTable()&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 15:13:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381327#M30037</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-10-27T15:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381328#M30038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks but I need further guidance please. I can use what is below to print out a list of Storenames from my table.&amp;nbsp; So it is connecting which is good.&amp;nbsp; One step closer. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I want all of my field names and values to go into this array to make the feature class which will hopefully make my shapefile.&amp;nbsp; Should be a simple way to loop through the table adding all of the column names and field values into the array.&amp;nbsp; Any help would be greatly appreciated. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def defAddSQLTable_CreateShapefile():&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnxn = pyodbc.connect("DSN=AR")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = cnxn.cursor()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.execute("select * from GISWEB.VW_MCYWEB")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = "c://temp/myfc&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##grab field value&amp;nbsp; print row.column_name&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'name:', row[1]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # access by column index&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'name:', row.STORENAME&amp;nbsp;&amp;nbsp; # or access by name&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 17:38:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381328#M30038</guid>
      <dc:creator>deleted-user-Pi5x1UjkS2PY</dc:creator>
      <dc:date>2014-10-27T17:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381329#M30039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;y_coords = "Longitude"&amp;nbsp; &lt;/P&gt;&lt;P&gt;x_coords = "Latitude"&lt;/P&gt;&lt;P&gt;Interesting...these are reversed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 17:45:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381329#M30039</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-27T17:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381330#M30040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like this (untested and just typed out from memory and other snippets):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14144345268441078" jivemacro_uid="_14144345268441078"&gt;
&lt;P&gt;datArray = []&lt;/P&gt;
&lt;P&gt;for row in cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datArray.append(row)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;cursor.close()&lt;/P&gt;
&lt;P&gt;del cursor&lt;/P&gt;
&lt;P&gt;if len(datArray)&amp;gt;0:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; npyarr = np.array(datArray, np.dtype([('storename', '|S25'), ('xCoord', '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')]))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; outFC = ws_mem + "&lt;A href="https://community.esri.com/"&gt;\\&lt;/A&gt;MyFeatureClass" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if arcpy.Exists(outFC):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(outFC)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "deleted " + str(outFC)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; arcpy.da.NumPyArrayToFeatureClass(npyarr, outFC, ("xCoord", "yCoord"))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; print "created..." + outFC&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 18:29:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381330#M30040</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-10-27T18:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381331#M30041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, please don't use "SELECT * FROM Table/View..." --- not only is it bad SQL, it's going to make your life really difficult when setting up your arrays and/or conversion into GIS-objects.&amp;nbsp; Be sure to specify the fields you want... ALWAYS. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 18:33:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381331#M30041</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-10-27T18:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381332#M30042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks but I want all of the fields and we will add to these fields as we grow this product. &lt;/P&gt;&lt;P&gt;I don't understand this line below.&amp;nbsp; what is the |S25' for and what is the &amp;lt;f8 for?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;npyarr = np.array(datArray, np.dtype([('STORENAME', '|S25'), ('xCoord', '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')]))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 18:40:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381332#M30042</guid>
      <dc:creator>deleted-user-Pi5x1UjkS2PY</dc:creator>
      <dc:date>2014-10-27T18:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381333#M30043</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt; but I want all of the fields and we will add to these fields as we grow this product&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then add them, don't be lazy.&amp;nbsp; "SELECT *" is fine for quick look at things, but not a great idea for production code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;what is the |S25' for and what is the &amp;lt;f8 for?&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018w0000001n000000" title="http://resources.arcgis.com/en/help/main/10.1/index.html#//018w0000001n000000"&gt;ArcGIS Help 10.1&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 18:44:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381333#M30043</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-10-27T18:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381334#M30044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;He is producing a numpy array using the arcpy.da.NumPyArrayToFeatureClass.... line&lt;/P&gt;&lt;P&gt;This line npyarr = np.array(datArray, np.dtype([('STORENAME', '|S25'), ('xCoord', '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')]))&lt;/P&gt;&lt;P&gt;sets the data type so that STORENAME is a string, 25 characters wide and xCoord, yCoord are floating point numbers (details in numpy dtype documentation)&lt;/P&gt;&lt;P&gt;in essence, you will end up with an array (npyarr) that you can query by field name and or coordinates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14144358570081626 jive_text_macro" jivemacro_uid="_14144358570081626"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; data = [ ("Walmart", -75.0, 45.0),("Costco", -75.5,45.1)]&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import numpy as np&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; dtype =np.dtype([('STORENAME', '|S25'), ('xCoord', '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')])&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; npyarr = np.array(data,dtype)&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; npyarr&lt;/P&gt;
&lt;P&gt;array([('Walmart', -75.0, 45.0), ('Costco', -75.5, 45.1)], &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dtype=[('STORENAME', 'S25'), ('xCoord', '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')])&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; npyarr['STORENAME']&lt;/P&gt;
&lt;P&gt;array(['Walmart', 'Costco'], &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dtype='|S25')&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; npyarr[0] &lt;/P&gt;
&lt;P&gt;('Walmart', -75.0, 45.0)&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; npyarr[1]&lt;/P&gt;
&lt;P&gt;('Costco', -75.5, 45.1)&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;such arrays can be extremely powerful&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 18:49:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381334#M30044</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-27T18:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381335#M30045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;augh.&amp;nbsp; I'm getting an error I'm not sure what to do about.&amp;nbsp; I've tried a lot of different samples so my code looks a little different.&amp;nbsp; Everything works fine when I do a print for the array but I continue to have the problem below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting this error below&lt;/P&gt;&lt;P&gt;TypeError: expected a readable buffer object&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On this line:&lt;/P&gt;&lt;P&gt;npyarr = numpy.array(datArray, numpy.dtype([('storename', '|S25'), ("xCoord", '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')]))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def defAddSQLTable_CreateShapefile():&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnxn = pyodbc.connect("DSN=AR")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = cnxn.cursor()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.execute("Select STORENAME, LATITUDE, LONGITUDE FROM GISWEB.VW_MCYWEB WHERE DISTRICTID = 944")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datArray = []&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datArray.append(row)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dtype = np.dtype([('STORENAME', '|S25'), ('xCoord', '&amp;lt;f8'), ('yCoord', '&amp;lt;f8')])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; npyarr = np.array(datArray, dtype)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_fc = "C:/inetpub/mystores3"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.da.NumPyArrayToFeatureClass(npyarr, out_fc, ['xCoord','yCoord' ])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 16:50:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381335#M30045</guid>
      <dc:creator>deleted-user-Pi5x1UjkS2PY</dc:creator>
      <dc:date>2014-10-29T16:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381336#M30046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Numpy lesson part 2....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are producing an array from a list of lists, you can run into some problems...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14146079440204750" jivemacro_uid="_14146079440204750"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import numpy as np&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; data_list = [[0,'Walmart',-75.0,45.0],[1,'Costco',-75.5,45.1],[2,'Best Buy',-75.1,45.2],[3,'Shoppers',-75.2,45.3]]&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; dtype = np.dtype([('ID','&amp;lt;i4'),('Store','|S25'),('Long','&amp;lt;f8'),('Lat','&amp;lt;f8')])&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; np_array = np.array(data_list,dtype)&lt;/P&gt;
&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;
&lt;P&gt;&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/P&gt;
&lt;P&gt;TypeError: expected a readable buffer object&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;you can correct for this by using a generator to convert the list of lists to a list of tuples...and life is good&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14146079557961307 jive_text_macro" jivemacro_uid="_14146079557961307"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; data = [ tuple(row) for row in data_list]&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; data&lt;/P&gt;
&lt;P&gt;[(0, 'Walmart', -75.0, 45.0), (1, 'Costco', -75.5, 45.1), (2, 'Best Buy', -75.1, 45.2), (3, 'Shoppers', -75.2, 45.3)]&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; np_array = np.array(data,dtype)&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; np_array&lt;/P&gt;
&lt;P&gt;array([(0, 'Walmart', -75.0, 45.0), (1, 'Costco', -75.5, 45.1),&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2, 'Best Buy', -75.1, 45.2), (3, 'Shoppers', -75.2, 45.3)],&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dtype=[('ID', '&amp;lt;i4'), ('Store', 'S25'), ('Long', '&amp;lt;f8'), ('Lat', '&amp;lt;f8')])&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;The stores in no way sponsor this thread...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 18:39:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381336#M30046</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-29T18:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381337#M30047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Changed to this and it works like a charm&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;datarray.append(tuple(row))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One last question.&amp;nbsp; I need to be able to add the spatial reference of webmercator to it.&amp;nbsp; I know you do it somehow like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just not sure what to put in for webmercator?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;SR&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Describe&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"C:/data/texas.gdb/fd"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;spatialReference&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 18:53:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381337#M30047</guid>
      <dc:creator>deleted-user-Pi5x1UjkS2PY</dc:creator>
      <dc:date>2014-10-29T18:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do you import an SQL query/view into arcgis</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381338#M30048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;stealing from the help files&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;SR&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Describe&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"C:/data/texas.gdb/fd"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;spatialReference&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="c"&gt;# Export the numpy array to a feature class using the XY field to&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="c"&gt;#&amp;nbsp; represent the output point feature&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="c"&gt;#&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;da&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;NumPyArrayToFeatureClass&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;array&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;outFC&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&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="n"&gt;SR&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;As long as you have a valid spatial reference, then you add it as SR when creating the output&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 19:08:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-import-an-sql-query-view-into-arcgis/m-p/381338#M30048</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-29T19:08:44Z</dc:date>
    </item>
  </channel>
</rss>

