def main(): print '-' * 50 print 'Using', prg.__path__, 'for parserasgeo' print '-' * 50, '\n' outfile = 'test.out' test_files = glob.glob(r"C:\workspace\git_clones\parserasgeo\geofiles\*.g*") #print len(test_files) #for x in test_files: #print type(x), x # print x for test_file in test_files: print('*' * 30), print('Processing ', test_file) geo = prg.ParseRASGeo(test_file) xss = geo.extract_xs() #xss[0].alter_channel_n() geo.write(outfile) if filecmp.cmp(test_file, outfile, shallow=False): print('Geometry file', test_file, 'exported correctly.') else: print('WARNING: file', test_file, 'did not export properly') subprocess.Popen(["diff", test_file, outfile]) sys.exit('WARNING: file' + test_file + 'did not export properly')
def correct_extents(geo_file, extents_list, round_digits): """ Correct extents for skew and offset :param geo_file: - name of RAS geometry file :param extents_list: - list of extents from import_extents() :param round_digits: - digits to round xs ids to """ ras_geo = prg.ParseRASGeo(geo_file) if round_digits != 0 and round_digits != '': rnd = True else: rnd = False for i, ex in enumerate(extents_list): # Pull info from RAS geometry file try: if rnd: geo_xs = ras_geo.return_xs_by_id(float(ex.XS_ID), rnd=rnd, digits=round_digits) else: geo_xs = ras_geo.return_xs_by_id(float(ex.XS_ID)) except prg.CrossSectionNotFound: arcpy.AddWarning( 'Cross section ' + ex.river + '/' + ex.reach + '-' + str(ex.XS_ID) + ' is in cross ' + 'section shapefile but is not in RAS geometry file. Skipping') continue offset = geo_xs.sta_elev.points[0][0] skew = geo_xs.skew.angle # if nothing changes, skip this extent if offset == 0 and skew is None: continue left_sta = ex.left_sta right_sta = ex.right_sta if offset != 0: arcpy.AddWarning('Correcting offset of ' + str(offset) + ' at XS ' + ex.river + '/' + ex.reach + '-' + str(ex.XS_ID)) left_sta = left_sta - offset right_sta = right_sta - offset if skew is not None: arcpy.AddWarning('Correcting skew of ' + str(skew) + ' at XS ' + ex.river + '/' + ex.reach + '-' + str(ex.XS_ID)) left_sta = left_sta / math.cos(math.radians(skew)) right_sta = right_sta / math.cos(math.radians(skew)) # Create new, corrected extent and replace the old one fixed = WS_extent(ex.river, ex.reach, ex.XS_ID, ex.profile, left_sta, right_sta, ex.WSEL) extents_list[i] = fixed
def main(): infile = r"Z:\UDFCD PLANNING\FHAD Review\Niver Round 3\Orig\20161012 FHAD Submittal\HEC-RAS\NiverCreek_FHAD_Sept.g01" infile = r"Z:\UDFCD PLANNING\Grange Hall Creek\02 HYDRAULICS\HEC-RAS\GHC_FHAD.g01" #infile = r"Z:\UDFCD PLANNING\FHAD Review\Sloans Lake Round 1\Orig\20161013 - Sloan'sLake_FHAD_HEC-RAS-20161007\HEC-RAS\SloansFHAD2017.g01" infile = r"Z:\UDFCD PLANNING\FHAD Review\Niver Round 3\Orig\20161012 FHAD Submittal\HEC-RAS\NiverCreek_FHAD_Sept.g01" #infile = r"Z:\UDFCD PLANNING\FHAD Review\SPR - 6th to 58th\Orig\20160907 Merrick_SPR 6th-58th_08-26-2016\SPR 6th-58th_Existing_HECRAS\SPR_Downstream.g04" infile = r"Z:\UDFCD PLANNING\FHAD Review\South Platte\Orig\20160629 5-27-16 SPR FHAD submittal\5-27-16 submittal\HEC-RAS\SouthPlatteFHAD.g08" infile = r"Z:\UDFCD PLANNING\Second Creek\12 FHAD\01_RAS\HEC-RAS\Submittal 2 - working\SCFHAD.g02" geo = prg.ParseRASGeo(infile) cross_sections = geo.extract_xs() print 'Levees are at the following XS:' for xs in cross_sections: if xs.levee.value is not None: print xs.river + ',' + xs.reach + ',' + str(xs.header.xs_id)
def main(): infile = r"Z:\UDFCD PLANNING\FHAD Review\Niver Round 3\Orig\20161012 FHAD Submittal\HEC-RAS\NiverCreek_FHAD_Sept.g01" #infile = r"Z:\UDFCD PLANNING\Grange Hall Creek\02 HYDRAULICS\HEC-RAS\GHC_FHAD.g01" infile = r"Z:\UDFCD PLANNING\FHAD Review\Sloans Lake Round 1\Orig\20161013 - Sloan'sLake_FHAD_HEC-RAS-20161007\HEC-RAS\SloansFHAD2017.g01" infile = r"Z:\UDFCD PLANNING\FHAD Review\Clear Creek Round 1\Orig\20161013 Review Submittal\ClearCreek_ModelReviewSubmittal\Hydraulics\ClearCreek_FHAD2016.g07" infile = r"Z:\UDFCD PLANNING\Second Creek\12 FHAD\01_RAS\HEC-RAS\Submittal 2 - working\SCFHAD.g02" geo = prg.ParseRASGeo(infile) cross_sections = geo.extract_xs() print 'There are skews at the flowing cross sections - river, reach, xs_id, skew_angle' skew = False for xs in cross_sections: if xs.skew.angle is not None: print xs.river+','+xs.reach+','+str(xs.header.xs_id)+','+str(xs.skew.angle) skew = True if not skew: print 'No cross sections are skewed'
def main(): infile = r"Z:\UDFCD PLANNING\FHAD Review\Niver Round 3\Orig\20161012 FHAD Submittal\HEC-RAS\NiverCreek_FHAD_Sept.g01" infile = r"Z:\UDFCD PLANNING\Grange Hall Creek\02 HYDRAULICS\HEC-RAS\GHC_FHAD.g01" #infile = r"Z:\UDFCD PLANNING\FHAD Review\Sloans Lake Round 1\Orig\20161013 - Sloan'sLake_FHAD_HEC-RAS-20161007\HEC-RAS\SloansFHAD2017.g01" infile = r"Z:\UDFCD PLANNING\FHAD Review\Niver Round 3\Orig\20161012 FHAD Submittal\HEC-RAS\NiverCreek_FHAD_Sept.g03" #infile = r"Z:\UDFCD PLANNING\FHAD Review\SPR - 6th to 58th\Orig\20160907 Merrick_SPR 6th-58th_08-26-2016\SPR 6th-58th_Existing_HECRAS\SPR_Downstream.g04" infile = r"Z:\UDFCD PLANNING\Second Creek\12 FHAD\01_RAS\HEC-RAS\Submittal 2 - working\SCFHAD.g02" tolerance = 1 geo = prg.ParseRASGeo(infile) cross_sections = geo.extract_xs() for xs in cross_sections: left_elv = xs.sta_elev.elevation(xs.bank_sta.left) right_elv = xs.sta_elev.elevation(xs.bank_sta.right) diff = left_elv - right_elv if abs(diff) >= tolerance: print xs.river + ',' + xs.reach + ',' + str( xs.header.xs_id) + ',' + str(diff)
def n_value_review(geofile, xs_shape_file, xs_id_field, river_field, reach_field, outfile): """ Combines HEC-RAS geometry file and cross section shapefile to create polylines representing areas of consistent surface roughness. :param geofile: HEC-RAS geoemtry file :param xs_shape_file: shape file of cross sections :param xs_id_field: cross section id field in xs_shape_file :param river_field: :param reach_field: :param outfile: name of output shape file :return: nothing """ # the field names cannot have spaces in them in ArcGIS. Replace spaces with "_" if they exist for the new shapefile # use the one with spaces with parsing through the original shapefile new_xs_id_field = xs_id_field.replace(' ', '_') new_river_field = river_field.replace(' ', '_') new_reach_field = reach_field.replace(' ', '_') # Setup output shapefile spatial_reference = arcpy.Describe(xs_shape_file).spatialReference _setup_output_shapefile(outfile, new_xs_id_field, new_river_field, new_reach_field, spatial_reference) message('Importing HEC-RAS geometry...') ras_geo = prg.ParseRASGeo(geofile) message('Done.\nCreating surface roughness review lines...') num_xs_ras_geo = ras_geo.number_xs() num_xs_gis = 0 num_xs_processed = 0 with arcpy.da.SearchCursor( xs_shape_file, ['SHAPE@', xs_id_field, river_field, reach_field]) as xs_cursor: with arcpy.da.InsertCursor(outfile, [ 'SHAPE@', new_xs_id_field, new_river_field, new_reach_field, N_VALUE_FIELD, SEGMENT_ID_FIELD ]) as out_cursor: for xs in xs_cursor: num_xs_gis += 1 geo = xs[0] xs_id = xs[1] river = xs[2] reach = xs[3] if DEBUG: message('*' * 20 + 'working on xs ' + str(xs_id) + '/' + river + '/' + reach) if geo.isMultipart: warn('Warning: Cross section ' + xs_id + ' is multipart. Using part 0.') # Get RAS cross section try: if type(xs_id) is str or type(xs_id) is unicode: warn( 'Cross section station for ' + str(xs_id) + ' is a string in GIS data, trying to cast to a number' ) try: xs_id = float(xs_id) except ValueError: error( 'Unable to convert XS station ' + str(xs_id) + ' to a number. Please remove any characters from the station ' ) sys.exit() geo_xs = ras_geo.return_xs(xs_id, river, reach, strip=True) except prg.CrossSectionNotFound: warn('Warning: Cross section ' + str(xs_id) + '/' + str(river) + '/' + str(reach) + \ ' is in cross section shape file but is not in the HEC-RAS geometry file. Continuing') continue # Check for duplicate n-values test = geo_xs.mannings_n.check_for_duplicate_n_values() if test is not None: message('Cross section ' + str(xs_id) + ' has duplicate n-values at the following stations: ' + \ str(test) + '. This is not visible in the cross section editor but can be seen in the ' + \ 'geometry file.') test = geo_xs.mannings_n.check_for_redundant_n_values() if test is not None: message('Cross section ' + str(xs_id) + ' has redundant n-values at the following stations: ' + \ str(test)) # Fix cross section skew (if present) n_values = _correct_skew(geo_xs) # Enough guard clauses, let's make the n-value review line try: n_lines = _create_n_value_lines(geo, n_values, xs_id) except CrossSectionLengthError: warn('Error: N-value stationing for cross section ' + str(xs_id) + ' in RAS geometry exceeds ' + \ 'GIS feature length. Ignored.') continue num_xs_processed += 1 for i, n_line in enumerate(n_lines): seg_id = river + '-' + reach + '-' + str( xs_id) + '-' + str(i) + '-' + str(n_line[1]) #message([n_line[0], xs_id, river, reach, n_line[1], seg_id]) out_cursor.insertRow( [n_line[0], xs_id, river, reach, n_line[1], seg_id]) warn('There are ' + str(num_xs_ras_geo) + ' cross sections in the HEC-RAS geometry and ' + str(num_xs_gis) + \ ' cross sections in the cross section shape file. ' + str(num_xs_processed) + ' cross sections were' + \ ' successfully converted into surface roughness review lines.')
def iefa_review(geofile, xs_shape_file, xs_id_field, river_field, reach_field, outfile, rnd=False, digits=0): """ Combines HEC-RAS geometry file and cross section shapefile to create polylines representing areas of consistent surface roughness. :param geofile: HEC-RAS geoemtry file :param xs_shape_file: shape file of cross sections :param xs_id_field: cross section id field in xs_shape_file :param river_field: :param reach_field: :param outfile: name of output shape file :param rnd: boolean - round XS ids? :param digits: number of digits to round to """ # the field names cannot have spaces in them in ArcGIS. Replace spaces with "_" if they exist for the new shapefile # use the one with spaces with parsing through the original shapefile new_xs_id_field = xs_id_field.replace(' ', '_') new_river_field = river_field.replace(' ', '_') new_reach_field = reach_field.replace(' ', '_') # Setup output shapefile spatial_reference = arcpy.Describe(xs_shape_file).spatialReference _setup_output_shapefile(outfile, new_xs_id_field, new_river_field, new_reach_field, spatial_reference) message('Importing HEC-RAS geometry...') ras_geo = prg.ParseRASGeo(geofile) message('Done.\nCreating IEFA review lines...') num_xs_ras_geo = ras_geo.number_xs() num_xs_gis = 0 num_xs_processed = 0 with arcpy.da.SearchCursor( xs_shape_file, ['SHAPE@', xs_id_field, river_field, reach_field]) as xs_cursor: with arcpy.da.InsertCursor(outfile, [ 'SHAPE@', new_xs_id_field, new_river_field, new_reach_field, IEFA_FIELD, IEFA_STATUS, PERMANENT_FIELD ]) as out_cursor: for xs in xs_cursor: num_xs_gis += 1 geo = xs[0] xs_id = xs[1] river = xs[2] reach = xs[3] if DEBUG: message('*' * 20 + 'working on xs ' + str(xs_id) + '/' + river + '/' + reach) if geo.isMultipart: warn('Warning: Cross section ' + xs_id + ' is multipart. Using part 0.') try: if type(xs_id) is str or type(xs_id) is unicode: warn( 'Cross section station for ' + str(xs_id) + ' is a string in GIS data, trying to cast to a number' ) try: xs_id = float(xs_id) except ValueError: error( 'Unable to convert XS station ' + str(xs_id) + ' to a number. Please remove any characters from the station ' ) sys.exit() geo_xs = ras_geo.return_xs(xs_id, river, reach, strip=True, rnd=rnd, digits=digits) except prg.CrossSectionNotFound: warn('Warning: Cross section ' + str(xs_id) + '/' + str(river) + '/' + str(reach) + \ ' is in cross section shape file but is not in the HEC-RAS geometry file. Continuing') continue # Verify presence of IEFA if geo_xs.iefa.num_iefa is None: continue # Enough guard clauses, let's make the n-value review line try: iefa_lines = _create_iefa_lines(geo, geo_xs) except CrossSectionLengthError: warn('Error: N-value stationing for cross section ' + str(xs_id) + ' in RAS geometry exceeds ' + \ 'GIS feature length. Ignored.') continue # get the list of the IEFA permanence from the geo xs # use that to determine the permanence of each existant IEFA line # a unique iefa index has to be created because iefa.iefa_permanence # only includes existing IEFA (i.e. iefa_line[1] != 0) iefa_permanence = geo_xs.iefa.iefa_permanence iefa_index = 0 num_xs_processed += 1 for iefa_line in iefa_lines: # only create out IEFA lines that had IEFA, not ones that don't have IEFA if iefa_line[1] == 0: status = 'no' else: status = 'yes' if iefa_permanence[iefa_index] == 0: permanence = 'No' else: permanence = 'Yes' iefa_index += 1 out_cursor.insertRow([ iefa_line[0], xs_id, river, reach, iefa_line[1], status, permanence ]) warn('There are ' + str(num_xs_ras_geo) + ' cross sections in the HEC-RAS geometry and ' + str(num_xs_gis) + \ ' cross sections in the cross section shape file. ' + str(num_xs_processed) + ' cross sections were' + \ ' successfully converted into IEFA review lines.')
def obstruction_review(geofile, xs_shape_file, xs_id_field, river_field, reach_field, outfile): """ Combines HEC-RAS geometry file and cross section shapefile to create polylines representing areas of consistent surface roughness. :param geofile: HEC-RAS geoemtry file :param xs_shape_file: shape file of cross sections :param xs_id_field: cross section id field in xs_shape_file :param river_field: :param reach_field: :param outfile: name of output shape file :return: nothing """ # the field names cannot have spaces in them in ArcGIS. Replace spaces with "_" if they exist for the new shapefile # use the one with spaces with parsing through the original shapefile new_xs_id_field = xs_id_field.replace(' ', '_') new_river_field = river_field.replace(' ', '_') new_reach_field = reach_field.replace(' ', '_') # Setup output shapefile spatial_reference = arcpy.Describe(xs_shape_file).spatialReference _setup_output_shapefile(outfile, new_xs_id_field, new_river_field, new_reach_field, spatial_reference) message('Importing HEC-RAS geometry...') ras_geo = prg.ParseRASGeo(geofile) message('Done.\nCreating blocked obstruction review lines...') num_xs_ras_geo = ras_geo.number_xs() num_xs_gis = 0 num_xs_processed = 0 with arcpy.da.SearchCursor( xs_shape_file, ['SHAPE@', xs_id_field, river_field, reach_field]) as xs_cursor: with arcpy.da.InsertCursor(outfile, [ 'SHAPE@', new_xs_id_field, new_river_field, new_reach_field, BLOCKED_FIELD, BLOCKED_STATUS ]) as out_cursor: for xs in xs_cursor: num_xs_gis += 1 geo = xs[0] xs_id = xs[1] river = xs[2] reach = xs[3] if DEBUG: message('*' * 20 + 'working on xs ' + str(xs_id) + '/' + river + '/' + reach) if geo.isMultipart: warn('Warning: Cross section ' + xs_id + ' is multipart. Using part 0.') try: if type(xs_id) is str or type(xs_id) is unicode: warn( 'Cross section station for ' + str(xs_id) + ' is a string in GIS data, trying to cast to a number' ) try: xs_id = float(xs_id) except ValueError: error( 'Unable to convert XS station ' + str(xs_id) + ' to a number. Please remove any characters from the station ' ) sys.exit() geo_xs = ras_geo.return_xs(xs_id, river, reach, strip=True) # ras_geo = prg_old.return_xs(geo_list, xs_id, river, reach) except prg.CrossSectionNotFound: warn('Warning: Cross section ' + str(xs_id) + '/' + str(river) + '/' + str(reach) + \ ' is in cross section shape file but is not in the HEC-RAS geometry file. Continuing') continue # Verify presence of obstructions if geo_xs.obstruct.num_blocked is None: continue # Enough guard clauses, let's make the n-value review line try: blocked_lines = _create_blocked_lines(geo, geo_xs) except CrossSectionLengthError: warn('Error: N-value stationing for cross section ' + str(xs_id) + ' in RAS geometry exceeds ' + \ 'GIS feature length. Ignored.') continue num_xs_processed += 1 for blocked_line in blocked_lines: # only write out blocked obstructions that exist # do not create them if they don't exist if blocked_line[1] == 0: status = 'no' else: status = 'yes' out_cursor.insertRow([ blocked_line[0], xs_id, river, reach, blocked_line[1], status ]) warn( 'There are ' + str(num_xs_ras_geo) + ' cross sections in the HEC-RAS geometry and ' + str(num_xs_gis) + ' cross sections in the cross section shape file. Obstructions were created at ' + str(num_xs_processed) + ' cross sections.')