Sorry about the code indent. Didn't realize I needed to use the INDENT tool.
Sample .csv data (including header):
ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType
0,-74.064842,40.617940,2010-01-01 00:01,0,WS0286,Other
0,-90.910605,30.080466,2010-01-01 00:02,0,WS0286,Other
0,-74.064867,40.617936,2010-01-01 00:03,0,WS0286,Other
1,-90.216484,29.125813,2010-01-01 00:00,511,FF0419,Cargo
1,-89.315449,29.047325,2010-01-01 00:00,511,FF0419,Cargo
1,-90.216495,29.125843,2010-01-01 00:01,511,FF0419,Cargo
Scripts with indentation:
min_interval.py:
import csv
from datetime import datetime
import os
def min_aggr(infile, outfile):
[INDENT] ifile = open(infile, 'rb')
reader = csv.reader(ifile)
out = open(outfile, 'wb')
writer = csv.writer(out)
header = reader.next()
hdr = ['ID','LON','LAT','DTTM','HEADING','CALL_SIGN','vesselType']
writer.writerow(hdr)
for ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType in reader:
[INDENT]dt = DTTM[:19]
dtime = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
str_date = dtime.strftime('%Y-%m-%d %H:%M')
data = [ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType]
writer.writerow(data)[/INDENT]
[/INDENT]
filenum = 0
path = raw_input("Enter the full path name (ex. c:\\test\):") datapath = raw_input('Enter the path for the output directory (ex. c:\\output\):')
dirList=os.listdir(path)
dirList.sort()
for fname in dirList:
[INDENT]filenum += 1
filename = path + fname
outfile = datapath + str(filenum) + 'output.csv'
[/INDENT]
[INDENT]try:
[INDENT]min_aggr(filename, outfile)[/INDENT]
except IOError:
[INDENT]print filename[/INDENT]
[/INDENT]
print 'files have been processed'
geocode.py:
import os
import arcpy
from arcpy import env
env.overwriteOutput = True
coord = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" #spatial projection
#create file geodatabase
dir = raw_input('Enter path to create geodatabase (ex. c:\\data\):')
dbname = raw_input('Enter the name for the geodatabase (ex. test.gdb):')
arcpy.CreateFileGDB_management(dir, dbname)
print 'geodatabase ' + dbname + ' has been created'
geodb = dir + dbname
filenum = 0
path = raw_input('Enter the full path name for input files (ex. c:\\test1\):')
datapath = raw_input('Enter the path for the output directory (ex. c:\\output1\):')
dirList=os.listdir(path)
dirList.sort()
for fname in dirList:
[INDENT]filenum += 1
filename = path + fname
shp = datapath + str(filenum) + 'output.shp'
[INDENT]try:
[INDENT]arcpy.MakeTableView_management(filename,'View')
arcpy.MakeXYEventLayer_management('View','LON','LAT','Layer')
arcpy.CopyFeatures_management('Layer', shp) arcpy.DefineProjection_management(shp, coord)
arcpy.FeatureClassToGeodatabase_conversion([shp], geodb) print 'file ' + filename + ' has been geoprocessed'[/INDENT]
except IOError:
[INDENT]print 'ERROR: ' + filename[/INDENT][/INDENT][/INDENT]
print 'geoprocessing complete'