Ignore:
Timestamp:
Feb 18, 2005, 5:15:46 PM (20 years ago)
Author:
ole
Message:

Incorporated variable false eastings and northings (just in case:-).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r900 r928  
    872872    dem_elevation = infile.variables['elevation']
    873873
     874    zone = infile.zone[0]
     875    false_easting = infile.false_easting[0]
     876    false_northing = infile.false_northing[0]
     877
     878    #Text strings
     879    projection = infile.projection
     880    datum = infile.datum
     881    units = infile.units
     882   
     883
    874884    #Get output file                               
    875885    xyaname = root + '.pts'
     
    884894
    885895    #Georeferencing
    886     outfile.zone = 56   #FIXME: Must be read from somewhere. Talk to Don.
     896    outfile.zone = zone
    887897    outfile.xllcorner = xllcorner #Easting of lower left corner
    888898    outfile.yllcorner = yllcorner #Northing of lower left corner
    889    
     899    outfile.false_easting = false_easting
     900    outfile.false_northing =false_northing
     901   
     902    outfile.projection = projection
     903    outfile.datum = datum
     904    outfile.units = units
     905
    890906
    891907    #Grid info (FIXME: probably not going to be used, but heck)
     
    938954
    939955    Convert to NetCDF format (.dem) mimcing the ASCII format closely.
     956
     957
     958    An accompanying file with same basename but extension .prj must exist
     959    and is used to fix the UTM zone, datum, false northings and eastings.
     960
     961    The prj format is assumed to be as
     962   
     963    Projection    UTM
     964    Zone          56
     965    Datum         WGS84
     966    Zunits        NO
     967    Units         METERS
     968    Spheroid      WGS84
     969    Xshift        0.0000000000
     970    Yshift        10000000.0000000000
     971    Parameters
    940972    """
    941973
     
    945977
    946978    root, ext = os.path.splitext(filename)
    947     fid = open(filename)
     979
     980    ###########################################
     981    # Read Meta data
     982    if verbose: print 'Reading METADATA from %s' %root + '.prj'
     983    metadatafile = open(root + '.prj')   
     984    metalines = metadatafile.readlines()
     985    metadatafile.close()
     986
     987    L = metalines[0].strip().split()
     988    assert L[0].strip().lower() == 'projection'
     989    projection = L[1].strip()                   #TEXT
     990
     991    L = metalines[1].strip().split()
     992    assert L[0].strip().lower() == 'zone'
     993    zone = int(L[1].strip())   
     994
     995    L = metalines[2].strip().split()
     996    assert L[0].strip().lower() == 'datum'
     997    datum = L[1].strip()                        #TEXT
     998
     999    L = metalines[3].strip().split()     
     1000    assert L[0].strip().lower() == 'zunits'     #IGNORE
     1001    zunits = L[1].strip()                       #TEXT
     1002
     1003    L = metalines[4].strip().split()
     1004    assert L[0].strip().lower() == 'units'
     1005    units = L[1].strip()                        #TEXT
     1006
     1007    L = metalines[5].strip().split()
     1008    assert L[0].strip().lower() == 'spheroid'   #IGNORE
     1009    spheroid = L[1].strip()                     #TEXT
     1010
     1011    L = metalines[6].strip().split()
     1012    assert L[0].strip().lower() == 'xshift'     
     1013    false_easting = float(L[1].strip())
     1014
     1015    L = metalines[7].strip().split()
     1016    assert L[0].strip().lower() == 'yshift'
     1017    false_northing = float(L[1].strip())   
     1018
     1019    #print false_easting, false_northing, zone, datum
     1020
     1021
     1022    ###########################################
     1023    #Read DEM data
     1024    datafile = open(filename)
    9481025
    9491026    if verbose: print 'Reading DEM from %s' %filename
    950     lines = fid.readlines()
    951     fid.close()
     1027    lines = datafile.readlines()
     1028    datafile.close()
    9521029
    9531030    if verbose: print 'Got', len(lines), ' lines'
     
    9621039    assert len(lines) == nrows + 6
    9631040
     1041
     1042    ##########################################
     1043
     1044   
    9641045    netcdfname = root + '.dem'
    9651046    if verbose: print 'Store to NetCDF file %s' %netcdfname
     
    9791060    fid.NODATA_value = NODATA_value
    9801061
     1062    fid.zone = zone
     1063    fid.false_easting = false_easting
     1064    fid.false_northing = false_northing   
     1065    fid.projection = projection
     1066    fid.datum = datum
     1067    fid.units = units
     1068   
     1069
    9811070    # dimension definitions
    9821071    fid.createDimension('number_of_rows', nrows)
     
    10031092
    10041093
    1005 
    1006 
    1007 
    1008 
    10091094def ferret2sww(basefilename, verbose=False,
    10101095               minlat = None, maxlat =None,
    10111096               minlon = None, maxlon =None,
    10121097               mint = None, maxt = None, mean_stage = 0,
    1013                origin = (0,0,0)):
     1098               origin = (0,0,0,0,0)):
    10141099    """Convert 'Ferret' NetCDF format for wave propagation to
    10151100    sww format native to pyvolution.
     
    11691254
    11701255    #Check zone boundaries
    1171     refzone, _, _ = redfearn(latitudes[0],longitudes[0])
     1256    refzone, _, _ = redfearn(latitudes[0],longitudes[0],
     1257                             false_easting=origin[3],
     1258                             false_northing=origin[4])
     1259   
     1260                             
    11721261
    11731262    vertices = {}
     
    11761265            vertices[l,k] = i
    11771266           
    1178             zone, easting, northing = redfearn(lat,lon)
     1267            zone, easting, northing = redfearn(lat,lon,
     1268                                               false_easting=origin[3],
     1269                                               false_northing=origin[4])
    11791270
    11801271            msg = 'Zone boundary crossed at longitude =', lon
Note: See TracChangeset for help on using the changeset viewer.