-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving additional info zone helper #3388
Changes from all commits
afcb954
c805665
70476d7
8b30145
1be8d70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,12 +72,6 @@ def assign_attributes(shapefile, buildings_height, buildings_floors, buildings_h | |
'if we do not find data in OSM for a particular building, we estimate it based on the number of floors, ' | ||
'multiplied by a pre-defined floor-to-floor height (set to 3m by default)') | ||
|
||
# Make sure relevant OSM parameters (if available) are passed as floats, not strings | ||
OSM_COLUMNS = ['building:min_level', 'min_height', 'building:levels', 'height'] | ||
selected_columns = list(set(list_of_columns).intersection(set(OSM_COLUMNS))) | ||
shapefile[selected_columns] = shapefile[selected_columns] \ | ||
.fillna(1).apply(lambda x: pd.to_numeric(x, errors='coerce')) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MatNif There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I think you're right. I missed that. In that case, I think this PR is good to go. |
||
# Make sure relevant OSM parameters (if available) are passed as floats, not strings | ||
OSM_COLUMNS = ['building:min_level', 'min_height', 'building:levels', 'height'] | ||
shapefile[[c for c in OSM_COLUMNS if c in list_of_columns]] = \ | ||
|
@@ -191,6 +185,46 @@ def assign_attributes(shapefile, buildings_height, buildings_floors, buildings_h | |
|
||
return shapefile | ||
|
||
def assign_attributes_additional(shapefile): | ||
""" | ||
This script fills the zone.shp file with additional information from OSM, | ||
including house number, street name, postcode, if HDB (for Singapore), city, country | ||
""" | ||
# TODO: include different terms used by OSM in different countries | ||
# As of 19 Sept 2023, this function works fine in Switzerland and Singapore | ||
|
||
# local variables | ||
no_buildings = shapefile.shape[0] | ||
list_of_columns = shapefile.columns | ||
|
||
# Check which attributes OSM has (sometimes it does not have any) and create the column if missing | ||
if 'addr:city' not in list_of_columns: | ||
shapefile['addr:city'] = [''] * no_buildings | ||
if 'addr:country' not in list_of_columns: | ||
shapefile['addr:country'] = [''] * no_buildings | ||
if 'addr:postcode' not in list_of_columns: | ||
shapefile['addr:postcode'] = [''] * no_buildings | ||
if 'addr:street' not in list_of_columns: | ||
shapefile['addr:street'] = [''] * no_buildings | ||
if 'addr:housename' not in list_of_columns: | ||
shapefile['addr:housename'] = [''] * no_buildings | ||
if 'addr:housenumber' not in list_of_columns: | ||
shapefile['addr:country'] = [''] * no_buildings | ||
if 'residential' not in list_of_columns: | ||
shapefile['residential'] = [''] * no_buildings #not HDB | ||
|
||
# Assign the cea-formatted columns with attributes | ||
shapefile['house_no'] = shapefile['addr:housenumber'] | ||
shapefile['street'] = shapefile['addr:street'] | ||
shapefile['postcode'] = shapefile['addr:postcode'] | ||
shapefile['house_name'] = shapefile['addr:housename'] | ||
shapefile['resi_type'] = shapefile['residential'] | ||
shapefile['city'] = shapefile['addr:city'] | ||
shapefile['country'] = shapefile['addr:country'] | ||
|
||
return shapefile | ||
|
||
|
||
|
||
def fix_overlapping_geoms(buildings, zone): | ||
""" | ||
|
@@ -482,6 +516,10 @@ def polygon_to_zone(buildings_floors, buildings_floors_below_ground, buildings_h | |
shapefile = assign_attributes(shapefile, buildings_height, buildings_floors, | ||
buildings_height_below_ground, buildings_floors_below_ground, key="B") | ||
|
||
# adding additional information from OSM | ||
# (e.g. house number, street number, postcode, if HDB for Singapore buildings) | ||
shapefile = assign_attributes_additional(shapefile) | ||
|
||
# fix geometries of buildings with overlapping polygons | ||
if fix_overlapping is True: | ||
print("Fixing overlapping geometries.") | ||
|
@@ -498,7 +536,7 @@ def polygon_to_zone(buildings_floors, buildings_floors_below_ground, buildings_h | |
# clean up attributes | ||
cleaned_shapefile = shapefile[ | ||
["Name", "height_ag", "floors_ag", "height_bg", "floors_bg", "description", "category", "geometry", | ||
"REFERENCE"]] | ||
"REFERENCE", 'house_no', 'street', 'postcode', 'house_name', 'resi_type', 'city', 'country']] | ||
cleaned_shapefile = cleaned_shapefile.to_crs(get_projected_coordinate_system(float(lat), float(lon))) | ||
|
||
# save shapefile to zone.shp | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the changes look good to be. The only question I have is about the removal of the string-to-float conversion for some of the parameters (lines 75-80): What's the reasoning behind removing that section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this.
Please see my comments below.