Ignore:
Timestamp:
Jul 5, 2005, 12:16:43 PM (19 years ago)
Author:
hitchman
Message:

added bounding box to dem2pts + test

File:
1 edited

Legend:

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

    r1502 r1577  
    921921    return cls(domain, mode)
    922922
    923 def dem2pts(basename_in, basename_out=None, verbose=False):
     923def dem2pts(basename_in, basename_out=None, verbose=False,
     924            easting_min=None, easting_max=None,
     925            northing_min=None, northing_max=None):
    924926    """Read Digitial Elevation model from the following NetCDF format (.dem)
    925927
     
    983985    outfile.description = 'NetCDF pts format for compact and portable storage ' +\
    984986                      'of spatial point data'
     987    #assign default values
     988    if easting_min is None: easting_min = xllcorner
     989    if easting_max is None: easting_max = xllcorner + ncols*cellsize
     990    if northing_min is None: northing_min = yllcorner
     991    if northing_max is None: northing_max = yllcorner + nrows*cellsize
     992
     993    #compute offsets to update georeferencing
     994    easting_offset = xllcorner - easting_min
     995    northing_offset = yllcorner - northing_min
    985996
    986997    #Georeferencing
    987998    outfile.zone = zone
    988     outfile.xllcorner = xllcorner #Easting of lower left corner
    989     outfile.yllcorner = yllcorner #Northing of lower left corner
     999    outfile.xllcorner = easting_min #Easting of lower left corner
     1000    outfile.yllcorner = northing_min #Northing of lower left corner
    9901001    outfile.false_easting = false_easting
    9911002    outfile.false_northing = false_northing
     
    10021013
    10031014    # dimension definitions
    1004     outfile.createDimension('number_of_points', nrows*ncols)
     1015    nrows_in_bounding_box = int(round((easting_max-easting_min)/cellsize))
     1016    ncols_in_bounding_box = int(round((northing_max-northing_min)/cellsize))
     1017    outfile.createDimension('number_of_points', nrows_in_bounding_box*ncols_in_bounding_box)
    10051018    outfile.createDimension('number_of_dimensions', 2) #This is 2d data
    10061019
     
    10161029    #Store data
    10171030    #FIXME: Could perhaps be faster using array operations
     1031    index = 0
    10181032    for i in range(nrows):
    10191033        if verbose: print 'Processing row %d of %d' %(i, nrows)
    10201034
    1021         y = (nrows-i)*cellsize
     1035        y = (nrows-i)*cellsize + yllcorner
    10221036        for j in range(ncols):
    1023             index = i*ncols + j
    1024 
    1025             x = j*cellsize
    1026             points[index, :] = [x,y]
    1027             elevation[index] = dem_elevation[i, j]
     1037            #index = i*ncols + j
     1038
     1039            x = j*cellsize + xllcorner
     1040            if easting_min <= x <= easting_max and \
     1041               northing_min <= y <= northing_max:
     1042                points[index, :] = [x-easting_min,y-northing_min]
     1043                elevation[index] = dem_elevation[i, j]
     1044                index += 1
     1045
     1046    #print easting_min, easting_max
     1047    #print index, nrows_in_bounding_box*ncols_in_bounding_box
     1048    #print nrows, ncols
     1049    assert index == nrows_in_bounding_box*ncols_in_bounding_box, 'index not equal to number of points'
    10281050
    10291051    infile.close()
Note: See TracChangeset for help on using the changeset viewer.