Home arrow GIS Data & Resources arrow Scripts and Code arrow Python arrow PYTHON! Batch FTP Download From Index Feature Class
PYTHON! Batch FTP Download From Index Feature Class PDF Print E-mail

Written by Kevin Bell,

GIS data is often tiled to reduce file sizes and to allow downloading data that is in a certain area. Index files are often used to show the file name for the cooresponding area. If you get your hands on the index feature class and export the tiles that you're interested in, then you can alter this code to download the corresponding files from AGRC's FTP site. I "borrowed" this code from an online sample from Matt Croydon, and I altered it to use the search cursor to build a list of files to download. You can find more detailed literature of python's FTP library online...

 ##################################################

#FTPfromFeatureClass.py
#Author: Kevin Bell
#           (FTP sample thanks to Matt Croydon!!!)
#Date: 20071231
# This e-mail address is being protected from spam bots, you need JavaScript enabled to view it

from ftplib import FTP
import arcgisscripting
gp = arcgisscripting.create()

#00000000000000000000000000000000000000000000
def handleDownload(block):
    file.write(block)
    print ".",
#00000000000000000000000000000000000000000000

ftp = FTP('ftp.agrc.utah.gov')
print 'Logging in.'
print ftp.login()
directory = 'Imagery/LIDAR/WasatchFront_2m'
ftp.cwd(directory)

# build a list of files to download from your index features...
inputFC = "F:\gis\zMisc\20071219_2MeterLiDAR\Temp\triCanyon.shp"
myList = []
cur = gp.SearchCursor(inputFC)
row = cur.Next()
while row:
    myList.append(row.USNG + ".asc") # <----- the field that has the tile name + file extension
    row = cur.Next()

del cur, gp; print "cleared out the ESRI objects"


for filename in myList:
    file = open(filename, 'wb'); print 'Opening local file ' + filename
    ftp.retrbinary('RETR ' + filename, handleDownload); print 'Getting ' + filename
    file.close(); print 'Closing file ' + filename

print 'Closing FTP connection'
print ftp.close()


Users' Comments  
 

No comment posted

Add your comment

31, Dec. 2007
Last Updated ( 31, Dec. 2007 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for