Commit bbb7a66b authored by Simantini Shinde's avatar Simantini Shinde
Browse files

Imported dwelling sizes data

parent e0de71e7
Pipeline #39418 passed with stage
in 1 minute and 48 seconds
......@@ -102,3 +102,9 @@ WGS84 = 4326
DWELLING_DENSITY_HOUSEHOLD = 15
HOUSEHOLD_NUMBER_DENSITY = 13
HOUSEHOLD_MEMBER_DENSITY = 14
# Constant numbers for import of dwelling-size data to DwellingDistribution table
NUMBER_DWELLING_SIZES = 6
# Constant numbers for import of dwelling-size data to DwellingFloorspace table
FLOORSPACE_PER_DWELLING_DWELLING_SIZES = 13
......@@ -315,6 +315,21 @@ class JapanDatabase(SpatialiteDatabase):
sql_statement += "VALUES (%d, '%s')" % (tenure_type_id, description)
self.cursor.execute(sql_statement)
def insert_dwelling_size_type(self, dwelling_size_type_id, description):
"""
Inserts a dwelling-size description to the DwellingSizeType table.
Args:
dwelling_size_type_id (int):
ID of the dwelling-size type entry
description (str):
Description of the dwelling-size type entry
"""
sql_statement = "INSERT INTO DwellingSizeType (id, description) "
sql_statement += "VALUES (%d, '%s')" % (dwelling_size_type_id, description)
self.cursor.execute(sql_statement)
def import_districts_and_boundaries(self, district_boundary_filepath):
"""
Imports all districts and boundaries from a prepared geopackage file.
......@@ -1298,12 +1313,173 @@ class JapanDatabase(SpatialiteDatabase):
self.connection.commit()
logger.info("Household data added")
def import_floorspace_and_dwelling_sizes(
self,
dwelling_sizes_filepath,
building_type_list,
dwelling_type_list,
tenure_type_list,
construction_material_list,
dwelling_size_type_list,
):
"""
Imports dwelling-size data from the 2018 building statistics files
provided by E-Stat, Japan. The following file is needed:
List of dwelling sizes by municipality (dwelling_sizes_filepath)
The dwelling-size data provide the average dwelling floorspace area
(in square meters) for the combination of different building and dwelling
attributes, imported into the DwellingFloorspace table:
- dwelling types (total, used exclusively for living, used also for commerce
or other purposes),
- tenure types (total, owned houses, rented houses, rented houses owned by
local government, rented houses owned by urban renaissance agency or
public corporation, rented houses owned privately, issued houses)
- building types (total, detached house, tenement house, apartments and
others),
- construction material type (total, wooden, wooden (excluding wooden and
fire-proofed), wooden and fire-proofed and non-wooden)
Also, it provides the number of dwellings for the combination of different
building and dwelling attributes, imported into the DwellingDistribution table:
- dwelling types (total, used exclusively for living, used also for commerce
or other purposes),
- tenure types (total, owned houses, rented houses, rented houses owned by
local government, rented houses owned by urban renaissance agency or
public corporation, rented houses owned privately, issued houses)
- building types (total, detached house, tenement house, apartments and
others),
- construction material type (total, wooden, wooden (excluding wooden and
fire-proofed), wooden and fire-proofed and non-wooden),
- dwelling size type (total, 29m^2 and under, 30m^2 to 49m^2, 50m^2 to 69m^2,
70m^2 to 99m^2, 100m^2 to 149m^2, 150m^2 and over)
This dwelling-size data is not available for all districts in Japan
i.e. the districts with population less than 15000 are ignored in the
building statistics.
Args:
dwelling_sizes_filepath (str):
Filepath to the file of dwelling floorspace (in square meters) and
number of dwellings.
building_type_list (list):
Collection of types of buildings from the dwelling-size data file.
dwelling_type_list (list):
Collection of types of dwellings from the dwelling-size data file.
tenure_type_list (list):
Collection of the dwelling tenures from the dwelling-size data file.
construction_material_list (list):
Collection of types of construction materials from the dwelling-
size data file.
dwelling_size_type_list (list):
Collection of types of dwelling sizes from the dwelling-size
"""
# Read columns identification area code, district, building type, dwelling type,
# tenure type, construction material type, dwelling-size type, number of dwellings
# and floorspace per dwelling from input CSV file
dwelling_sizes_input = pandas.read_excel(
dwelling_sizes_filepath,
header=10,
usecols=[4, 5, 7, 9, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21],
)
for index, row in dwelling_sizes_input.iterrows():
admin_id = int((row["Area classification"].split("_"))[0])
# Identify district_id based on admin_id from the District table
district_id_result = self.get_district_id(admin_id)
if district_id_result is None: # Only data for which a district exist matter
continue
district_id = district_id_result[0]
# Get ID of building type, dwelling type, and tenure type
building_type_id = add_element_and_get_index(
row["Type of building"], building_type_list
)
dwelling_type_id = add_element_and_get_index(
row["Type of dwelling"], dwelling_type_list
)
tenure_type_id = add_element_and_get_index(
row["Tenure of dwelling"], tenure_type_list
)
construction_material_id = add_element_and_get_index(
row["Construction material"], construction_material_list
)
# Prepare and insert the data to the DwellingFloorspace table
floorspace = float(
str(row[constants.FLOORSPACE_PER_DWELLING_DWELLING_SIZES]).replace("-", "0")
)
# Insert the data to the DwellingFloorspace table
sql_statement = """
INSERT INTO DwellingFloorspace
(
district_id,
building_type_id,
dwelling_type_id,
tenure_type_id,
construction_material_id,
floorspace
)
VALUES
(
%d, %d, %d, %d, %d, %f
)
""" % (
district_id,
building_type_id,
dwelling_type_id,
tenure_type_id,
construction_material_id,
floorspace,
)
self.cursor.execute(sql_statement)
# Prepare and insert the data to the DwellingDistribution table
for dwelling_size_type_id in range(len(dwelling_size_type_list)):
number_dwelling = float(
str(row[constants.NUMBER_DWELLING_SIZES + dwelling_size_type_id]).replace(
"-", "0"
)
)
# Insert the data to the DwellingDistribution table
sql_statement = """
INSERT INTO DwellingDistribution
(
district_id,
building_type_id,
dwelling_type_id,
tenure_type_id,
construction_material_id,
dwelling_size_type_id,
number_dwelling
)
VALUES
(
%d, %d, %d, %d, %d, %d, %f
)
""" % (
district_id,
building_type_id,
dwelling_type_id,
tenure_type_id,
construction_material_id,
dwelling_size_type_id,
number_dwelling,
)
self.cursor.execute(sql_statement)
self.connection.commit()
logger.info("Number and sizes of dwellings added")
def import_exposure_data(
self,
population_distribution_filepath,
building_numbers_filepath,
dwelling_numbers_filepath,
household_data_filepath,
dwelling_sizes_filepath,
):
"""
Imports all exposure data from the CSV and Excel files provided by E-Stat, Japan.
......@@ -1313,6 +1489,7 @@ class JapanDatabase(SpatialiteDatabase):
List of numbers of dwellings by municipality (dwelling_numbers_filepath)
List of numbers of households and household members by municipality
(household_data_filepath)
List of dwelling sizes by municipality (dwelling_sizes_filepath)
Args:
population_distribution_filepath (str):
......@@ -1323,6 +1500,8 @@ class JapanDatabase(SpatialiteDatabase):
Filepath to the file of number of dwellings
household_data_filepath (str):
Filepath to the file of numbers of households and household members
dwelling_sizes_filepath (str):
Filepath to the file of dwelling sizes
"""
# Create lists to store building attribute classifications
......@@ -1340,6 +1519,17 @@ class JapanDatabase(SpatialiteDatabase):
"2_Non-wooden",
]
# Dwelling size type classifications
dwelling_size_type_list = [
"0_Total",
"1_29m2 and under",
"2_30m2 to 49m2",
"3_50m2 to 69m2",
"4_70m2 to 99m2",
"5_100m2 to 149m2",
"6_150m2 and over",
]
# Import population data into the database
self.import_population_distribution(population_distribution_filepath)
......@@ -1375,6 +1565,17 @@ class JapanDatabase(SpatialiteDatabase):
household_data_filepath, building_type_list, dwelling_type_list, tenure_type_list
)
# Import dwelling floorspace and number of dwellings for
# dwelling sizes types into the database
self.import_floorspace_and_dwelling_sizes(
dwelling_sizes_filepath,
building_type_list,
dwelling_type_list,
tenure_type_list,
construction_material_list,
dwelling_size_type_list,
)
# Add the building types to the database
for building_type_id, building_type in enumerate(building_type_list):
self.insert_building_type(building_type_id, building_type)
......@@ -1402,4 +1603,9 @@ class JapanDatabase(SpatialiteDatabase):
self.insert_tenure_type(tenure_type_id, tenure_type)
logger.info("Tenure types added")
# Add the types of dwelling sizes to the database
for dwelling_size_type_id, dwelling_size_type in enumerate(dwelling_size_type_list):
self.insert_dwelling_size_type(dwelling_size_type_id, dwelling_size_type)
logger.info("Dwelling-size types added")
self.connection.commit()
......@@ -48,6 +48,7 @@ def main():
"data/e039_3e.xlsx",
"data/e008_3e.xlsx",
"data/e011_2e.xlsx",
"data/e014e.xlsx",
)
# Leave the program
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment