Skip to content

Commit

Permalink
Handle tables that are None
Browse files Browse the repository at this point in the history
  • Loading branch information
reyery committed Apr 30, 2024
1 parent 9145fe2 commit 59676a1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cea/interfaces/dashboard/api/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ def put(self):
location = getattr(locator, db_info['location'])()
file_type = db_info['file_type']

if len(tables[db]) != 0:
if tables.get(db) is None: # ignore if table does not exist
continue

if len(tables[db]):
if file_type == 'shp':
from cea.utilities.standardize_coordinates import get_geographic_coordinate_system
table_df = geopandas.GeoDataFrame.from_features(geojsons[db]['features'],
crs=get_geographic_coordinate_system())
out['geojsons'][db] = json.loads(table_df.to_json(show_bbox=True))
out['geojsons'][db] = json.loads(table_df.to_json())
table_df = table_df.to_crs(crs[db])
table_df.to_file(location, driver='ESRI Shapefile', encoding='ISO-8859-1')

Expand All @@ -173,15 +175,22 @@ def put(self):
cea.utilities.dbf.dataframe_to_dbf(table_df, location)
out['tables'][db] = json.loads(table_df.set_index('Name').to_json(orient='index'))

else: # delete file if empty
out['tables'][db] = {}
if os.path.isfile(location):
else: # delete file if empty unless it is surroundings (allow for empty surroundings file)
if db == "surroundings":
table_df = geopandas.GeoDataFrame(columns=["Name", "height_ag", "floors_ag"], geometry=[],
crs=get_geographic_coordinate_system())
table_df.to_file(location)

out['tables'][db] = []

elif os.path.isfile(location):
if file_type == 'shp':
import glob
for filepath in glob.glob(os.path.join(locator.get_building_geometry_folder(), '%s.*' % db)):
os.remove(filepath)
elif file_type == 'dbf':
os.remove(location)

if file_type == 'shp':
out['geojsons'][db] = {}

Expand Down

0 comments on commit 59676a1

Please sign in to comment.