Skip to content

Commit

Permalink
Merge pull request #182 from bacetiner/master
Browse files Browse the repository at this point in the history
TranspInventoryGenerator now displays combined inventory file name and location
  • Loading branch information
bacetiner authored Jan 29, 2024
2 parents 1ddb508 + 661fbe2 commit 69fb187
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions brails/TranspInventoryGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#
# Last updated:
# 01-26-2024
# 01-29-2024


import geopandas as gpd
Expand All @@ -52,7 +52,7 @@
import warnings
import numpy as np
from datetime import datetime
import brails
from importlib.metadata import version
from brails.workflow.TransportationElementHandler import TransportationElementHandler

# The map defines the default values according to MTFCC code
Expand All @@ -71,7 +71,6 @@
"S1710":25, "S1720":25, "S1730":25, "S1740":10, "S1750":10, "S1780":10,
"S1810":10, "S1820":10, "S1830":10}


class TranspInventoryGenerator:

def __init__(self, location='Berkeley, CA'):
Expand Down Expand Up @@ -112,7 +111,7 @@ def combineAndFormat_HWY(self, minimumHAZUS=True, connectivity=False, maxRoadLen
bnodeDF = gpd.GeoDataFrame(columns = ["nodeID", "geometry"], crs = "epsg:4326")
bridgesDict = {'type':'FeatureCollection',
'generated':str(datetime.now()),
'brails_version': brails.__version__,
'brails_version': version('BRAILS'),
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},
'units': {"length": lengthUnit},
'features':[]}
Expand All @@ -132,7 +131,7 @@ def combineAndFormat_HWY(self, minimumHAZUS=True, connectivity=False, maxRoadLen
rnodeDF = gpd.GeoDataFrame(columns = ["nodeID", "geometry"], crs = "epsg:4326")
roadsDict = {'type':'FeatureCollection',
'generated':str(datetime.now()),
'brails_version': brails.__version__,
'brails_version': version('BRAILS'),
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},
'units': {"length": lengthUnit},
'features':[]}
Expand All @@ -146,7 +145,7 @@ def combineAndFormat_HWY(self, minimumHAZUS=True, connectivity=False, maxRoadLen
tnodeDF = gpd.GeoDataFrame(columns = ["nodeID", "geometry"], crs = "epsg:4326")
tunnelsDict = {'type':'FeatureCollection',
'generated':str(datetime.now()),
'brails_version': brails.__version__,
'brails_version': version('BRAILS'),
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},
'units': {"length": lengthUnit},
'features':[]}
Expand All @@ -158,10 +157,10 @@ def combineAndFormat_HWY(self, minimumHAZUS=True, connectivity=False, maxRoadLen
# Dump to json file
with open("hwy_inventory.geojson", "w") as f:
json.dump(combinedGeoJSON, f, indent = 2)

print('Combined transportation inventory saved in hwy_inventory.geojson'
'This file is suitable for R2D use and is available in {os.getcwd()}')
return


# Convert common length units
def convertUnits(value, unit_in, unit_out):
aval_types = ['m', 'mm', 'cm', 'km', 'inch', 'ft', 'mile']
Expand All @@ -180,7 +179,6 @@ def convertUnits(value, unit_in, unit_out):
value = value*scale_map[unit_in]/scale_map[unit_out]
return value


# Break down long roads according to delta
def breakDownLongEdges(edges, delta, nodes = None, tolerance = 10e-3):
dropedEdges = []
Expand Down Expand Up @@ -401,7 +399,6 @@ def explodeLineString(roads_gdf):
expandedRoads.append(newRoad)
expandedRoads = gpd.GeoDataFrame(expandedRoads, crs=crs)
return expandedRoads


def formatRoads(minimumHAZUS, connectivity, maxRoadLength, roads_gdf):
if roads_gdf.shape[0] == 0:
Expand Down Expand Up @@ -494,14 +491,13 @@ def formatTunnels(minimumHAZUS, connectivity, tunnels_gdf):
tunnels_gdf["type"] = "Tunnel"
tunnels_gdf["assetSubtype"] = "HwyTunnel"
tunnelDict = json.loads(tunnels_gdf.to_json())
return tnodeDF, tunnelDict

return tnodeDF, tunnelDict

def combineDict(bnodeDF, bridgesDict, rnodeDF, roadsDict, tnodeDF, tunnelsDict,
connectivity, lengthUnit, crs="epsg:4326"):
combinedDict = {'type':'FeatureCollection',
'generated':str(datetime.now()),
'brails_version': brails.__version__,
'brails_version': version('BRAILS'),
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},
'units': {"length": lengthUnit},
'features':[]}
Expand Down

0 comments on commit 69fb187

Please sign in to comment.