Library Reference

Constants

Module to define constant variables and field names across all other modules.

swtbx.objects.constants.ACS_GOAL = 'ACS_GOAL'

Scenario aiming to provide access only in some / all parts of the floodplain.

swtbx.objects.constants.BLDGCOS = 'BLDGCOS'

Efficient cost of raising buildings.

swtbx.objects.constants.BLDGCOS_MX = 'BLDGCOS_MX'

Cost of raising buildings for up to the max flood protection level.

swtbx.objects.constants.BLDGDAM = 'BLDGDAM'

Efficient value of damages to buildings.

swtbx.objects.constants.BLDGDAM_MX = 'BLDGDAM_MX'

Value of damages to buildings for up to the max flood protection level.

swtbx.objects.constants.BLDG_CAPEX = 0.005

Building maintenance capex.

swtbx.objects.constants.BLDG_DEM = 'BLDG_DEM'

Elevation (in Feet) of each building within the cleaned building data.

swtbx.objects.constants.BLDG_ID = 'BLDG_ID'

Unique ID of each building within the cleaned building data.

swtbx.objects.constants.BLDG_SQFT = 'BLDG_SQFT'

Footprint (in sq. ft) of each building within the cleaned building data.

swtbx.objects.constants.BLDG_VALUE = 'BLDG_VAL'

Value (in USD) of each building within the cleaned building data.

swtbx.objects.constants.BOTH_GOALS = 'BOTH_GOALS'

Scenario aiming to provide access in some parts and protection in other parts of the floodplain.

swtbx.objects.constants.CJL = {'branford': 4.3, 'bridgeport': 5, 'clinton': 3.4, 'darien': 5.5, 'east_haven': 4.5, 'east_lyme': 2.3, 'fairfield': 5.2, 'greenwich': 5.5, 'groton': 2, 'guilford': 4, 'hamden': 4.6, 'madison': 3.7, 'milford': 4.7, 'new_haven': 4.6, 'new_london': 2, 'north_haven': 4.6, 'norwalk': 5.4, 'old_lyme': 2.6, 'old_saybrook': 2.9, 'orange': 4.7, 'stamford': 5.5, 'stonington': 2, 'stratford': 4.8, 'waterford': 2.1, 'west_haven': 4.6, 'westbrook': 3.2, 'westport': 5.3}

Coastal jurisdiction values for each town in Connecticut (in Feet). The town names are used to create town obejcts: Town. The CJL values were obtained from DEEP

swtbx.objects.constants.CL_LENGTH = 'CL_LENGTH'

Coastline length (in Meter).

swtbx.objects.constants.DISCOUNT_RATE = 0.025

Discount rate.

swtbx.objects.constants.EXP_TYPE = 'PYTHON3'

Expression type use in field calculation. Based on the ArcGIS tool.

swtbx.objects.constants.FLOODPLAIN_PREFIX = 'fp'

Prefix / Abbreviation for all features, files or folders of type floodplain.

swtbx.objects.constants.FT2M = 0.3048

Conversion unit from feet to meter.

swtbx.objects.constants.GOAL = 'GOAL'

Goal of the scenario / defense plan (based on nature of benefits). Scenarios of the same goal can be compared.

swtbx.objects.constants.GROUP = 'GROUP'

Group of the scenario / defense plan (based on location / extent). Scenarios of the same group can be compared.

Groups are inputted manual from A to Z by the user. The automatic scenario creates 3 groups by default:

  • A: Maximum extent protected by seawall / shoreline protection.

  • B: Maximum extent protected by raised-roads only.

  • Z: All floodplain abandonned. Homeowners have the option to leave or raise their homes.

swtbx.objects.constants.ID_FLOODPLAIN = 9999

Field ID value of any polygons of class floodplain with no scenarios.

swtbx.objects.constants.M2FT = 3.2808

Conversion unit from meter to feet.

swtbx.objects.constants.MIN_BLDG_VALUE = 50000

Minimum value of a building in USD (to exclude parcels with no physical building but has billboards for example as their “building value”).

swtbx.objects.constants.MIN_PCL_SQFT = 3000

Minimum square feet of a parcel or a zone of shared risk.

swtbx.objects.constants.NETBEN = 'NETBEN'

Efficient net benefits of coastal defense scenario.

swtbx.objects.constants.NETBEN_MX = 'NETBEN_MX'

Net benefits of coastal defense scenario for up to the max flood protection level.

swtbx.objects.constants.N_BLDG_PR = 'N_BLDG_PR'

Number of buildings that are protected by the scenario.

swtbx.objects.constants.N_BLDG_RS = 'N_BLDG_RS'

Number of buildings that must be raised given the scenario.

swtbx.objects.constants.OPTHEIGHT = 'OPTHEIGHT'

Efficient NAVD88 height of protection.

swtbx.objects.constants.PCL_DEM = 'PCL_DEM'

Elevation (in Feet) of each parcel within the cleaned parcel data.

swtbx.objects.constants.PCL_ID = 'PCL_ID'

Unique ID of each parcel within the cleaned parcel data.

swtbx.objects.constants.PCL_SQFT = 'PCL_SQFT'

Square feet of each parcel within the cleaned parcel data.

swtbx.objects.constants.PROJECT_PREFIX = 'project'

Prefix for all files or folders of type project.

swtbx.objects.constants.PROJECT_TIME = 30

Useful life of the defense plan (in years).

swtbx.objects.constants.PROTECTED_PREFIX = 'prbldg'

Prefix / Abbreviation for all features, files or folders of type protected building.

swtbx.objects.constants.PR_GOAL = 'PR_GOAL'

Scenario aiming to provide flood protection only in some / all parts of the floodplain. More common for island like regions.

swtbx.objects.constants.RAISED_PREFIX = 'rsbldg'

Prefix / Abbreviation for all features, files or folders of type raised building.

swtbx.objects.constants.RDCOST = 'RDCOST'

Efficient cost of raising roads.

swtbx.objects.constants.RDCOST_MX = 'RDCOST_MX'

Cost of raising roads for up to the max flood protection level.

swtbx.objects.constants.RDHEIGHT = 'RDHEIGHT'

Efficient height above current elevation for roads.

swtbx.objects.constants.RD_CAPEX = 0.005

Road maintenance capex.

swtbx.objects.constants.RD_DEM = 'RD_DEM'

Average road elevation (in Feet).

swtbx.objects.constants.RD_LENGTH = 'RD_LENGTH'

Road length (in Feet).

swtbx.objects.constants.ROAD_PREFIX = 'rd'

Prefix / Abbreviation for all features, files or folders of type road.

swtbx.objects.constants.SCENDESC = 'SCENDESC'

Description of the scenario / defense plan.

swtbx.objects.constants.SEAWALL_PREFIX = 'sw'

Prefix / Abbreviation for all features, files or folders of type seawall.

swtbx.objects.constants.SGCOST = 'SGCOST'

Efficient cost of constructing storm gates.

swtbx.objects.constants.SGCOST_MX = 'SGCOST_MX'

Cost of constructing storm gates for up to the max flood protection level.

swtbx.objects.constants.SGHEIGHT = 'SGHEIGHT'

Efficient height above NAVD88 for storm gates.

swtbx.objects.constants.SG_CAPEX = 0.005

Storm gate maintenance capex.

swtbx.objects.constants.SG_LENGTH = 'SG_LENGTH'

Storm gate length (in Meter).

swtbx.objects.constants.STORMGATE_PREFIX = 'sg'

Prefix / Abbreviation for all features, files or folders of type storm gate.

swtbx.objects.constants.SWCOST = 'SWCOST'

Efficient cost of constructing seawalls.

swtbx.objects.constants.SWCOST_MX = 'SWCOST_MX'

Cost of constructing seawalls for up to the max flood protection level.

swtbx.objects.constants.SWHEIGHT = 'SWHEIGHT'

Efficient height above CJL for seawalls.

swtbx.objects.constants.SW_LENGTH = 'SW_LENGTH'

Seawall length (in Meter).

swtbx.objects.constants.TTLCOST = 'TTLCOST'

Efficient cost of constructing all defense structures.

swtbx.objects.constants.TTLCOST_MX = 'TTLCOST_MX'

Cost of constructing all defense structures for up to the max flood protection level.

swtbx.objects.constants.TTLDAM = 'TTLDAM'

Efficient value of total damages.

swtbx.objects.constants.TTLDAM_MX = 'TTLDAM_MX'

Value of total damages for up to the max flood protection level.

swtbx.objects.constants.URD_COST_H = 578

Cost of raising a road unit by height (feet).

swtbx.objects.constants.URD_COST_L = 1795

Cost of raising a road unit by length (feet).

swtbx.objects.constants.USG_COST = 145000

Cost of building a storm gate unit.

swtbx.objects.constants.UWL_COST = 5200

Cost of building a seawall unit.

swtbx.objects.constants.WETLAND_PREFIX = 'wl'

Prefix / Abbreviation for all features, files or folders of type wetland.

swtbx.objects.constants.WETL_AREA = 'WETL_AREA'

Wetland area.

swtbx.objects.constants.WL_CAPEX = 0.005

Wall maintenance capex.

swtbx.objects.constants.ZERO_GOAL = 'ZERO_GOAL'

Scenario aiming to retreat (no access or flood protection benefits provided).

Town objects

Module to handle spatial objects and models withiin a town.

class swtbx.objects.town.FloodModel(source='')

Create a flood model, and estimate flood frequencies and return periods.

surges

List of surge values.

mu

Location parameter of GEV_CDF() function.

sigma

Scale parameter of GEV_CDF() function.

k

Shape parameter of GEV_CDF() function.

slr_trend

Sea level rise rate (mm/year).

get_flood_projection(return_period=100, project_duration=30)

Estimate the flood level of a return period. Answer questions like: what is the 1/100-year flood level at the end of the project?

Parameters
  • return_period – Return period (in years).

  • project_duration – Duration of the proposed project (in years).

Returns

List containing the Index (in surges) and the Surge value.

get_frequency_table(project_duration=30)

Creates dataframes of flood frequency across different surge level and over time.

Parameters

project_duration – Duration of the proposed project (in years).

Returns

List containing the 2 pandas dataframes of CDF and PDF of all surges values.

swtbx.objects.town.GEV_CDF(s, mu, sigma, k)

Generalized Extreme Value (GEV) function estimating extreme flood frequencies.

The Long Island Sound model is used as default.

Parameters
  • s – surge value (in meter).

  • mu – Location.

  • sigma – Scale.

  • k – Shape.

Returns

CDF of surge value.

class swtbx.objects.town.Town(name)

Create a town object.

name

Town name from CJL.

baseFt

Minimum base height of the wall (CJL) in Feet.

baseM

Minimum base height of the wall (CJL) in Meter.

Scenario objects

Module to handle economic analysis.

class swtbx.objects.scenario.BuildingUnit(uniqueID, value, dem, sqFt)

Creates a building unit object.

uniqueID

Unique ID of the building unit.

value

Value of the building unit.

dem

Elevation of the building unit.

sqFt

Footprint of the building unit.

raise_cost(surges)

Calculates the cost of raising the unit of building for each surge values.

Parameters

surges – Surge values.

Returns

List containing the 2 lists of Total raise costs and Marginal costs for all surges values.

class swtbx.objects.scenario.RoadSegment(seg_ID, rd_length, avg_rd_height)

Creates a road unit object.

seg_ID

Unique ID of the segment corresponding to the road.

rl_length

Length of the road (in Feet).

avg_rd_height

Current elevation of the road (in Feet).

road_cost(surges)

Calculates the cost of raising the unit of road for each surge values.

Parameters

surges – Surge values.

Returns

List containing the 2 lists of Total raise costs and Marginal costs for all surges values.

class swtbx.objects.scenario.SeawallSegment(seg_ID, wl_length, wl_base)

Creates a seawall unit object.

seg_ID

Unique ID of the segment corresponding to the seawall.

wl_length

Length of the seawall (in meter).

wl_base

Base elevation of the seawall (in meter).

wall_cost(surges)

Calculates the cost of constructing the unit of seawall for each surge values.

Parameters

surges – Surge values.

Returns

List containing the 2 lists of Total construction costs and Marginal costs for all surges values.

class swtbx.objects.scenario.StormGate(seg_ID, sg_length, sg_base, sg_max)

Creates a storm gate unit object.

seg_ID

Unique ID of the segment corresponding to the storm gate.

sg_length

Length of the storm gate (in meter).

sg_base

Base elevation of the storm gate (in meter).

sg_max

Max elevation of the storm gate (in meter).

sg_cost(surges)

Calculates the cost of constructing the unit of storm gate for each surge values.

Parameters

surges – Surge values.

Returns

List containing the 2 lists of Total construction costs and Marginal costs for all surges values.

swtbx.objects.scenario.create_building_units(buildings_shp)

Creates building units from a shapefile.

Parameters

buildings_shp – Building shapefile.

Returns

List of building units created from BuildingUnit.

swtbx.objects.scenario.create_default_scenarios(default_zsr, rd_zsr, sw_structure, rd_structure, workspace)

Create scenarios for each zones of shared risks. Each zone will be given a project ID, and a folder will be created for each project. Within each folder there are 4 fileds: fp* for floodplain, sw* for seawall, rd* for roads, sg* for storm gates.

Parameters
  • default_zsr – Default zones of shared risks. Can be obtained from create_raw_segments().

  • rd_zsr – Zones of shared risks for raised roads. Can be obtained from get_flooded_roads().

  • sw_structure – Default location of seawall. Can be obtained from create_raw_segments().

  • rd_structure – Default location of raised-roads. Can be obtained from get_flooded_roads().

  • workspace – Working directory.

swtbx.objects.scenario.get_bldg_mg_raisecosts(bldg_units, surges)

Calculates the cost of raising units of buildings within a segment for each surge values.

Parameters
  • bldg_units – List of building units. Created from BuildingUnit.

  • surges – Surge values.

Returns

List of Marginal raise costs accross all surges values.

swtbx.objects.scenario.get_mg_damages_by_bldg(bldg_units, surges, pdf_table)

Calculates the damages to the flooded buildings within a segment for each surge values.

Parameters
  • bldg_units – List of building units. Created from BuildingUnit.

  • surges – Surge values.

  • pdf_table – Frequency table obtained from FloodModel.

Returns

Dataframe of marginal building damage where each column is a surge value and each row is a building unit.

swtbx.objects.scenario.map_damages(default_zsr, buildings_shp, freq_table, surges, max_flood_params, wetlands_shp)

Calculate the default damages across each of the default segments.

Parameters
  • default_zsr – Default zones of shared risks. Can be obtained from create_raw_segments().

  • buildings_shp – Cleaned building shapefile.

  • freq_table – Frequency table obtained from FloodModel.

  • surges – List of surges values. Can be obtained from FloodModel.

  • max_flood_params – Location of max planned flood. Can be obtained from FloodModel.

  • wetlands_shp – Shapefile of wetlands. Obtained from National Wetlands Invetory.

swtbx.objects.scenario.perform_cba(project_id, cba_dir, source_dir, buildings_shp, raster_dem, road_fragments, freq_table, surges, max_flood_params, wl_base, wetlands_shp)

Perform cost-benefit analysis on each scenario created from create_default_scenarios().

Parameters
  • project_id – ID of the project / segment / ZSR.

  • cba_dir – Folder to store economic results.

  • source_dir – Working directory.

  • buildings_shp – Cleaned building shapefile.

  • raster_dem – Raster DEM.

  • road_fragments – Road data in fragments. Can be obtained from get_flooded_roads().

  • freq_table – Frequency table obtained from FloodModel.

  • surges – List of surges values. Can be obtained from FloodModel.

  • max_flood_params – Location of max planned flood. Can be obtained from FloodModel.

  • wl_base – Base height of the wall or CJL.

  • wetlands_shp – Shapefile of wetlands. Obtained from National Wetlands Invetory.

Generic tools

Generic functions used in the package.

swtbx.tools.generic.calculate_distance(x1, y1, x2, y2)

Calculate distance between two points.

Reference: ESRI Community

Parameters
  • y1 (x1,) – x, y coordinates of point 1.

  • y2 (x2,) – x, y coordinates of point 2.

Returns

Distance between the two points. The distance unit will be the linear unit of the point data.

swtbx.tools.generic.random_string(string_length=10)

Generate random strings.

Reference: PYnative

Parameters

string_length – Desired length of the string. By default the value is set to 10.

Returns

Random string.

Environment tools

Module to manage the workspace.

These functions are built upon the arcpy library from ArcGIS Pro. You can visit ArcGIS Pro reference from more details.

swtbx.tools.env.clean_workspace(wildcard)

Delete (all intermediary) files.

Parameters

wildcard – name pattern of the files to keep in the workspace. All files will be deleted if not specified.

swtbx.tools.env.create_folder(folder_name)

Create a folder in the current directory.

Parameters

folder_name – Name of the folder.

swtbx.tools.env.download_zip_file(url, source_dir)

Download zip file.

Parameters
  • url – Zip file url.

  • source_dir – Destination folder.

swtbx.tools.env.duplicate(input_file, output_name='')

Copy the shapefile / feature class to the current directory.

Parameters
  • input_file – shapefile / feature class object.

  • output_name – desired name of the output.

Returns

A duplicate of the shapefile / feature class.

swtbx.tools.env.duplicate_in_memory(input_file)

Copy the shapefile / feature class to the memory.

Parameters

input_file – shapefile / feature class object.

Returns

A duplicate of the shapefile / feature class.

swtbx.tools.env.set_workspace(folder)

Set the workspace directory.

Parameters

folder – Name of the folder.

Edit tools

Module to perform operations on a single shapefile / feature class.

These functions are built upon the arcpy library from ArcGIS Pro. You can visit ArcGIS Pro reference from more details.

swtbx.tools.edit.add_field(input_feature, field_names, field_type=['LONG'])

Add all fields in the list.

Parameters
  • input_feature – shapefile / feature class object.

  • field_names – list of fields to add.

  • field_type – list of the data types for each field in the same order as field_names.

swtbx.tools.edit.add_geom_attr(input_feature, name='AREA', unit='SQUARE_FEET_US')

Add an area field to the input feature.

Reference: Visit ArcGIS - Add Geom Attributes for a list of geometry that can be added.

Parameters
  • input_feature – shapefile / feature class object.

  • name – name of the geometry to be added.

  • unit – geometry unit.

Returns

An updated shapefile / feature class.

swtbx.tools.edit.add_id(input_feature, id_field='Id', id_formula='!FID!')

Add unique ID field to the input feature.

Parameters
  • input_feature – Shapefile /feature class object.

  • id_field – Name of the ID field.

  • id_formula – PYTHON3 expression to calculate the ID value.

Returns

Features with unique ID.

swtbx.tools.edit.delete_field_in_list(input_feature, field_list)

Delete all fields in the list.

Parameters
  • input_feature – shapefile / feature class object.

  • field_list – List of fields to delete.

swtbx.tools.edit.delete_field_not_in_list(input_feature, field_list)

Delete all fields not in the list.

Parameters
  • input_feature – shapefile / feature class object.

  • field_list – List of fields to keep.

swtbx.tools.edit.get_oid(input_feature)

Get the first field in the shapefile.

Parameters

input_feature – Shapefile / feature class object.

Returns

The first field in the shapefile (FID or OBJECTID).

swtbx.tools.edit.remove_duplicates(input_feature, geom_attr=['POLY_AREA'])

Remove all possible duplicate of a feature based on a geometry attribute.

Parameters
  • input_feature – shapefile / feature class object.

  • geom_attr – name of the field with geometry attribute.

Returns

An updated shapefile / feature class without any duplicates.

swtbx.tools.edit.remove_features_in_list(input_feature, id_list, id_field='UniqueID')

Delete all features specificied in the list.

Parameters
  • input_feature – shapefile / feature class object.

  • id_list – list of the of the features to be deleted.

  • id_field – name of the ID field in the input feature.

Returns

An updated shapefile / feature class.

swtbx.tools.edit.remove_small_polygons(input_feature, minimum_area=3000)

Remove small polygons.

Parameters
  • input_feature – Shapefile / feature class object.

  • minimum_area – Minimum area of the polygon. The default value 3000 is in sq. ft.

Returns

An updated shapefile.

swtbx.tools.edit.save_features_in_list(input_feature, id_list, id_field='UniqueID')

Save all features specificied in the list.

Parameters
  • input_feature – shapefile / feature class object.

  • id_list – list of the of the features to be saved.

  • id_field – name of the ID field in the input feature.

Returns

An updated shapefile / feature class.

swtbx.tools.edit.select_by_attribute(input_feature, attr_name, attr_value, invert='NON_INVERT', cond='=')

Filter rows of the input feature based on attribute value.

Parameters
  • input_feature – shapefile / feature class object.

  • attr_name – name of the attribute field to use as filter.

  • attr_value – attribute value to use in the filter expression.

  • invert – whether to invert the expression. NON_INVERT to not invert (default). INVERT to invert.

  • cond – condition to use in the filter expression. Possible values: <, >=, etc.

Returns

A subset of the shapefile / feature class.

swtbx.tools.edit.set_crs(ref_fc, target_fc)

Transform the coordinate system of the feature that doesn’t match the desired crs.

Parameters
  • ref_fc – reference shapefile / feature class object.

  • target_fc – list of shapefile / feature class object.

Returns

List of transformed shapefile / feature class object.

Overlay tools

Module to perform operations on a group of shapefiles / feature classes.

These functions are built upon the arcpy library from ArcGIS Pro. You can visit ArcGIS Pro reference from more details.

swtbx.tools.overlay.add_feature_length(target_feature, ref_line, field_name)

Calculate and add feature length to a target intersecting feature.

Parameters
  • target_feature – Shapefile / feature class object where the length will be added.

  • ref_line – Shapefile / feature class object used to calculate the line.

  • field_name – name of the field to store the length values (in Meter).

Returns

Target feature with length values from reference line.

swtbx.tools.overlay.find_overlaps(selecting_feature, target_feature)

Find overlaps if one feature from selecting feature (parcels) overlaps multiple features in the target feature (buildings).

Parameters
  • selecting_feature – shapefile / feature class object.

  • target_feature – shapefile / feature class object.

Returns

those who have multiple overlaps, those who doesn’t.

Return type

A list containing two shapefiles

swtbx.tools.overlay.get_dem_stats(input_feature, id_field, dem_field, raster_dem, join_type='KEEP_ALL', exp_type='PYTHON3')

Add the statistics of DEM values to a feature class.

Parameters
  • input_feature – shapefile / feature class object.

  • id_field – unique ID field used to get statistics of DEM.

  • dem_field – desired name of the DEM field in the output.

  • raster_dem – raster layer of the DEM.

  • join_type – whether to keep only matching records: KEEP_COMMON; or all records: KEEP_ALL (default - account for overlapping polygons.)

  • exp_type – Expression type for the CalculateField_management function.

Returns

A shapefile / feature class with DEM values for each row.

swtbx.tools.overlay.get_largest_feature(input_feature, workspace, target_feature, input_id_field, target_id_field)

Get the largest feature from a group of features (sharing the same spatial relationship to an input feature).

Parameters
  • input_feature – shapefile / feature class object.

  • workspace – where to save the output.

  • target_feature – shapefile / feature class object.

  • input_id_field – unique ID field of the input feature (containing feature).

  • target_id_field – unique ID field of the group of features.

Returns

The largest feature from the group of features.

swtbx.tools.overlay.remove_irrelevant_polygons(input_feature, reference_feature, workspace, minimum_area=1300)

Remove irrelevant polygons based on a reference feature.

Parameters
  • input_feature – Shapefile / feature class object.

  • reference_feature – Shapefile / feature class object.

  • workspace – the working directory.

  • minimum_area – Minimum area of the polygon. The default value 1300 is in sq. ft.

Returns

An updated shapefile.

swtbx.tools.overlay.select_by_location(input_feature, selecting_feature, relationship='INTERSECT', invert='NOT_INVERT')

Filter rows of the input feature based on spatial relationship to another feature.

Reference: Visit ArcGIS - Select By Location for a list of possible spatial relationship.

Parameters
  • input_feature – shapefile / feature class object.

  • selecting_feature – shapefile / feature class object.

  • relationship – spatial relationship between the 2 features. input_feature that relationship selecting_feature.

  • default, 'INTERSECT'. (By) –

  • invert – whether to invert the expression. NOT_INVERT to not invert (default). INVERT to invert.

Returns

A subset of the shapefile / feature class.

swtbx.tools.overlay.spatial_join(target_feature, join_feature, in_fields, stats, match_option)

Join two features based on spatial relationship.

Reference: Visit ArcGIS - Spatial Join for a list of possible ‘match_option’.

Parameters
  • target_feature – shapefile / feature class object.

  • join_feature – shapefile / feature class object.

  • in_fields – list of fields to keep and with specified merge rule in stats.

  • stats – list of merge rules for the values if multiple join features have the same match_option.

  • match_option – spatial relationship between the 2 features. target_feature that match_option join_feature.

Returns

An updated shapefile / feature class.

Landscape tools

Module to create topographic features within a town.

These functions are built upon the arcpy library from ArcGIS Pro. You can visit ArcGIS Pro reference from more details.

swtbx.tools.landscape.calculate_line_length(input_line, lUnit='FEET_US')

Calculate the length of an input line.

Parameters
  • input_polygon – Shapefile object.

  • aUnit – Length unit. Visit ArcGIS documentation for other possible values.

Returns

The total length of the line features.

swtbx.tools.landscape.calculate_polygon_area(input_polygon, aUnit='SQUARE_METERS')

Calculate the area of an input polygon.

Parameters
  • input_polygon – Shapefile object.

  • aUnit

    Area unit. Visit ArcGIS documentation for other possible values.

Returns

The total area of the polygon features.

swtbx.tools.landscape.connect_edge_points_with_line(point_1, point_2, workspace)

Connect two points (of different contour) with line feature.

Used to connect segment edges. In the Seawall Toolbox, point_1 comes from the Coastal Jurisdiction Line, and point_2 from the 1/100-year line.

Parameters
  • point_1 – Group of points on a contour line. ???

  • point_2 – Another group of points on a different contour line. ???

  • workspace – The working directory.

Returns

List of points on the outer part of clusters.

swtbx.tools.landscape.create_contour(contour_lines, dem_value, unit='FEET')

Get contour lines corresponding to a DEM value.

For this version, all units must be in Feet.

Parameters
  • contour_lines – Contour data on a specific. It can be created using DEM.

  • dem_value – Elevation of the contour in Feet.

  • unit – just a reminder that all units are in FEET.

Returns

A contour line of the DEM value.

swtbx.tools.landscape.create_random_points(input_line, pt_spacing, unique_id='UniqueID')

Create random points along a (contour) line.

Parameters
  • input_line – The (contour) line. Can be obtained with create_contour().

  • pt_spacing – Desired spacing between the points (in Feet).

  • unique_id – Name of the field to store unique identifier for each point.

Returns

Random points along a line.

swtbx.tools.landscape.create_raw_segments(segment_base, segment_max, pt_spacing, th_list, raster_dem, workspace, buildings, roads='')

Creates zones of shared risks.

Parameters
  • segment_base – Line (contour) indicating wall locations.

  • segment_max – Line (contour) indicating max (1/100-year) flood.

  • pt_spacing – Desired spacing between the points (in Feet).

  • th_list – Arbitrary list of threshold values (in Feet).

  • raster_dem – Raster DEM.

  • workspace – The working directory.

  • ccl_shp – Island-lowland lines.

  • buildings – Buildings shapefile.

  • roads – Roads shapefile to be used as reference (optional).

Returns

Coastal segments with independent risk of flooding.

swtbx.tools.landscape.filter_points(point_feature, threshold, id_field='UniqueID', min_th=0)

Filter points within threshold.

Parameters
  • input_feature – Points object obtained from Near_Analysis.

  • threshold – Maximum distance between points of different contour lines. This value controls for the steepness of the edge of the zones of shared risk. High threshold value translate to flatter edge.

  • id_field – Field with unique identifier.

  • min_th – Minimum distance between points of different contour lines. Helps if the topography is mostly steep.

Returns

Filtered / subset points.

swtbx.tools.landscape.get_building_bounds(input_segments, input_buildings, segment_base, segment_max, workspace, buffer=25)

Get bounding box of a group of buildings.

Parameters
  • input_segments – Coastal segments created with create_raw_segments().

  • input_buildings – Buildings within the max (1/100-year) floodplain.

  • segment_base – Line (contour) indicating wall locations.

  • segment_max – Line (contour) indicating max (1/100-year) flood.

  • workspace – The working directory.

  • buffer – Buffer of the bounding box (in Feet).

Returns

Building bounds that could serve as seawalls.

swtbx.tools.landscape.get_complete_seawall(segment_base, pts_base, edge_wall, bldg_bbox, ccl_shp, input_segment)

Get bounding box of a group of buildings.

Parameters
  • segment_base – Line (contour) indicating wall locations.

  • pts_base – Edge points along line (contour) indicating max (1/100-year) flood.

  • edge_wall – Additional seawalls on segment edge.

  • bldg_bbox – Additional seawalls on building box.

  • ccl_shp – Island-lowland lines.

  • input_segment – Coastal segments.

Returns

Coastline and seawalls.

swtbx.tools.landscape.get_flooded_buildings(buildings_shp, lowlands_shp, raster_dem, surge_level, workspace)

Get the subset of flooded buildings in a town.

Parameters
  • buildings_shp – Raw buildings data.

  • lowlands_shp – Lowland polygons.

  • raster_dem – Raster DEM.

  • surge_level – Surge level in Feet.

  • workspace – The working directory.

Returns

Flooded buildings.

swtbx.tools.landscape.get_flooded_roads(osm_roads, zsr, segment_max)

Get flooded roads within the .

Parameters
  • osm_roads – Raw road data (can be downloaded from OpenStreetMap).

  • zsr – Zones of share risks.

  • segment_max – Line (contour) indicating max (1/100-year) flood.

Returns

List of Proposed raised-roads, Split roads, and Bridges.

swtbx.tools.landscape.get_highlowlands_edges(base_points, workspace)

Finding highlands / lowlands edges.

Used to create lines that when combined with contour lines will create either upland or lowland regions that shouldn’t be part of the zones at risk of flooding.

Parameters
  • base_points – Subset of relevant points on the wall base contour line.

  • workspace – The working directory.

Returns

Lines used to create upland/lowland regions.

swtbx.tools.landscape.get_line_fragments(input_line, frg_length='1 Meters')

Convert a line feature into fragments.

Parameters
  • input_line – Input line feature (roads).

  • frg_length – Length of each line fragment.

Returns

Line features into fragments of frg_length.

swtbx.tools.landscape.get_narrow_segment_lines(wall_base, workspace, th=35, sp=40)

Creates lines on narrow part of flooplain which will help create highland / lowland like regions.

Parameters
  • wall_base – Line (contour) on indicating wall locations.

  • workspace – The working directory.

  • th – Arbitrary threshold value in Feet.

  • sp – Arbitrary point spacing value in Feet.

Returns

Line feature class.

swtbx.tools.landscape.get_outer_in_cluster(cluster_points, min_wall, id_field='UniqueID')

Get outer points within cluster.

Parameters
  • cluster_points – Points object obtained from filter_points(). ???

  • min_wall – Minimum distance between points of same contour lines. This value controls for the accuracy of the location of the edge of the zones of shared risk. High threshold value translate to innacurate edge, but small value could cost the performance of the tool.

  • id_field – Field with unique identifier.

Returns

List of points on the outer part of clusters.

swtbx.tools.landscape.get_road_dem(road_project, road_fragments, raster_dem, zsr, dem_field='RD_DEM')

Get the road dem.

Parameters
  • road_project – Input road feature.

  • road_fragments – Road data in fragments (of 1 meter).

  • raster_dem – Raster DEM.

  • zsr – Zones protected by the raised road.

  • dem_field – Field to store DEM value.

Returns

Road feature with elevation statistics.

swtbx.tools.landscape.identify_edges(point_1, point_2, th_list, sp_list, workspace, ref_feature)

Identify segment edges using random points created on lines.

Parameters
  • point_1 – Random points on the wall base line.

  • point_2 – Random points on the max (1/100-year) flood line.

  • th_list – Arbitrary list of threshold values in Feet.

  • sp_list – Arbitrary list of point spacing values in Feet.

  • workspace – The working directory.

  • ref_feature – Constraining features where the segment edges can’t be located (ex: buildings, etc.).

Returns

Point feature locating segment edges and some additional seawalls.

swtbx.tools.landscape.merge_all_structures(source_dir, n_proj, template_shp)

Merge all individual defense structure features into 1 file i.e. seawalls + storm gates + raised roads.

Parameters
  • source_dir – Folder containing all (raw) project files.

  • n_proj – Number of projects.

  • template_shp – Template structure file (Just choose any of the structure files).

Returns

Merged defense structures.

swtbx.tools.landscape.subset_by_dem(input_feature, ref_feature, raster_dem, min_dem=4.5)

Remove features below certain elevation threshold.

Parameters
  • input_feature – Features to subset.

  • ref_feature – Reference feature.

  • raster_dem – Raster DEM.

  • workspace – The working directory.

  • min_dem – Elevation threshold in Feet. Usually the value of the contour base.

Returns

Lines used to create upland/lowland regions.