Monday 30 November 2015

arcgis 10.3 - Making table from MySQL query with ArcPy?


I am trying to interact directly with data from a MySQL database in ArcMap using Python. So far, I have successfully connected the database using the MySQLdb.connect() function and have successfully executed queries using the cur.execute() function. I also am able to print the results in the Python window.


I cannot, however, figure out how to create a table from the query output that I can then use to, for instance, join to a shapefile or display XY data. I assumed that the MakeQueryTable_management() function would allow me to do this, but the syntax is very confusing to me. Do I execute the query using cur.execute() and then execute this function, does this function replace the cur.execute() function, or do I do something altogether different?


for example, here is a query:



cur.execute("SELECT count(zip_codes.zip_code) AS Zips, zip_codes.state FROM   zip_codes GROUP BY zip_codes.state ORDER BY zip_codes.state ASC")

so how would I write the MakQueryTable_management() function given this syntax?


MakeQueryTable_management (in_table, out_table, in_key_field_option, {in_key_field}, {in_field}, {where_clause})

I am new to ArcPy.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...