Skip to content

Commit

Permalink
Merge pull request #199 from bacetiner/master
Browse files Browse the repository at this point in the history
Cleaned and updated EnabledAttributes and added type hints to workflow methods
  • Loading branch information
bacetiner authored Mar 30, 2024
2 parents 0fcc0f8 + 493575e commit 9959fc3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
21 changes: 15 additions & 6 deletions brails/EnabledAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@
# Barbaros Cetiner
#
# Last updated:
# 03-21-2024
# 03-28-2024

def BldgAttributes():
attr = ['buildingheight','chimney','erabuilt',
'garage','numstories','occupancy',
'roofeaveheight','roofshape','roofpitch',
'constype', 'roofcover','constype']
return attr
attr = ['buildingheight','chimney','constype','erabuilt','garage',
'numstories','occupancy','roofcover','roofeaveheight','roofshape',
'roofpitch','windarea']
return attr

def BRAILStoR2D_BldgAttrMap():
r2dHeaders = ['BuildingHeight','ChimneyExists','StructureType',
'YearBuilt','GarageExists','NumberOfStories',
'OccupancyClass','RoofCoverType','RoofEaveHeight',
'RoofShape','RoofPitch','WindowAreaRatio']
brailsAttributes = BldgAttributes()
brails2r2dmap = {}
for ind,attr in enumerate(brailsAttributes):
brails2r2dmap[attr] = r2dHeaders[ind]
15 changes: 8 additions & 7 deletions brails/workflow/FootprintHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# Barbaros Cetiner
#
# Last updated:
# 03-26-2024
# 03-29-2024

import math
import json
Expand All @@ -64,7 +64,7 @@ def __init__(self):
self.lengthUnit = 'ft'
self.queryarea = []

def __fetch_roi(self,queryarea,outfile=False):
def __fetch_roi(self,queryarea:str,outfile:str=''):
# Search for the query area using Nominatim API:
print(f"\nSearching for {queryarea}...")
queryarea = queryarea.replace(" ", "+").replace(',','+')
Expand Down Expand Up @@ -145,7 +145,7 @@ def __fetch_roi(self,queryarea,outfile=False):
write_polygon2geojson(bpoly,outfile)
return bpoly, queryarea_printname, queryarea_osmid

def __bbox2poly(self,queryarea,outfile=False):
def __bbox2poly(self,queryarea:tuple,outfile:str=''):
# Parse the entered bounding box into a polygon:
if len(queryarea)%2==0 and len(queryarea)!=0:
if len(queryarea)==4:
Expand All @@ -169,7 +169,7 @@ def __bbox2poly(self,queryarea,outfile=False):
write_polygon2geojson(bpoly,outfile)
return bpoly, queryarea_printname

def __write_fp2geojson(self,footprints,attributes,outputFilename):
def __write_fp2geojson(self,footprints:list,attributes:dict,outputFilename:str):
attrkeys = list(attributes.keys())
geojson = {'type':'FeatureCollection',
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},
Expand All @@ -188,8 +188,8 @@ def __write_fp2geojson(self,footprints,attributes,outputFilename):
with open(outputFilename, 'w') as outputFile:
json.dump(geojson, outputFile, indent=2)

def fetch_footprint_data(self,queryarea,fpSource='osm',attrmap=None,
lengthUnit='ft',outputFile='footprints.geojson'):
def fetch_footprint_data(self,queryarea,fpSource:str='osm',attrmap:str='',
lengthUnit:str='ft',outputFile:str=''):
"""
Function that loads footprint data from OpenStreetMap, Microsoft, USA
Structures, user-defined data
Expand Down Expand Up @@ -1084,4 +1084,5 @@ def fp_source_selector(self):
del self.attributes[key][i]

# Write the footprint data into a GeoJSON file:
self.__write_fp2geojson(self.footprints, self.attributes, outputFile)
if outputFile:
self.__write_fp2geojson(self.footprints, self.attributes, outputFile)
4 changes: 2 additions & 2 deletions brails/workflow/NSIParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# Barbaros Cetiner
#
# Last updated:
# 03-26-2024
# 03-28-2024

import requests
import pandas as pd
Expand Down Expand Up @@ -212,7 +212,7 @@ def GetRawDataROI(self,roi,outfile:str)->None:
with open(outfile, 'w') as outputFile:
json.dump(geojson, outputFile, indent=2)

def GetNSIData(self,footprints:list,lengthUnit:str='ft',outfile=None):
def GetNSIData(self,footprints:list,lengthUnit:str='ft',outfile:str=''):
"""
Method that reads NSI buildings points and matches the data to a set
of footprints and writes the data in a BRAILS-compatible format
Expand Down

0 comments on commit 9959fc3

Please sign in to comment.