Help performing these steps >Sample >Display XY Data >Export Attribute Table

3852
14
Jump to solution
12-15-2015 02:46 PM
DannyLackey
Deactivated User

I have a manual process I'm trying to automate.  My question is mostly related to step 2, but I welcome any suggestion for any of the process I've described that may help me achieve my goal.  Thanks in advance!

The first part is dumping raster data:  Spatial Analyst Tools > Extraction > Sample > 

(Step 1) I've been able to do this piece with the following code:

import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = r"c:\InputRasters"
# Set local variables
inRasters = ["b_inst"]
locations = r"c:\Grids\50ft_Grid.shp"
outTable = r"c:\TestTable"
sampMethod = "NEAREST"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute Sample
Sample(inRasters, locations, outTable, sampMethod)
Environments

(Step 2) Now I need to Display the XY data and export attribute table to either a dbf or Excel spreadsheet.

This piece of code seems to be what I need, but it seems to require a .dbf file.  The script from the previous step didn't output a .dbf, it output a folder called "info" containing the following files: arc.dir (1 kb), arc0000.dat (7,022 kb), arc0000.nit (1 kb), and arc0000.xml (1 kb).

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000006z000000 

(Step 3) Finally, I'm thinking I can use this technique to dump the resulting dbf to .xls

arcgis desktop - Saving *.dbf as *.xls using Python? - Geographic Information Systems Stack Exchange

0 Kudos
14 Replies
FreddieGibson
Honored Contributor

Would it be possible for you to upgrade to a version of the software that has the tool you're needing to leverage? Writing your own tool in this case is going to be a rather involved process.

0 Kudos
DannyLackey
Deactivated User

I'm comfortable writing python, but there are some aspects that just haven't come up for me yet...this is one of them.  What do I need in order to run these commands?  Chances are, it will require an admin to install.

0 Kudos
DannyLackey
Deactivated User

I'd like to keep it all in the same tool, but for now, I just wrote it in vb.

Const xlXLSX = 51
'Open Excel and load dbf
Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = FALSE
objExcel.Visible = FALSE
Set objWorkbook = objExcel.Workbooks.Open("C:\TestTable.dbf")
'Save as xlsx and close workbook
objWorkbook.SaveAs "C:\test.xlsx", xlXLSX
objWorkbook.Close
'Close Excel and quit
objExcel.Quit
0 Kudos
FreddieGibson
Honored Contributor

The steps on the following page are probably the easiest way to install pip other than upgrading python to 2.7.10, which comes with pip by default.

http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows/11311788#11311788

I've included a one minute video that shows how I leveraged the installers on the above page to install pip and then use it to install xlwt.

DannyLackey
Deactivated User

Thank you!  I'll check these out.

0 Kudos