[7113] | 1 | # --------------------------------------------------------------------------- |
---|
| 2 | # txt2fc_res.py |
---|
| 3 | # Created on: Mon Dec 01 2008 11:36:17 AM |
---|
| 4 | # (generated by ArcGIS/ModelBuilder) |
---|
| 5 | # --------------------------------------------------------------------------- |
---|
| 6 | |
---|
| 7 | # Import system modules |
---|
| 8 | import sys, string, os, arcgisscripting |
---|
| 9 | from os.path import join |
---|
| 10 | |
---|
| 11 | # Create the Geoprocessor object |
---|
| 12 | gp = arcgisscripting.create() |
---|
| 13 | |
---|
| 14 | # Load required toolboxes... |
---|
| 15 | gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") |
---|
| 16 | gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") |
---|
| 17 | gp.overwriteoutput = 1 |
---|
| 18 | |
---|
| 19 | scenario_dir="\\\\nas2\\gemd\\georisk_models\\inundation\\data\\western_australia\\perth_tsunami_scenario\\" |
---|
| 20 | output_dir = "anuga\\outputs\\" |
---|
| 21 | |
---|
| 22 | time_dir1 = '20090324_135427_run_final_0.6_27255_Bt_kvanputt' |
---|
| 23 | time_dir2 = '20090324_154957_run_final_0.6_68693_Bt_kvanputt' |
---|
| 24 | time_dir3 = '20090324_155028_run_final_0.6_27283_Bt_kvanputt' |
---|
| 25 | time_dir4 = '20090327_155353_run_final_0_27283_Bt_kvanputt' |
---|
| 26 | time_dir5 = '20090327_155659_run_final_0_27255_Bt_kvanputt' |
---|
| 27 | time_dir6 = '20090327_155803_run_final_0_68693_Bt_kvanputt' |
---|
| 28 | |
---|
| 29 | time_dirs = [time_dir3, time_dir4, time_dir5, time_dir6] |
---|
| 30 | |
---|
| 31 | def replace_in_file(filename, instr, repstr): |
---|
| 32 | '''Replace one string with another in a file.''' |
---|
| 33 | |
---|
| 34 | # get the file contents |
---|
| 35 | fd = open(filename, 'r') |
---|
| 36 | lines = fd.readlines() |
---|
| 37 | fd.close() |
---|
| 38 | |
---|
| 39 | # convert list to one string |
---|
| 40 | newlines = ''.join(lines) |
---|
| 41 | |
---|
| 42 | # replace 'instr' with 'repstr' |
---|
| 43 | newlines = newlines.replace(instr, repstr) |
---|
| 44 | |
---|
| 45 | # write changed lines back to file |
---|
| 46 | fd = open(filename, 'w') |
---|
| 47 | fd.write(newlines) |
---|
| 48 | fd.close() |
---|
| 49 | |
---|
| 50 | for time_dir in time_dirs: |
---|
| 51 | print 'time_dir = ', time_dir |
---|
| 52 | |
---|
| 53 | # Local variables... |
---|
| 54 | folder = scenario_dir + output_dir + time_dir + '\\' |
---|
| 55 | input_dir_name = folder+'perth_res.csv' |
---|
| 56 | raster_gdb = folder + "raster.gdb" |
---|
| 57 | layer = 'layer' |
---|
| 58 | |
---|
| 59 | print 'replace _$ with nothing' |
---|
| 60 | replace_in_file(input_dir_name, '_$', '') |
---|
| 61 | |
---|
| 62 | ## print 'Process: Feature Class to Feature Class' |
---|
| 63 | ## gp.FeatureClassToFeatureClass_conversion(layer, raster_gdb, "perth_res", "", "OBJECTID OBJECTID true true false 4 Long 0 10 ,First,#,perth_res.csv_Features,OBJECTID,-1,-1;LONGITUDE LONGITUDE true true false 8 Double 0 0 ,First,#,perth_res.csv_Features,LONGITUDE,-1,-1;LATITUDE LATITUDE true true false 8 Double 0 0 ,First,#,perth_res.csv_Features,LATITUDE,-1,-1;STRUCT_INUNDATED STRUCT_INUNDATED true true false 4 Long 0 10 ,First,#,perth_res.csv_Features,STRUCT_INUNDATED,-1,-1;STRUCT_DAMAGE_fraction STRUCT_DAMAGE_fraction true true false 8 Double 0 0 ,First,#,perth_res.csv_Features,STRUCT_DAMAGE_fraction,-1,-1;COLLAPSE_CSV_INFO COLLAPSE_CSV_INFO true true false 255 Text 0 0 ,First,#,perth_res.csv_Features,COLLAPSE_CSV_INFO,-1,-1;MAX_DEPTH_m MAX_DEPTH_m true true false 8 Double 0 0 ,First,#,perth_res.csv_Features,MAX_DEPTH_m,-1,-1;STRUCT_COLLAPSED STRUCT_COLLAPSED true true false 255 Text 0 0 ,First,#,perth_res.csv_Features,STRUCT_COLLAPSED,-1,-1;STRUCT_LOSS STRUCT_LOSS true true false 8 Double 0 0 ,First,#,perth_res.csv_Features,STRUCT_LOSS,-1,-1;CONTENTS_DAMAGE_fraction CONTENTS_DAMAGE_fraction true true false 8 Double 0 0 ,First,#,perth_res.csv_Features,CONTENTS_DAMAGE_fraction,-1,-1;CONTENTS_LOSS CONTENTS_LOSS true true false 8 Double 0 0 ,First,#,perth_res.csv_Features,CONTENTS_LOSS,-1,-1", "") |
---|
| 64 | ## |
---|