hypercadaster-ES 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1551 @@
1
+ import sys
2
+ import zipfile
3
+ import geopandas as gpd
4
+ import os
5
+ import requests
6
+ import pandas as pd
7
+ import fiona
8
+ from hypercadaster_ES import utils
9
+ import polars as pl
10
+ from charset_normalizer import from_path
11
+ import time
12
+ import numpy as np
13
+ from tqdm import tqdm
14
+ from joblib import Parallel, delayed
15
+ from joblib.externals.loky import get_reusable_executor
16
+
17
+ def download_file(dir, url, file):
18
+ """Download a file from URL to directory if it doesn't exist."""
19
+ file_path = os.path.join(dir, file)
20
+ if not os.path.exists(file_path):
21
+ try:
22
+ response = requests.get(url, timeout=30)
23
+ if response.status_code == 200:
24
+ with open(file_path, 'wb') as archivo:
25
+ archivo.write(response.content)
26
+ else:
27
+ sys.stderr.write(f"Error downloading {file}: Status {response.status_code}\n")
28
+ except requests.exceptions.RequestException as e:
29
+ sys.stderr.write(f"Error downloading {file}: {e}\n")
30
+ except Exception as e:
31
+ sys.stderr.write(f"Unexpected error downloading {file}: {e}\n")
32
+
33
+
34
+ def download_postal_codes(postal_codes_dir, province_codes=None):
35
+ sys.stderr.write('\nDownloading postal codes from Spain\n')
36
+ if province_codes is None:
37
+ province_codes = ["{:02d}".format(i) for i in range(1, 53)]
38
+ fiona.drvsupport.supported_drivers['KML'] = 'rw'
39
+ for province_code in province_codes:
40
+ if not os.path.exists(f"{postal_codes_dir}/raw/k{province_code}.geojson"):
41
+ response = requests.get(f"https://www.codigospostales.com/kml/k{province_code}.kml")
42
+ if response.status_code == 200:
43
+ geojson_data = utils.kml_to_geojson(response.content)
44
+ with open(f"{postal_codes_dir}/raw/k{province_code}.geojson", 'w') as f:
45
+ f.write(geojson_data)
46
+ else:
47
+ sys.stderr.write(f"Error downloading postal code {province_code} file: Status {response.status_code}\n")
48
+
49
+ # Filter and concatenate downloaded geojson files
50
+ patterns = [f'k{pr}.geojson' for pr in province_codes]
51
+ raw_files = [filename for filename in os.listdir(f"{postal_codes_dir}/raw")
52
+ if any(filename.endswith(pattern) for pattern in patterns)]
53
+
54
+ if not raw_files:
55
+ sys.stderr.write("Error: No postal code files were successfully downloaded\n")
56
+ return
57
+
58
+ try:
59
+ geojson_filenames = []
60
+ for file in raw_files:
61
+ try:
62
+ gdf = gpd.read_file(f"{postal_codes_dir}/raw/{file}")
63
+ if not gdf.empty:
64
+ geojson_filenames.append(gdf)
65
+ except Exception as e:
66
+ sys.stderr.write(f"Error reading {file}: {e}\n")
67
+
68
+ if not geojson_filenames:
69
+ sys.stderr.write("Error: No valid postal code files found\n")
70
+ return
71
+
72
+ concatenated_gdf = gpd.GeoDataFrame(pd.concat(geojson_filenames, ignore_index=True),
73
+ crs=geojson_filenames[0].crs)
74
+ concatenated_gdf.geometry = concatenated_gdf.geometry.make_valid()
75
+ concatenated_gdf.to_file(f"{postal_codes_dir}/postal_codes.geojson", driver="GeoJSON")
76
+ except Exception as e:
77
+ sys.stderr.write(f"Error processing postal codes: {e}\n")
78
+
79
+
80
+ def download_census_tracts(census_tracts_dir, year):
81
+ sys.stderr.write(f"\nDownloading census tract geometries for year: {year}\n")
82
+ output_file = f"{census_tracts_dir}/validated_census_{year}.gpkg"
83
+
84
+ if not os.path.exists(output_file):
85
+ extracted_dir = f"España_Seccionado{year}_ETRS89H30"
86
+
87
+ if not os.path.exists(os.path.join(census_tracts_dir, extracted_dir)):
88
+ os.makedirs(f"{census_tracts_dir}/zip", exist_ok=True)
89
+ zip_file = f"{census_tracts_dir}/zip/census_{year}.zip"
90
+
91
+ response = requests.get(f"https://www.ine.es/prodyser/cartografia/seccionado_{year}.zip")
92
+ if response.status_code == 200:
93
+ with open(zip_file, 'wb') as archivo:
94
+ archivo.write(response.content)
95
+
96
+ try:
97
+ with zipfile.ZipFile(zip_file, "r") as zip_ref:
98
+ zip_ref.extractall(census_tracts_dir)
99
+ except zipfile.BadZipFile:
100
+ sys.stderr.write(f"Error: Downloaded file is not a valid zip file\n")
101
+ return
102
+ else:
103
+ sys.stderr.write(f"Error downloading census data: Status {response.status_code}\n")
104
+ return
105
+
106
+ # Find and read the shapefile
107
+ extracted_path = os.path.join(census_tracts_dir, extracted_dir)
108
+ if not os.path.exists(extracted_path):
109
+ sys.stderr.write(f"Error: Extracted directory {extracted_dir} not found\n")
110
+ return
111
+
112
+ shp_files = [f for f in os.listdir(extracted_path) if f.endswith(".shp")]
113
+ if not shp_files:
114
+ sys.stderr.write(f"Error: No shapefile found in {extracted_dir}\n")
115
+ return
116
+
117
+ shp_path = os.path.join(extracted_path, shp_files[0])
118
+
119
+ try:
120
+ shp = gpd.read_file(shp_path)
121
+ shp.geometry = shp.geometry.make_valid()
122
+ shp.to_file(output_file, driver="GPKG")
123
+ except Exception as e:
124
+ sys.stderr.write(f"Error processing census shapefile: {e}\n")
125
+ return
126
+
127
+
128
+ def cadaster_downloader(cadaster_dir, cadaster_codes=None):
129
+
130
+ inspire_dict = {
131
+ "parcels": "https://www.catastro.hacienda.gob.es/INSPIRE/CadastralParcels/ES.SDGC.CP.atom.xml",
132
+ "address": "https://www.catastro.hacienda.gob.es/INSPIRE/Addresses/ES.SDGC.AD.atom.xml",
133
+ "buildings": "https://www.catastro.hacienda.gob.es/INSPIRE/buildings/ES.SDGC.BU.atom.xml"
134
+ }
135
+
136
+ for k, v in inspire_dict.items():
137
+ sys.stderr.write(f"\nDownloading INSPIRE-harmonised cadaster data: {k}\n")
138
+ municipalities = utils.list_municipalities(
139
+ province_codes=list(set([code[:2] for code in cadaster_codes])),
140
+ inspire_url=v, echo=False)
141
+ if cadaster_codes is not None:
142
+ municipalities = [item for item in municipalities if item['name'].split("-")[0] in cadaster_codes]
143
+ nf = False
144
+ for municipality in municipalities:
145
+ if (not os.path.exists(f"{cadaster_dir}/{k}/zip/{municipality['url'].split('.')[-2]}.zip") and
146
+ municipality['url'].split('.')[-1] == 'zip'):
147
+ nf = True
148
+ sys.stderr.write("\r" + " " * 60)
149
+ sys.stderr.flush()
150
+ sys.stderr.write(f"\r\t{municipality['name']}")
151
+ sys.stderr.flush()
152
+ download(municipality['url'], f"{municipality['url'].split('.')[-2]}.zip",
153
+ f"{cadaster_dir}/{k}/zip/")
154
+ sys.stderr.write("\r" + " " * 60)
155
+ if nf:
156
+ utils.unzip_directory(f"{cadaster_dir}/{k}/zip/", f"{cadaster_dir}/{k}/unzip/")
157
+
158
+
159
+ def download_DEM_raster(raster_dir, bbox, year=2023):
160
+ sys.stderr.write(f"\nDownloading Digital Elevation Models for year: {year}\n")
161
+ os.makedirs(f"{raster_dir}/raw", exist_ok=True)
162
+ os.makedirs(f"{raster_dir}/uncompressed", exist_ok=True)
163
+ bbox = [int(i) for i in bbox]
164
+ nf = False
165
+ for latitude in range(bbox[1],bbox[3]+1):
166
+ for longitude in range(bbox[0],bbox[2]+1):
167
+ if not os.path.exists(f"{raster_dir}/raw/DEM_{latitude}_{longitude}_{year}.tar"):
168
+ nf = True
169
+ sys.stderr.write(f"\t--> Latitude {latitude}, longitude {longitude}\n")
170
+ download_file(dir = f"{raster_dir}/raw",
171
+ url = f"https://prism-dem-open.copernicus.eu/pd-desk-open-access/prismDownload/"
172
+ f"COP-DEM_GLO-30-DGED__{year}_1/"
173
+ f"Copernicus_DSM_10_N{latitude:02}_00_E{longitude:03}_00.tar",
174
+ file = f"DEM_{latitude}_{longitude}_{year}.tar")
175
+ if nf:
176
+ utils.untar_directory(tar_directory = f"{raster_dir}/raw/",
177
+ untar_directory = f"{raster_dir}/uncompressed/",
178
+ files_to_extract= "*/DEM/*.tif")
179
+ utils.concatenate_tiffs(input_dir=f"{raster_dir}/uncompressed/",
180
+ output_file=f"{raster_dir}/DEM.tif")
181
+
182
+
183
+ def download(url, name, save_path):
184
+ """Download a file with streaming for large files."""
185
+ try:
186
+ get_response = requests.get(url, stream=True, timeout=60)
187
+ if get_response.status_code == 200:
188
+ file_name = os.path.join(save_path, name)
189
+ os.makedirs(save_path, exist_ok=True)
190
+
191
+ with open(file_name, 'wb') as f:
192
+ for chunk in get_response.iter_content(chunk_size=1024):
193
+ if chunk:
194
+ f.write(chunk)
195
+ else:
196
+ sys.stderr.write(f"Error downloading {url}: Status {get_response.status_code}\n")
197
+ except requests.exceptions.RequestException as e:
198
+ sys.stderr.write(f"Error downloading {url}: {e}\n")
199
+ except Exception as e:
200
+ sys.stderr.write(f"Unexpected error downloading {url}: {e}\n")
201
+
202
+
203
+ def load_and_transform_barcelona_ground_premises(open_data_layers_dir):
204
+ ground_premises = pd.read_csv(
205
+ filepath_or_buffer=f"{open_data_layers_dir}/barcelona_ground_premises.csv",
206
+ encoding=from_path(f"{open_data_layers_dir}/barcelona_ground_premises.csv").best().encoding,
207
+ on_bad_lines='skip',
208
+ sep=",", low_memory=False)
209
+ ground_premises["Nom_Activitat"] = ground_premises["Nom_Activitat"].replace(
210
+ {
211
+ 'Activitats emmagatzematge': "Activitats d'emmagatzematge@ca\tActividades de almacenamiento@es\tStorage activities@en",
212
+ 'Ensenyament': "Ensenyament@ca\tEnseñanza@es\tEducation@en",
213
+ 'Serveis a les empreses i oficines': "Serveis a les empreses i oficines@ca\tServicios a empresas y oficinas@es\tBusiness and office services@en",
214
+ 'Arts gràfiques': "Arts gràfiques@ca\tArtes gráficas@es\tGraphic arts@en",
215
+ 'Activitats de la construcció': "Activitats de la construcció@ca\tActividades de construcción@es\tConstruction activities@en",
216
+ 'Reparacions (Electrodomèstics i automòbils)': "Reparacions (Electrodomèstics i automòbils)@ca\tReparaciones (Electrodomésticos y automóviles)@es\tRepairs (Appliances and automobiles)@en",
217
+ 'Sanitat i assistència': "Sanitat i assistència@ca\tSanidad y asistencia@es\tHealthcare and assistance@en",
218
+ 'Maquinària': "Maquinària@ca\tMaquinaria@es\tMachinery@en",
219
+ 'Associacions': "Associacions@ca\tAsociaciones@es\tAssociations@en",
220
+ 'Locals buits en venda i lloguer – reanalisi': "Locals buits en venda i lloguer – reanalisi@ca\tLocales vacíos en venta y alquiler – reanálisis@es\tEmpty premises for sale and rent – reanalysis@en",
221
+ 'Vehicles': "Vehicles@ca\tVehículos@es\tVehicles@en",
222
+ 'Vestir': "Vestir@ca\tVestimenta@es\tClothing@en",
223
+ 'Restaurants': "Restaurants@ca\tRestaurantes@es\tRestaurants@en",
224
+ 'Pàrquings i garatges': "Pàrquings i garatges@ca\tAparcamientos y garajes@es\tParking and garages@en",
225
+ 'Locutoris': "Locutoris@ca\tLocutorios@es\tCall centers@en",
226
+ 'Autoservei / Supermercat': "Autoservei / Supermercat@ca\tAutoservicio / Supermercado@es\tSelf-service / Supermarket@en",
227
+ 'Altres': "Altres@ca\tOtros@es\tOthers@en",
228
+ 'Activitats industrials': "Activitats industrials@ca\tActividades industriales@es\tIndustrial activities@en",
229
+ 'Locals buits en venda': "Locals buits en venda@ca\tLocales vacíos en venta@es\tEmpty premises for sale@en",
230
+ 'Bars / CIBERCAFÈ': "Bars / CIBERCAFÈ@ca\tBares / CIBERCAFÉ@es\tBars / CYBERCAFÉ@en",
231
+ 'Farmàcies PARAFARMÀCIA': "Farmàcies PARAFARMÀCIA@ca\tFarmacias PARAFARMACIA@es\tPharmacies and para-pharmacies@en",
232
+ 'Arranjaments': "Arranjaments@ca\tArreglos@es\tAlterations@en",
233
+ 'Equipaments culturals i recreatius': "Equipaments culturals i recreatius@ca\tEquipamientos culturales y recreativos@es\tCultural and recreational facilities@en",
234
+ "Centres d'estètica": "Centres d'estètica@ca\tCentros de estética@es\tAesthetic centers@en",
235
+ 'Serveis Socials': "Serveis Socials@ca\tServicios Sociales@es\tSocial services@en",
236
+ 'Fruites i verdures': "Fruites i verdures@ca\tFrutas y verduras@es\tFruits and vegetables@en",
237
+ 'Joieria, rellotgeria i bijuteria': "Joieria, rellotgeria i bijuteria@ca\tJoyería, relojería y bisutería@es\tJewelry, watches, and costume jewelry@en",
238
+ 'Perruqueries': "Perruqueries@ca\tPeluquerías@es\tHairdressing@en",
239
+ 'Drogueria i perfumeria': "Drogueria i perfumeria@ca\tDroguería y perfumería@es\tDrugstore and perfumery@en",
240
+ 'Material equipament llar': "Material equipament llar@ca\tMaterial de equipamiento del hogar@es\tHome equipment materials@en",
241
+ 'Basars': "Basars@ca\tBazares@es\tBazaars@en",
242
+ 'Pa, pastisseria i làctics': "Pa, pastisseria i làctics@ca\tPan, pastelería y lácteos@es\tBread, pastries, and dairy@en",
243
+ 'Activitats de transport': "Activitats de transport@ca\tActividades de transporte@es\tTransport activities@en",
244
+ 'Mobles i articles fusta i metall': "Mobles i articles fusta i metall@ca\tMuebles y artículos de madera y metal@es\tFurniture and wood/metal goods@en",
245
+ 'Serveis de telecomunicacions': "Serveis de telecomunicacions@ca\tServicios de telecomunicaciones@es\tTelecommunication services@en",
246
+ 'Plats preparats (no degustació)': "Plats preparats (no degustació)@ca\tPlatos preparados (sin degustación)@es\tPrepared dishes (no tasting)@en",
247
+ 'Bars especials amb actuació / Bars musicals / Discoteques /PUB': "Bars especials amb actuació / Bars musicals / Discoteques /PUB@ca\tBares especiales con actuación / Bares musicales / Discotecas / PUB@es\tSpecial bars with live performance / Music bars / Nightclubs / PUB@en",
248
+ 'Parament ferreteria': "Parament ferreteria@ca\tSuministros de ferretería@es\tHardware supplies@en",
249
+ 'Serveis de menjar take away MENJAR RÀPID': "Serveis de menjar take away MENJAR RÀPID@ca\tServicios de comida para llevar / Comida rápida@es\tTake-away / Fast food services@en",
250
+ 'Locals buits en lloguer': "Locals buits en lloguer@ca\tLocales vacíos en alquiler@es\tEmpty premises for rent@en",
251
+ 'Tintoreries': "Tintoreries@ca\tTintorerías@es\tDry cleaners@en",
252
+ "serveis d'allotjament": "serveis d'allotjament@ca\tservicios de alojamiento@es\tAccommodation services@en",
253
+ 'Altres equipaments esportius': "Altres equipaments esportius@ca\tOtros equipamientos deportivos@es\tOther sports facilities@en",
254
+ 'Carn i Porc': "Carn i Porc@ca\tCarne y cerdo@es\tMeat and pork@en",
255
+ 'Begudes': "Begudes@ca\tBebidas@es\tBeverages@en",
256
+ 'Herbolaris, dietètica i NUTRICIÓ': "Herbolaris, dietètica i NUTRICIÓ@ca\tHerbolarios, dietética y NUTRICIÓN@es\tHerbalists, dietetics, and NUTRITION@en",
257
+ 'Informàtica': "Informàtica@ca\tInformática@es\tComputing@en",
258
+ 'Aparells domèstics': "Aparells domèstics@ca\tAparatos domésticos@es\tHousehold appliances@en",
259
+ 'Veterinaris / Mascotes': "Veterinaris / Mascotes@ca\tVeterinarios / Mascotas@es\tVeterinarians / Pets@en",
260
+ 'Música': "Música@ca\tMúsica@es\tMusic@en",
261
+ 'Finances i assegurances': "Finances i assegurances@ca\tFinanzas y seguros@es\tFinance and insurance@en",
262
+ 'Activitats immobiliàries': "Activitats immobiliàries@ca\tActividades inmobiliarias@es\tReal estate activities@en",
263
+ 'Equipaments religiosos': "Equipaments religiosos@ca\tEquipamientos religiosos@es\tReligious facilities@en",
264
+ 'Joguines i esports': "Joguines i esports@ca\tJuguetes y deportes@es\tToys and sports@en",
265
+ 'Manteniment, neteja i similars': "Manteniment, neteja i similars@ca\tMantenimiento, limpieza y similares@es\tMaintenance, cleaning, and similar@en",
266
+ 'Administració': "Administració@ca\tAdministración@es\tAdministration@en",
267
+ 'Fotografia': "Fotografia@ca\tFotografía@es\tPhotography@en",
268
+ 'Gimnàs /fitnes': "Gimnàs /fitnes@ca\tGimnasio / fitness@es\tGym / Fitness@en",
269
+ 'Locals buits en venda i lloguer': "Locals buits en venda i lloguer@ca\tLocales vacíos en venta y alquiler@es\tEmpty premises for sale and rent@en",
270
+ 'Combustibles i carburants': "Combustibles i carburants@ca\tCombustibles y carburantes@es\tFuels and combustibles@en",
271
+ 'Fabricació tèxtil': "Fabricació tèxtil@ca\tFabricación textil@es\tTextile manufacturing@en",
272
+ 'Tabac i articles fumadors': "Tabac i articles fumadors@ca\tTabaco y artículos de fumadores@es\tTobacco and smoking articles@en",
273
+ 'Merceria': "Merceria@ca\tMercería@es\tHaberdashery@en",
274
+ 'Floristeries': "Floristeries@ca\tFloristerías@es\tFlorists@en",
275
+ 'Llibres, diaris i revistes': "Llibres, diaris i revistes@ca\tLibros, diarios y revistas@es\tBooks, newspapers, and magazines@en",
276
+ 'Òptiques': "Òptiques@ca\tÓpticas@es\tOptics@en",
277
+ 'Ous i aus': "Ous i aus@ca\tHuevos y aves@es\tEggs and poultry@en",
278
+ 'Agències de viatge': "Agències de viatge@ca\tAgencias de viaje@es\tTravel agencies@en",
279
+ 'Souvenirs': "Souvenirs@ca\tSouvenirs@es\tSouvenirs@en",
280
+ 'Calçat i pell': "Calçat i pell@ca\tCalzado y piel@es\tFootwear and leather@en",
281
+ 'Xocolateries / Geladeries / Degustació': "Xocolateries / Geladeries / Degustació@ca\tChocolaterías / Heladerías / Degustación@es\tChocolate shops / Ice cream parlors / Tasting@en",
282
+ 'Segells, monedes i antiguitats': "Segells, monedes i antiguitats@ca\tSellos, monedas y antigüedades@es\tStamps, coins, and antiques@en",
283
+ 'Peix i marisc': "Peix i marisc@ca\tPescado y marisco@es\tFish and seafood@en",
284
+ 'serveis de menjar i begudes': "serveis de menjar i begudes@ca\tservicios de comida y bebidas@es\tFood and beverage services@en",
285
+ 'Altres ( per exemple VENDING)': "Altres ( per exemple VENDING)@ca\tOtros (por ejemplo, VENDING)@es\tOthers (e.g., VENDING)@en",
286
+ 'altres': "altres@ca\totros@es\tothers@en",
287
+ 'Resta alimentació': "Resta alimentació@ca\tResto alimentación@es\tOther food products@en",
288
+ 'Souvenirs i basars': "Souvenirs i basars@ca\tSouvenirs y bazares@es\tSouvenirs and bazaars@en",
289
+ 'Grans magatzems i hipermercats': "Grans magatzems i hipermercats@ca\tGrandes almacenes e hipermercados@es\tDepartment stores and hypermarkets@en"
290
+ }
291
+ )
292
+ ground_premises = ground_premises.groupby("Referencia_Cadastral").agg(
293
+ cases=('Referencia_Cadastral', 'size'),
294
+ ground_premises_activities=('Nom_Activitat', lambda x: list(x)),
295
+ ground_premises_names=('Nom_Local', lambda x: list(x)),
296
+ ground_premises_last_revision=('Data_Revisio', 'max')
297
+ ).reset_index().rename({"Referencia_Cadastral": "building_reference",
298
+ "cases": "number_of_ground_premises",
299
+ "last_revision": "last_revision_ground_premises"}, axis=1)
300
+ ground_premises["building_reference"] = ground_premises["building_reference"].astype(str)
301
+
302
+ return ground_premises
303
+
304
+ # Estructura de los ficheros .CAT
305
+ # Transposicion literal de la especificacion (salvo error u omision):
306
+ # https://www.catastro.hacienda.gob.es/documentos/formatos_intercambio/catastro_fin_cat_2006.pdf
307
+ catstruct = {}
308
+ catstruct[1] = [
309
+ [3, 1, 'X', 'tipo_entidad_generadora',pl.Utf8],
310
+ [4, 9, 'N', 'codigo_entidad_generadora',pl.Utf8],
311
+ [13, 27, 'X', 'nombre_entidad_generadora',pl.Utf8],
312
+ [40, 8, 'N', 'fecha_generacion_fichero',pl.Utf8],
313
+ [48, 6, 'N', 'hora_generacion_fichero',pl.Utf8],
314
+ [54, 4, 'X', 'tipo_fichero',pl.Utf8],
315
+ [58, 39, 'X', 'descripcion_contenido_fichero',pl.Utf8],
316
+ [97, 21, 'X', 'nombre_fichero',pl.Utf8],
317
+ [118, 3, 'N', 'codigo_entidad_destinataria',pl.Utf8],
318
+ [121, 8, 'N', 'fecha_inicio_periodo',pl.Utf8],
319
+ [129, 8, 'N', 'fecha_finalizacion_periodo',pl.Utf8]
320
+ ]
321
+
322
+ # 11 - Registro de Finca
323
+ catstruct[11] = [
324
+ [24, 2, 'N', 'codigo_delegacion_meh',pl.Utf8],
325
+ [26, 3, 'N', 'codigo_municipio_dgc',pl.Utf8],
326
+ [31, 14, 'X', 'parcela_catastral',pl.Utf8],
327
+ [51, 2, 'N', 'codigo_provincia_ine',pl.Utf8],
328
+ [53, 25, 'X', 'nombre_provincia',pl.Utf8],
329
+ [78, 3, 'N', 'codigo_municipio_dgc_2',pl.Utf8],
330
+ [81, 3, 'N', 'codigo_municipio_ine',pl.Utf8],
331
+ [84, 40, 'X', 'nombre_municipio',pl.Utf8],
332
+ [124, 30, 'X', 'nombre_entidad_menor',pl.Utf8],
333
+ [154, 5, 'N', 'codigo_via_publica_dgc',pl.Utf8],
334
+ [159, 5, 'X', 'tipo_via',pl.Utf8],
335
+ [164, 25, 'X', 'nombre_via',pl.Utf8],
336
+ [189, 4, 'N', 'primer_numero_policia',pl.Utf8],
337
+ [193, 1, 'X', 'primera_letra',pl.Utf8],
338
+ [194, 4, 'N', 'segundo_numero_policia',pl.Utf8],
339
+ [198, 1, 'X', 'segunda_letra',pl.Utf8],
340
+ [199, 5, 'N', 'kilometro_por_cien',pl.Utf8],
341
+ [204, 4, 'X', 'bloque',pl.Utf8],
342
+ [216, 25, 'X', 'direccion_no_estructurada',pl.Utf8],
343
+ [241, 5, 'N', 'codigo_postal',pl.Utf8],
344
+ [246, 2, 'X', 'distrito_municipal',pl.Utf8],
345
+ [248, 3, 'N', 'codigo_municipio_origen_caso_agregacion_dgc',pl.Utf8],
346
+ [251, 2, 'N', 'codigo_zona_concentracion',pl.Utf8],
347
+ [253, 3, 'N', 'codigo_poligono',pl.Utf8],
348
+ [256, 5, 'N', 'codigo_parcela',pl.Utf8],
349
+ [261, 5, 'X', 'codigo_paraje_dgc',pl.Utf8],
350
+ [266, 30, 'X', 'nombre_paraje',pl.Utf8],
351
+ [296, 10, 'N', 'superficie_finca_o_parcela_catastral_m2',pl.Float32],
352
+ [306, 7, 'N', 'superficie_construida_total',pl.Float32],
353
+ [313, 7, 'N', 'superficie_construida_sobre_rasante',pl.Float32],
354
+ [320, 7, 'N', 'superficie_construida_bajo_rasante',pl.Float32],
355
+ [327, 7, 'N', 'superficie_cubierta',pl.Float32],
356
+ [334, 9, 'N', 'coordenada_x_por_cien',pl.Float32],
357
+ [343, 10, 'N', 'coordenada_y_por_cien',pl.Float32],
358
+ [582, 20, 'X', 'referencia_catastral_bice',pl.Utf8],
359
+ [602, 65, 'X', 'denominacion_bice',pl.Utf8],
360
+ [667, 10, 'X', 'codigo_epsg',pl.Utf8]
361
+ ]
362
+
363
+ # 13 - Registro de Unidad Constructiva
364
+ catstruct[13] = [
365
+ [24, 2, 'N', 'codigo_delegacion_meh',pl.Utf8],
366
+ [26, 3, 'N', 'codigo_municipio_dgc',pl.Utf8],
367
+ [29, 2, 'X', 'clase_unidad_constructiva',pl.Utf8],
368
+ [31, 14, 'X', 'parcela_catastral',pl.Utf8],
369
+ [45, 4, 'X', 'codigo_unidad_constructiva',pl.Utf8],
370
+ [51, 2, 'N', 'codigo_provincia_ine',pl.Utf8],
371
+ [53, 25, 'X', 'nombre_provincia',pl.Utf8],
372
+ [78, 3, 'N', 'codigo_municipio_dgc_2',pl.Utf8],
373
+ [81, 3, 'N', 'codigo_municipio_ine',pl.Utf8],
374
+ [84, 40, 'X', 'nombre_municipio',pl.Utf8],
375
+ [124, 30, 'X', 'nombre_entidad_menor',pl.Utf8],
376
+ [154, 5, 'N', 'codigo_via_publica_dgc',pl.Utf8],
377
+ [159, 5, 'X', 'tipo_via',pl.Utf8],
378
+ [164, 25, 'X', 'nombre_via',pl.Utf8],
379
+ [189, 4, 'N', 'primer_numero_policia',pl.Utf8],
380
+ [193, 1, 'X', 'primera_letra',pl.Utf8],
381
+ [194, 4, 'N', 'segundo_numero_policia',pl.Utf8],
382
+ [198, 1, 'X', 'segunda_letra',pl.Utf8],
383
+ [199, 5, 'N', 'kilometro_por_cien',pl.Utf8],
384
+ [216, 25, 'X', 'direccion_no_estructurada',pl.Utf8],
385
+ [296, 4, 'N', 'año_construccion',pl.Int16],
386
+ [300, 1, 'X', 'exactitud_año_construccion',pl.Utf8],
387
+ [301, 7, 'N', 'superficie_suelo_ocupado',pl.Float32],
388
+ [308, 5, 'N', 'longitud_fachada_cm',pl.Float32],
389
+ [410, 4, 'X', 'codigo_unidad_constructiva_matriz',pl.Utf8]
390
+ ]
391
+
392
+ # 14 - Registro de Construccion
393
+ catstruct[14] = [
394
+ [24, 2, 'N', 'delegation_meh_code', pl.Utf8],
395
+ [26, 3, 'N', 'municipality_cadaster_code', pl.Utf8],
396
+ [29, 2, 'X', 'real_estate_type', pl.Utf8],
397
+ [31, 14, 'X', 'building_reference', pl.Utf8],
398
+ [45, 4, 'N', 'element_reference',pl.Utf8],
399
+ [51, 4, 'X', 'space1_reference',pl.Utf8],
400
+ [59, 4, 'X', 'building_space_block_name',pl.Utf8],
401
+ [63, 2, 'X', 'building_space_stair_name',pl.Utf8],
402
+ [65, 3, 'X', 'building_space_floor_name',pl.Utf8],
403
+ [68, 3, 'X', 'building_space_door_name',pl.Utf8],
404
+ [71, 3, 'X', 'building_space_detailed_use_type', pl.Utf8],
405
+ [74, 1, 'X', 'retrofitted', pl.Utf8],
406
+ [75, 4, 'N', 'building_space_retroffiting_year', pl.Int16],
407
+ [79, 4, 'N', 'building_space_effective_year', pl.Int16],
408
+ [83, 1, 'X', 'local_interior_indicator', pl.Utf8],
409
+ [84, 7, 'N', 'building_space_area_without_communal', pl.Float32],
410
+ [91, 7, 'N', 'building_space_area_balconies_terraces', pl.Float32],
411
+ [98, 7, 'N', 'building_space_area_imputable_to_other_floors', pl.Float32],
412
+ [105, 5, 'X', 'building_space_typology', pl.Utf8],
413
+ [112, 3, 'X', 'distribution_method_for_communal_areas', pl.Utf8]
414
+ ]
415
+
416
+ building_space_detailed_use_types = {
417
+ "A": "Storage",
418
+ "AAL": "Warehouse",
419
+ "AAP": "Parking",
420
+ "AES": "Station",
421
+ "AAV": "Parking in a household",
422
+ "BCR": "Irrigation hut",
423
+ "BCT": "Transformer hut",
424
+ "BIG": "Livestock facilities",
425
+ "C": "Commerce",
426
+ "CAT": "Automobile commerce",
427
+ "CBZ": "Bazaar commerce",
428
+ "CCE": "Retail commerce",
429
+ "CCL": "Shoe commerce",
430
+ "CCR": "Butcher commerce",
431
+ "CDM": "Personal/Home commerce",
432
+ "CDR": "Drugstore commerce",
433
+ "CFN": "Financial commerce",
434
+ "CFR": "Pharmacy commerce",
435
+ "CFT": "Plumbing commerce",
436
+ "CGL": "Galleries commerce",
437
+ "CIM": "Printing commerce",
438
+ "CJY": "Jewelry commerce",
439
+ "CLB": "Bookstore commerce",
440
+ "CMB": "Furniture commerce",
441
+ "CPA": "Wholesale commerce",
442
+ "CPR": "Perfumery commerce",
443
+ "CRL": "Watchmaking commerce",
444
+ "CSP": "Supermarket commerce",
445
+ "CTJ": "Fabric commerce",
446
+ "E": "Education",
447
+ "EBL": "Education (Library)",
448
+ "EBS": "Basic education",
449
+ "ECL": "Cultural house education",
450
+ "EIN": "Institute education",
451
+ "EMS": "Museum education",
452
+ "EPR": "Professional education",
453
+ "EUN": "University education",
454
+ "IIM": "Chemical industry",
455
+ "IMD": "Wood industry",
456
+ "G": "Hotel",
457
+ "GC1": "Hotel Cafe 1 Star",
458
+ "GC2": "Hotel Cafe 2 Stars",
459
+ "GC3": "Hotel Cafe 3 Stars",
460
+ "GC4": "Hotel Cafe 4 Stars",
461
+ "GC5": "Hotel Cafe 5 Stars",
462
+ "GH1": "Hotel 1 Star",
463
+ "GH2": "Hotel 2 Stars",
464
+ "GH3": "Hotel 3 Stars",
465
+ "GH4": "Hotel 4 Stars",
466
+ "GH5": "Hotel 5 Stars",
467
+ "GPL": "Luxury apartments",
468
+ "GP1": "Luxury apartments 1 Star",
469
+ "GP2": "Luxury apartments 2 Stars",
470
+ "GP3": "Luxury apartments 3 Stars",
471
+ "GR1": "Restaurant 1 Star",
472
+ "GR2": "Restaurant 2 Stars",
473
+ "GR3": "Restaurant 3 Stars",
474
+ "GR4": "Restaurant 4 Stars",
475
+ "GR5": "Restaurant 5 Stars",
476
+ "GS1": "Hostel Standard 1",
477
+ "GS2": "Hostel Standard 2",
478
+ "GS3": "Hostel Standard 3",
479
+ "GTL": "Luxury guesthouse",
480
+ "GT1": "Luxury guesthouse 1 Star",
481
+ "GT2": "Luxury guesthouse 2 Stars",
482
+ "GT3": "Luxury guesthouse 3 Stars",
483
+ "I": "Industry",
484
+ "IAG": "Agricultural industry",
485
+ "IAL": "Food industry",
486
+ "IAR": "Farming industry",
487
+ "IBB": "Beverage industry",
488
+ "IBR": "Clay industry",
489
+ "ICN": "Construction industry",
490
+ "ICT": "Quarry/Mining industry",
491
+ "IEL": "Electric industry",
492
+ "O99": "Other office activities",
493
+ "P": "Public",
494
+ "IMN": "Manufacturing industry",
495
+ "IMT": "Metal industry",
496
+ "IMU": "Machinery industry",
497
+ "IPL": "Plastics industry",
498
+ "IPP": "Paper industry",
499
+ "IPS": "Fishing industry",
500
+ "IPT": "Petroleum industry",
501
+ "ITB": "Tobacco industry",
502
+ "ITX": "Textile industry",
503
+ "IVD": "Glass industry",
504
+ "JAM": "Oil mills",
505
+ "JAS": "Sawmills",
506
+ "JBD": "Wineries",
507
+ "JCH": "Mushroom farms",
508
+ "JGR": "Farms",
509
+ "JIN": "Greenhouses",
510
+ "K": "Sports",
511
+ "KDP": "Sports facilities",
512
+ "KES": "Stadium",
513
+ "KPL": "Sports complex",
514
+ "KPS": "Swimming pool",
515
+ "M": "Undeveloped land",
516
+ "O": "Office",
517
+ "O02": "Superior office",
518
+ "O03": "Medium office",
519
+ "O06": "Medical/Law office",
520
+ "O07": "Nursing office",
521
+ "O11": "Teacher's office",
522
+ "O13": "University professor office",
523
+ "O15": "Writer's office",
524
+ "O16": "Plastic arts office",
525
+ "O17": "Musician's office",
526
+ "O43": "Salesperson office",
527
+ "O44": "Agent office",
528
+ "O75": "Weaver's office",
529
+ "O79": "Tailor's office",
530
+ "O81": "Carpenter's office",
531
+ "O88": "Jeweler's office",
532
+ "YSC": "Other rescue facilities",
533
+ "YSL": "Silos, solid storage",
534
+ "YSN": "Other sanatorium",
535
+ "YSO": "Other provincial union",
536
+ "PAA": "Public town hall (<20,000)",
537
+ "PAD": "Public courthouse",
538
+ "PAE": "Public town hall (>20,000)",
539
+ "PCB": "Public government hall",
540
+ "PDL": "Public delegation",
541
+ "PGB": "Government building",
542
+ "PJA": "Regional court",
543
+ "PJO": "Provincial court",
544
+ "R": "Religious",
545
+ "RBS": "Religious basilica",
546
+ "RCP": "Religious chapel",
547
+ "RCT": "Religious cathedral",
548
+ "RER": "Religious hermitage",
549
+ "RPR": "Religious parish",
550
+ "RSN": "Religious sanctuary",
551
+ "T": "Entertainment",
552
+ "TAD": "Auditorium",
553
+ "TCM": "Cinema",
554
+ "TCN": "Cinema (undecorated)",
555
+ "TSL": "Entertainment hall",
556
+ "TTT": "Theater",
557
+ "V": "Housing",
558
+ "Y": "Other uses",
559
+ "YAM": "Other outpatient clinic",
560
+ "YCA": "Casino (<20,000)",
561
+ "YCB": "Club",
562
+ "YCE": "Casino (>20,000)",
563
+ "YCL": "Clinic",
564
+ "YDG": "Gas storage",
565
+ "YDL": "Liquid storage tanks",
566
+ "YDS": "Other dispensary",
567
+ "YGR": "Daycare",
568
+ "YHG": "Hygiene facilities",
569
+ "YHS": "Hospital",
570
+ "YJD": "Private garden (100%)",
571
+ "YPO": "Porch (100%)",
572
+ "YRS": "Residence",
573
+ "YSA": "Local union",
574
+ "YSP": "Colonnade (50%)",
575
+ "YOU": "Urbanization works",
576
+ "YTD": "Open terrace (100%)",
577
+ "YTZ": "Covered terrace (100%)",
578
+ "Z": "Other uses",
579
+ "ZAM": "Outpatient clinic",
580
+ "ZBE": "Ponds, tanks",
581
+ "ZCA": "Casino (<20,000)",
582
+ "ZCB": "Club",
583
+ "ZCE": "Casino (>20,000)",
584
+ "ZCL": "Clinic",
585
+ "ZCT": "Quarries",
586
+ "ZDE": "Water treatment plants",
587
+ "ZDG": "Gas storage",
588
+ "ZDL": "Liquid storage tanks",
589
+ "ZDS": "Other dispensary",
590
+ "ZGR": "Daycare",
591
+ "ZGV": "Gravel pits",
592
+ "ZHG": "Hygiene facilities",
593
+ "ZHS": "Hospital",
594
+ "ZMA": "Open-pit mines",
595
+ "ZME": "Docks and piers",
596
+ "ZPC": "Fish farms",
597
+ "ZRS": "Residence",
598
+ "ZSA": "Local union",
599
+ "ZSC": "Other rescue facilities",
600
+ "ZSL": "Silos, solid storage",
601
+ "ZSN": "Other sanatorium",
602
+ "ZSO": "Other provincial union",
603
+ "ZVR": "Landfill"
604
+ }
605
+
606
+ building_space_typologies = { #https://www.boe.es/buscar/act.php?id=BOE-A-1993-19265
607
+ "PDEP": {
608
+ "Use": "Unknown/Undefined",
609
+ "UseLevel": 1,
610
+ "UseClass": "Undefined Space",
611
+ "UseClassModality": "No Classification",
612
+ "ConstructionValue": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
613
+ },
614
+ "0000": {
615
+ "Use": "Unknown/Undefined",
616
+ "UseLevel": 1,
617
+ "UseClass": "Undefined Space",
618
+ "UseClassModality": "No Classification",
619
+ "ConstructionValue": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
620
+ },
621
+ "0111": {
622
+ "Use": "Residential",
623
+ "UseLevel": 1,
624
+ "UseClass": "Collective Urban Housing",
625
+ "UseClassModality": "Open Building",
626
+ "ConstructionValue": [1.65, 1.40, 1.20, 1.05, 0.95, 0.85, 0.75, 0.65, 0.55]
627
+ },
628
+ "0112": {
629
+ "Use": "Residential",
630
+ "UseLevel": 1,
631
+ "UseClass": "Collective Urban Housing",
632
+ "UseClassModality": "Closed Block",
633
+ "ConstructionValue": [1.60, 1.35, 1.15, 1.00, 0.90, 0.80, 0.70, 0.60, 0.50]
634
+ },
635
+ "0113": {
636
+ "Use": "Residential",
637
+ "UseLevel": 1,
638
+ "UseClass": "Collective Urban Housing",
639
+ "UseClassModality": "Garages, Storage Rooms, and Premises in Structure",
640
+ "ConstructionValue": [0.80, 0.70, 0.62, 0.53, 0.46, 0.40, 0.30, 0.26, 0.20]
641
+ },
642
+ "0121": {
643
+ "Use": "Residential",
644
+ "UseLevel": 1,
645
+ "UseClass": "Single-Family Urban Housing",
646
+ "UseClassModality": "Isolated or Semi-Detached Building",
647
+ "ConstructionValue": [2.15, 1.80, 1.45, 1.25, 1.10, 1.00, 0.90, 0.80, 0.70]
648
+ },
649
+ "0122": {
650
+ "Use": "Residential",
651
+ "UseLevel": 1,
652
+ "UseClass": "Single-Family Urban Housing",
653
+ "UseClassModality": "Row or Closed Block",
654
+ "ConstructionValue": [2.00, 1.65, 1.35, 1.15, 1.05, 0.95, 0.85, 0.75, 0.65]
655
+ },
656
+ "0123": {
657
+ "Use": "Residential",
658
+ "UseLevel": 1,
659
+ "UseClass": "Single-Family Urban Housing",
660
+ "UseClassModality": "Garages and Porches on Ground Floor",
661
+ "ConstructionValue": [0.90, 0.85, 0.75, 0.65, 0.60, 0.55, 0.45, 0.40, 0.35]
662
+ },
663
+ "0131": {
664
+ "Use": "Residential",
665
+ "UseLevel": 1,
666
+ "UseClass": "Rural Building",
667
+ "UseClassModality": "Exclusive Housing Use",
668
+ "ConstructionValue": [1.35, 1.20, 1.05, 0.90, 0.80, 0.70, 0.60, 0.50, 0.40]
669
+ },
670
+ "0132": {
671
+ "Use": "Residential",
672
+ "UseLevel": 1,
673
+ "UseClass": "Rural Building",
674
+ "UseClassModality": "Annexes",
675
+ "ConstructionValue": [0.70, 0.60, 0.50, 0.45, 0.40, 0.35, 0.30, 0.25, 0.20]
676
+ },
677
+ "0211": {
678
+ "Use": "Industrial",
679
+ "UseLevel": 3,
680
+ "UseClass": "Manufacturing and Storage Sheds",
681
+ "UseClassModality": "Single-Story Manufacturing",
682
+ "ConstructionValue": [1.05, 0.90, 0.75, 0.60, 0.50, 0.45, 0.40, 0.37, 0.35]
683
+ },
684
+ "0212": {
685
+ "Use": "Industrial",
686
+ "UseLevel": 3,
687
+ "UseClass": "Manufacturing and Storage Sheds",
688
+ "UseClassModality": "Multi-Story Manufacturing",
689
+ "ConstructionValue": [1.15, 1.00, 0.85, 0.70, 0.60, 0.55, 0.52, 0.50, 0.40]
690
+ },
691
+ "0213": {
692
+ "Use": "Industrial",
693
+ "UseLevel": 2,
694
+ "UseClass": "Manufacturing and Storage Sheds",
695
+ "UseClassModality": "Storage",
696
+ "ConstructionValue": [0.85, 0.70, 0.60, 0.50, 0.45, 0.35, 0.30, 0.25, 0.20]
697
+ },
698
+ "0221": {
699
+ "Use": "Industrial",
700
+ "UseLevel": 2,
701
+ "UseClass": "Garages and Parking Lots",
702
+ "UseClassModality": "Garages",
703
+ "ConstructionValue": [1.15, 1.00, 0.85, 0.70, 0.60, 0.50, 0.40, 0.30, 0.20]
704
+ },
705
+ "0222": {
706
+ "Use": "Industrial",
707
+ "UseLevel": 2,
708
+ "UseClass": "Garages and Parking Lots",
709
+ "UseClassModality": "Parking Lots",
710
+ "ConstructionValue": [0.60, 0.50, 0.45, 0.40, 0.35, 0.30, 0.20, 0.10, 0.05]
711
+ },
712
+ "0231": {
713
+ "Use": "Industrial",
714
+ "UseLevel": 2,
715
+ "UseClass": "Transport Services",
716
+ "UseClassModality": "Service Stations",
717
+ "ConstructionValue": [1.80, 1.60, 1.40, 1.25, 1.20, 1.10, 1.00, 0.90, 0.80]
718
+ },
719
+ "0232": {
720
+ "Use": "Industrial",
721
+ "UseLevel": 2,
722
+ "UseClass": "Transport Services",
723
+ "UseClassModality": "Stations",
724
+ "ConstructionValue": [2.55, 2.25, 2.00, 1.80, 1.60, 1.40, 1.25, 1.10, 1.00]
725
+ },
726
+ "0311": {
727
+ "Use": "Offices",
728
+ "UseLevel": 1,
729
+ "UseClass": "Exclusive Building",
730
+ "UseClassModality": "Multiple Offices",
731
+ "ConstructionValue": [2.35, 2.00, 1.70, 1.50, 1.30, 1.15, 1.00, 0.90, 0.80]
732
+ },
733
+ "0312": {
734
+ "Use": "Offices",
735
+ "UseLevel": 1,
736
+ "UseClass": "Exclusive Building",
737
+ "UseClassModality": "Single Offices",
738
+ "ConstructionValue": [2.55, 2.20, 1.85, 1.60, 1.40, 1.25, 1.10, 1.00, 0.90]
739
+ },
740
+ "0321": {
741
+ "Use": "Offices",
742
+ "UseLevel": 1,
743
+ "UseClass": "Mixed Building",
744
+ "UseClassModality": "Attached to Housing",
745
+ "ConstructionValue": [2.05, 1.80, 1.50, 1.30, 1.10, 1.00, 0.90, 0.80, 0.70]
746
+ },
747
+ "0322": {
748
+ "Use": "Offices",
749
+ "UseLevel": 1,
750
+ "UseClass": "Mixed Building",
751
+ "UseClassModality": "Attached to Industry",
752
+ "ConstructionValue": [1.40, 1.25, 1.10, 1.00, 0.85, 0.65, 0.55, 0.45, 0.35]
753
+ },
754
+ "0331": {
755
+ "Use": "Offices",
756
+ "UseLevel": 1,
757
+ "UseClass": "Banking and Insurance",
758
+ "UseClassModality": "In Exclusive Building",
759
+ "ConstructionValue": [2.95, 2.65, 2.35, 2.10, 1.90, 1.70, 1.50, 1.35, 1.20]
760
+ },
761
+ "0332": {
762
+ "Use": "Offices",
763
+ "UseLevel": 1,
764
+ "UseClass": "Banking and Insurance",
765
+ "UseClassModality": "In Mixed Building",
766
+ "ConstructionValue": [2.65, 2.35, 2.10, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05]
767
+ },
768
+ "0411": {
769
+ "Use": "Commercial",
770
+ "UseLevel": 2,
771
+ "UseClass": "Commerce in Mixed Building",
772
+ "UseClassModality": "Shops and Workshops",
773
+ "ConstructionValue": [1.95, 1.60, 1.35, 1.20, 1.05, 0.95, 0.85, 0.75, 0.65]
774
+ },
775
+ "0412": {
776
+ "Use": "Commercial",
777
+ "UseLevel": 2,
778
+ "UseClass": "Commerce in Mixed Building",
779
+ "UseClassModality": "Commercial Galleries",
780
+ "ConstructionValue": [1.85, 1.65, 1.45, 1.30, 1.15, 1.00, 0.90, 0.80, 0.70]
781
+ },
782
+ "0421": {
783
+ "Use": "Commercial",
784
+ "UseLevel": 2,
785
+ "UseClass": "Commerce in Exclusive Building",
786
+ "UseClassModality": "Single Floor",
787
+ "ConstructionValue": [2.50, 2.15, 1.85, 1.60, 1.40, 1.25, 1.10, 1.00, 0.85]
788
+ },
789
+ "0422": {
790
+ "Use": "Commercial",
791
+ "UseLevel": 2,
792
+ "UseClass": "Commerce in Exclusive Building",
793
+ "UseClassModality": "Multiple Floors",
794
+ "ConstructionValue": [2.75, 2.35, 2.00, 1.75, 1.50, 1.35, 1.20, 1.05, 0.90]
795
+ },
796
+ "0431": {
797
+ "Use": "Commercial",
798
+ "UseLevel": 2,
799
+ "UseClass": "Markets and Supermarkets",
800
+ "UseClassModality": "Markets",
801
+ "ConstructionValue": [2.00, 1.80, 1.60, 1.45, 1.30, 1.15, 1.00, 0.90, 0.80]
802
+ },
803
+ "0432": {
804
+ "Use": "Commercial",
805
+ "UseLevel": 2,
806
+ "UseClass": "Markets and Supermarkets",
807
+ "UseClassModality": "Hypermarkets and Supermarkets",
808
+ "ConstructionValue": [1.80, 1.60, 1.45, 1.30, 1.15, 1.00, 0.90, 0.80, 0.70]
809
+ },
810
+ "0511": {
811
+ "Use": "Sports",
812
+ "UseLevel": 2,
813
+ "UseClass": "Covered",
814
+ "UseClassModality": "Various Sports",
815
+ "ConstructionValue": [2.10, 1.90, 1.70, 1.50, 1.30, 1.10, 0.90, 0.70, 0.50]
816
+ },
817
+ "0512": {
818
+ "Use": "Sports",
819
+ "UseLevel": 2,
820
+ "UseClass": "Covered",
821
+ "UseClassModality": "Pools",
822
+ "ConstructionValue": [2.30, 2.05, 1.85, 1.65, 1.45, 1.30, 1.15, 1.00, 0.90]
823
+ },
824
+ "0521": {
825
+ "Use": "Sports",
826
+ "UseLevel": 2,
827
+ "UseClass": "Uncovered",
828
+ "UseClassModality": "Various Sports",
829
+ "ConstructionValue": [0.70, 0.55, 0.50, 0.45, 0.35, 0.25, 0.20, 0.10, 0.05]
830
+ },
831
+ "0522": {
832
+ "Use": "Sports",
833
+ "UseLevel": 2,
834
+ "UseClass": "Uncovered",
835
+ "UseClassModality": "Pools",
836
+ "ConstructionValue": [0.90, 0.80, 0.70, 0.60, 0.50, 0.40, 0.35, 0.30, 0.25]
837
+ },
838
+ "0531": {
839
+ "Use": "Sports",
840
+ "UseLevel": 2,
841
+ "UseClass": "Auxiliaries",
842
+ "UseClassModality": "Locker Rooms, Water Treatment, Heating, etc.",
843
+ "ConstructionValue": [1.50, 1.35, 1.20, 1.05, 0.90, 0.80, 0.70, 0.60, 0.50]
844
+ },
845
+ "0541": {
846
+ "Use": "Sports",
847
+ "UseLevel": 3,
848
+ "UseClass": "Sports Shows",
849
+ "UseClassModality": "Stadiums, Bullrings",
850
+ "ConstructionValue": [2.40, 2.15, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05, 0.95]
851
+ },
852
+ "0542": {
853
+ "Use": "Sports",
854
+ "UseLevel": 3,
855
+ "UseClass": "Sports Shows",
856
+ "UseClassModality": "Racecourses, Dog Tracks, Velodromes, etc.",
857
+ "ConstructionValue": [2.20, 1.95, 1.75, 1.55, 1.40, 1.25, 1.10, 1.00, 0.90]
858
+ },
859
+ "0611": {
860
+ "Use": "Shows",
861
+ "UseLevel": 3,
862
+ "UseClass": "Various",
863
+ "UseClassModality": "Covered",
864
+ "ConstructionValue": [1.90, 1.70, 1.50, 1.35, 1.20, 1.05, 0.95, 0.85, 0.75]
865
+ },
866
+ "0612": {
867
+ "Use": "Shows",
868
+ "UseLevel": 3,
869
+ "UseClass": "Various",
870
+ "UseClassModality": "Uncovered",
871
+ "ConstructionValue": [0.80, 0.70, 0.60, 0.55, 0.50, 0.45, 0.40, 0.35, 0.30]
872
+ },
873
+ "0621": {
874
+ "Use": "Shows",
875
+ "UseLevel": 3,
876
+ "UseClass": "Musical Bars, Party Halls, and Discotheques",
877
+ "UseClassModality": "In Exclusive Building",
878
+ "ConstructionValue": [2.65, 2.35, 2.10, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05]
879
+ },
880
+ "0622": {
881
+ "Use": "Shows",
882
+ "UseLevel": 3,
883
+ "UseClass": "Musical Bars, Party Halls, and Discotheques",
884
+ "UseClassModality": "Attached to Other Uses",
885
+ "ConstructionValue": [2.20, 1.95, 1.75, 1.55, 1.40, 1.25, 1.10, 1.00, 0.90]
886
+ },
887
+ "0631": {
888
+ "Use": "Shows",
889
+ "UseLevel": 3,
890
+ "UseClass": "Cinemas and Theaters",
891
+ "UseClassModality": "Cinemas",
892
+ "ConstructionValue": [2.55, 2.30, 2.05, 1.80, 1.60, 1.45, 1.30, 1.15, 1.00]
893
+ },
894
+ "0632": {
895
+ "Use": "Shows",
896
+ "UseLevel": 3,
897
+ "UseClass": "Cinemas and Theaters",
898
+ "UseClassModality": "Theaters",
899
+ "ConstructionValue": [2.70, 2.40, 2.15, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05]
900
+ },
901
+ "0711": {
902
+ "Use": "Leisure and Hospitality",
903
+ "UseLevel": 2,
904
+ "UseClass": "With Residence",
905
+ "UseClassModality": "Hotels, Hostels, Motels",
906
+ "ConstructionValue": [2.65, 2.35, 2.10, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05]
907
+ },
908
+ "0712": {
909
+ "Use": "Leisure and Hospitality",
910
+ "UseLevel": 2,
911
+ "UseClass": "With Residence",
912
+ "UseClassModality": "Aparthotels, Bungalows",
913
+ "ConstructionValue": [2.85, 2.55, 2.30, 2.05, 1.85, 1.65, 1.45, 1.30, 1.15]
914
+ },
915
+ "0721": {
916
+ "Use": "Leisure and Hospitality",
917
+ "UseLevel": 2,
918
+ "UseClass": "Without Residence",
919
+ "UseClassModality": "Restaurants",
920
+ "ConstructionValue": [2.60, 2.35, 2.00, 1.75, 1.50, 1.35, 1.20, 1.05, 0.95]
921
+ },
922
+ "0722": {
923
+ "Use": "Leisure and Hospitality",
924
+ "UseLevel": 2,
925
+ "UseClass": "Without Residence",
926
+ "UseClassModality": "Bars and Cafeterias",
927
+ "ConstructionValue": [2.35, 2.00, 1.70, 1.50, 1.30, 1.15, 1.00, 0.90, 0.80]
928
+ },
929
+ "0731": {
930
+ "Use": "Leisure and Hospitality",
931
+ "UseLevel": 2,
932
+ "UseClass": "Exhibitions and Meetings",
933
+ "UseClassModality": "Casinos and Social Clubs",
934
+ "ConstructionValue": [2.60, 2.35, 2.10, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05]
935
+ },
936
+ "0732": {
937
+ "Use": "Leisure and Hospitality",
938
+ "UseLevel": 2,
939
+ "UseClass": "Exhibitions and Meetings",
940
+ "UseClassModality": "Exhibitions and Congresses",
941
+ "ConstructionValue": [2.50, 2.25, 2.00, 1.80, 1.60, 1.45, 1.25, 1.10, 1.00]
942
+ },
943
+ "0811": {
944
+ "Use": "Health and Welfare",
945
+ "UseLevel": 2,
946
+ "UseClass": "Healthcare with Beds",
947
+ "UseClassModality": "Sanatoriums and Clinics",
948
+ "ConstructionValue": [3.15, 2.80, 2.50, 2.25, 2.00, 1.80, 1.60, 1.45, 1.30]
949
+ },
950
+ "0812": {
951
+ "Use": "Health and Welfare",
952
+ "UseLevel": 2,
953
+ "UseClass": "Healthcare with Beds",
954
+ "UseClassModality": "Hospitals",
955
+ "ConstructionValue": [3.05, 2.70, 2.40, 2.15, 1.90, 1.70, 1.50, 1.35, 1.20]
956
+ },
957
+ "0821": {
958
+ "Use": "Health and Welfare",
959
+ "UseLevel": 2,
960
+ "UseClass": "Various Healthcare",
961
+ "UseClassModality": "Ambulatory Care and Clinics",
962
+ "ConstructionValue": [2.40, 2.15, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05, 0.95]
963
+ },
964
+ "0822": {
965
+ "Use": "Health and Welfare",
966
+ "UseLevel": 2,
967
+ "UseClass": "Various Healthcare",
968
+ "UseClassModality": "Spas and Bathhouses",
969
+ "ConstructionValue": [2.65, 2.35, 2.10, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05]
970
+ },
971
+ "0831": {
972
+ "Use": "Health and Welfare",
973
+ "UseLevel": 2,
974
+ "UseClass": "Welfare and Assistance",
975
+ "UseClassModality": "With Residence (Asylums, Residences, etc.)",
976
+ "ConstructionValue": [2.45, 2.20, 2.00, 1.80, 1.60, 1.40, 1.25, 1.10, 1.00]
977
+ },
978
+ "0832": {
979
+ "Use": "Health and Welfare",
980
+ "UseLevel": 2,
981
+ "UseClass": "Welfare and Assistance",
982
+ "UseClassModality": "Without Residence (Dining Rooms, Clubs, Daycares, etc.)",
983
+ "ConstructionValue": [1.95, 1.75, 1.55, 1.40, 1.25, 1.10, 1.00, 0.90, 0.80]
984
+ },
985
+ "0911": {
986
+ "Use": "Cultural and Religious",
987
+ "UseLevel": 2,
988
+ "UseClass": "Cultural with Residence",
989
+ "UseClassModality": "Boarding Schools",
990
+ "ConstructionValue": [2.40, 2.15, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05, 0.95]
991
+ },
992
+ "0912": {
993
+ "Use": "Cultural and Religious",
994
+ "UseLevel": 2,
995
+ "UseClass": "Cultural with Residence",
996
+ "UseClassModality": "University Halls of Residence",
997
+ "ConstructionValue": [2.60, 2.35, 2.10, 1.90, 1.70, 1.50, 1.35, 1.20, 1.05]
998
+ },
999
+ "0921": {
1000
+ "Use": "Cultural and Religious",
1001
+ "UseLevel": 2,
1002
+ "UseClass": "Cultural without Residence",
1003
+ "UseClassModality": "Faculties, Colleges, and Schools",
1004
+ "ConstructionValue": [1.95, 1.75, 1.55, 1.40, 1.25, 1.10, 1.00, 0.90, 0.80]
1005
+ },
1006
+ "0922": {
1007
+ "Use": "Cultural and Religious",
1008
+ "UseLevel": 2,
1009
+ "UseClass": "Cultural without Residence",
1010
+ "UseClassModality": "Libraries and Museums",
1011
+ "ConstructionValue": [2.30, 2.05, 1.85, 1.65, 1.45, 1.30, 1.15, 1.00, 0.90]
1012
+ },
1013
+ "0931": {
1014
+ "Use": "Cultural and Religious",
1015
+ "UseLevel": 2,
1016
+ "UseClass": "Religious",
1017
+ "UseClassModality": "Convents and Parish Centers",
1018
+ "ConstructionValue": [1.75, 1.55, 1.40, 1.25, 1.10, 1.00, 0.90, 0.80, 0.70]
1019
+ },
1020
+ "0932": {
1021
+ "Use": "Cultural and Religious",
1022
+ "UseLevel": 2,
1023
+ "UseClass": "Religious",
1024
+ "UseClassModality": "Churches and Chapels",
1025
+ "ConstructionValue": [2.90, 2.60, 2.30, 2.00, 1.80, 1.60, 1.40, 1.20, 1.05]
1026
+ },
1027
+ "1011": {
1028
+ "Use": "Unique Buildings",
1029
+ "UseLevel": 1,
1030
+ "UseClass": "Historic-Artistic",
1031
+ "UseClassModality": "Monumental",
1032
+ "ConstructionValue": [2.90, 2.60, 2.30, 2.00, 1.80, 1.60, 1.40, 1.20, 1.05]
1033
+ },
1034
+ "1012": {
1035
+ "Use": "Unique Buildings",
1036
+ "UseLevel": 1,
1037
+ "UseClass": "Historic-Artistic",
1038
+ "UseClassModality": "Environmental or Typical",
1039
+ "ConstructionValue": [2.30, 2.05, 1.85, 1.65, 1.45, 1.30, 1.15, 1.00, 0.90]
1040
+ },
1041
+ "1021": {
1042
+ "Use": "Unique Buildings",
1043
+ "UseLevel": 1,
1044
+ "UseClass": "Official",
1045
+ "UseClassModality": "Administrative",
1046
+ "ConstructionValue": [2.55, 2.20, 1.85, 1.60, 1.30, 1.15, 1.00, 0.90, 0.80]
1047
+ },
1048
+ "1022": {
1049
+ "Use": "Unique Buildings",
1050
+ "UseLevel": 1,
1051
+ "UseClass": "Official",
1052
+ "UseClassModality": "Representative",
1053
+ "ConstructionValue": [2.75, 2.35, 2.00, 1.75, 1.50, 1.35, 1.20, 1.05, 0.95]
1054
+ },
1055
+ "1031": {
1056
+ "Use": "Unique Buildings",
1057
+ "UseLevel": 1,
1058
+ "UseClass": "Special",
1059
+ "UseClassModality": "Penitentiary, Military, and Various",
1060
+ "ConstructionValue": [2.20, 1.95, 1.75, 1.55, 1.40, 1.25, 1.10, 1.00, 0.85]
1061
+ },
1062
+ "1032": {
1063
+ "Use": "Unique Buildings",
1064
+ "UseLevel": 1,
1065
+ "UseClass": "Special",
1066
+ "UseClassModality": "Interior Urbanization Works",
1067
+ "ConstructionValue": [0.26, 0.22, 0.18, 0.15, 0.11, 0.08, 0.06, 0.04, 0.03]
1068
+ },
1069
+ "1033": {
1070
+ "Use": "Unique Buildings",
1071
+ "UseLevel": 1,
1072
+ "UseClass": "Special",
1073
+ "UseClassModality": "Campgrounds",
1074
+ "ConstructionValue": [0.18, 0.16, 0.14, 0.12, 0.10, 0.08, 0.06, 0.04, 0.02]
1075
+ },
1076
+ "1034": {
1077
+ "Use": "Unique Buildings",
1078
+ "UseLevel": 1,
1079
+ "UseClass": "Special",
1080
+ "UseClassModality": "Golf Courses",
1081
+ "ConstructionValue": [0.050, 0.040, 0.035, 0.030, 0.025, 0.020, 0.015, 0.010, 0.005]
1082
+ },
1083
+ "1035": {
1084
+ "Use": "Unique Buildings",
1085
+ "UseLevel": 1,
1086
+ "UseClass": "Special",
1087
+ "UseClassModality": "Gardening",
1088
+ "ConstructionValue": [0.17, 0.15, 0.13, 0.11, 0.09, 0.07, 0.05, 0.03, 0.01]
1089
+ },
1090
+ "1036": {
1091
+ "Use": "Unique Buildings",
1092
+ "UseLevel": 1,
1093
+ "UseClass": "Special",
1094
+ "UseClassModality": "Silos and Solid Storage (m³)",
1095
+ "ConstructionValue": [0.35, 0.30, 0.25, 0.20, 0.17, 0.15, 0.14, 0.12, 0.10]
1096
+ },
1097
+ "1037": {
1098
+ "Use": "Unique Buildings",
1099
+ "UseLevel": 1,
1100
+ "UseClass": "Special",
1101
+ "UseClassModality": "Liquid Storage (m³)",
1102
+ "ConstructionValue": [0.37, 0.34, 0.31, 0.29, 0.25, 0.23, 0.20, 0.17, 0.15]
1103
+ },
1104
+ "1038": {
1105
+ "Use": "Unique Buildings",
1106
+ "UseLevel": 1,
1107
+ "UseClass": "Special",
1108
+ "UseClassModality": "Gas Storage (m³)",
1109
+ "ConstructionValue": [0.80, 0.65, 0.50, 0.40, 0.37, 0.35, 0.31, 0.27, 0.25]
1110
+ }
1111
+ }
1112
+
1113
+ building_space_age_value = [
1114
+ {
1115
+ "Age": [0, 4],
1116
+ "1": [1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
1117
+ "2": [1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
1118
+ "3": [1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00]
1119
+ },
1120
+ {
1121
+ "Age": [5, 9],
1122
+ "1": [0.93, 0.93, 0.92, 0.92, 0.92, 0.92, 0.90, 0.90, 0.90],
1123
+ "2": [0.93, 0.93, 0.91, 0.91, 0.91, 0.91, 0.89, 0.89, 0.89],
1124
+ "3": [0.92, 0.92, 0.90, 0.90, 0.90, 0.90, 0.88, 0.88, 0.88]
1125
+ },
1126
+ {
1127
+ "Age": [10, 14],
1128
+ "1": [0.87, 0.87, 0.85, 0.85, 0.85, 0.85, 0.82, 0.82, 0.82],
1129
+ "2": [0.86, 0.86, 0.84, 0.84, 0.84, 0.84, 0.80, 0.80, 0.80],
1130
+ "3": [0.84, 0.84, 0.82, 0.82, 0.82, 0.82, 0.78, 0.78, 0.78]
1131
+ },
1132
+ {
1133
+ "Age": [15, 19],
1134
+ "1": [0.82, 0.82, 0.79, 0.79, 0.79, 0.79, 0.74, 0.74, 0.74],
1135
+ "2": [0.80, 0.80, 0.77, 0.77, 0.77, 0.77, 0.72, 0.72, 0.72],
1136
+ "3": [0.78, 0.78, 0.74, 0.74, 0.74, 0.74, 0.69, 0.69, 0.69]
1137
+ },
1138
+ {
1139
+ "Age": [20, 24],
1140
+ "1": [0.77, 0.77, 0.73, 0.73, 0.73, 0.73, 0.67, 0.67, 0.67],
1141
+ "2": [0.75, 0.75, 0.70, 0.70, 0.70, 0.70, 0.64, 0.64, 0.64],
1142
+ "3": [0.72, 0.72, 0.67, 0.67, 0.67, 0.67, 0.61, 0.61, 0.61]
1143
+ },
1144
+ {
1145
+ "Age": [25, 29],
1146
+ "1": [0.72, 0.72, 0.68, 0.68, 0.68, 0.68, 0.61, 0.61, 0.61],
1147
+ "2": [0.70, 0.70, 0.65, 0.65, 0.65, 0.65, 0.58, 0.58, 0.58],
1148
+ "3": [0.67, 0.67, 0.61, 0.61, 0.61, 0.61, 0.54, 0.54, 0.54]
1149
+ },
1150
+ {
1151
+ "Age": [30, 34],
1152
+ "1": [0.68, 0.68, 0.63, 0.63, 0.63, 0.63, 0.56, 0.56, 0.56],
1153
+ "2": [0.65, 0.65, 0.60, 0.60, 0.60, 0.60, 0.53, 0.53, 0.53],
1154
+ "3": [0.62, 0.62, 0.56, 0.56, 0.56, 0.56, 0.49, 0.49, 0.49]
1155
+ },
1156
+ {
1157
+ "Age": [35, 39],
1158
+ "1": [0.64, 0.64, 0.59, 0.59, 0.59, 0.59, 0.51, 0.51, 0.51],
1159
+ "2": [0.61, 0.61, 0.56, 0.56, 0.56, 0.56, 0.48, 0.48, 0.48],
1160
+ "3": [0.58, 0.58, 0.51, 0.51, 0.51, 0.51, 0.44, 0.44, 0.44]
1161
+ },
1162
+ {
1163
+ "Age": [40, 44],
1164
+ "1": [0.61, 0.61, 0.55, 0.55, 0.55, 0.55, 0.47, 0.47, 0.47],
1165
+ "2": [0.57, 0.57, 0.52, 0.52, 0.52, 0.52, 0.44, 0.44, 0.44],
1166
+ "3": [0.54, 0.54, 0.47, 0.47, 0.47, 0.47, 0.39, 0.39, 0.39]
1167
+ },
1168
+ {
1169
+ "Age": [45, 49],
1170
+ "1": [0.58, 0.58, 0.52, 0.52, 0.52, 0.52, 0.43, 0.43, 0.43],
1171
+ "2": [0.54, 0.54, 0.48, 0.48, 0.48, 0.48, 0.40, 0.40, 0.40],
1172
+ "3": [0.50, 0.50, 0.43, 0.43, 0.43, 0.43, 0.35, 0.35, 0.35]
1173
+ },
1174
+ {
1175
+ "Age": [50, 54],
1176
+ "1": [0.55, 0.55, 0.49, 0.49, 0.49, 0.49, 0.40, 0.40, 0.40],
1177
+ "2": [0.51, 0.51, 0.45, 0.45, 0.45, 0.45, 0.37, 0.37, 0.37],
1178
+ "3": [0.47, 0.47, 0.40, 0.40, 0.40, 0.40, 0.32, 0.32, 0.32]
1179
+ },
1180
+ {
1181
+ "Age": [55, 59],
1182
+ "1": [0.52, 0.52, 0.46, 0.46, 0.46, 0.46, 0.37, 0.37, 0.37],
1183
+ "2": [0.48, 0.48, 0.42, 0.42, 0.42, 0.42, 0.34, 0.34, 0.34],
1184
+ "3": [0.44, 0.44, 0.37, 0.37, 0.37, 0.37, 0.29, 0.29, 0.29]
1185
+ },
1186
+ {
1187
+ "Age": [60, 64],
1188
+ "1": [0.49, 0.49, 0.43, 0.43, 0.43, 0.43, 0.34, 0.34, 0.34],
1189
+ "2": [0.45, 0.45, 0.39, 0.39, 0.39, 0.39, 0.31, 0.31, 0.31],
1190
+ "3": [0.41, 0.41, 0.34, 0.34, 0.34, 0.34, 0.26, 0.26, 0.26]
1191
+ },
1192
+ {
1193
+ "Age": [65, 69],
1194
+ "1": [0.47, 0.47, 0.41, 0.41, 0.41, 0.41, 0.32, 0.32, 0.32],
1195
+ "2": [0.43, 0.43, 0.37, 0.37, 0.37, 0.37, 0.29, 0.29, 0.29],
1196
+ "3": [0.39, 0.39, 0.32, 0.32, 0.32, 0.32, 0.24, 0.24, 0.24]
1197
+ },
1198
+ {
1199
+ "Age": [70, 74],
1200
+ "1": [0.45, 0.45, 0.39, 0.39, 0.39, 0.39, 0.30, 0.30, 0.30],
1201
+ "2": [0.41, 0.41, 0.35, 0.35, 0.35, 0.35, 0.27, 0.27, 0.27],
1202
+ "3": [0.37, 0.37, 0.30, 0.30, 0.30, 0.30, 0.22, 0.22, 0.22]
1203
+ },
1204
+ {
1205
+ "Age": [75, 79],
1206
+ "1": [0.43, 0.43, 0.37, 0.37, 0.37, 0.37, 0.28, 0.28, 0.28],
1207
+ "2": [0.39, 0.39, 0.33, 0.33, 0.33, 0.33, 0.25, 0.25, 0.25],
1208
+ "3": [0.35, 0.35, 0.28, 0.28, 0.28, 0.28, 0.20, 0.20, 0.20]
1209
+ },
1210
+ {
1211
+ "Age": [80, 84],
1212
+ "1": [0.41, 0.41, 0.35, 0.35, 0.35, 0.35, 0.26, 0.26, 0.26],
1213
+ "2": [0.37, 0.37, 0.31, 0.31, 0.31, 0.31, 0.23, 0.23, 0.23],
1214
+ "3": [0.33, 0.33, 0.26, 0.26, 0.26, 0.26, 0.19, 0.19, 0.19]
1215
+ },
1216
+ {
1217
+ "Age": [85, 89],
1218
+ "1": [0.40, 0.40, 0.33, 0.33, 0.33, 0.33, 0.25, 0.25, 0.25],
1219
+ "2": [0.36, 0.36, 0.29, 0.29, 0.29, 0.29, 0.21, 0.21, 0.21],
1220
+ "3": [0.31, 0.31, 0.25, 0.25, 0.25, 0.25, 0.18, 0.18, 0.18]
1221
+ },
1222
+ {
1223
+ "Age": [90, np.inf],
1224
+ "1": [0.39, 0.39, 0.32, 0.32, 0.32, 0.32, 0.24, 0.24, 0.24],
1225
+ "2": [0.35, 0.35, 0.28, 0.28, 0.28, 0.28, 0.20, 0.20, 0.20],
1226
+ "3": [0.30, 0.30, 0.24, 0.24, 0.24, 0.24, 0.17, 0.17, 0.17]
1227
+ }
1228
+ ]
1229
+
1230
+ # 15 - Registro de Inmueble
1231
+ catstruct[15] = [
1232
+ [24, 2, 'N', 'delegation_meh_code', pl.Utf8],
1233
+ [26, 3, 'N', 'municipality_cadaster_code', pl.Utf8],
1234
+ [29, 2, 'X', 'real_estate_type', pl.Utf8],
1235
+ [31, 14, 'X', 'building_reference', pl.Utf8],
1236
+ [45, 4, 'N', 'space1_reference', pl.Utf8],
1237
+ [49, 1, 'X', 'space2_reference', pl.Utf8],
1238
+ [50, 1, 'X', 'space3_reference', pl.Utf8],
1239
+ [51, 8, 'N', 'real_estate_fix_number', pl.Utf8],
1240
+ [59, 15, 'X', 'real_estate_id_city_council', pl.Utf8],
1241
+ [74, 19, 'X', 'register_reference', pl.Utf8],
1242
+ [93, 2, 'N', 'province_code', pl.Utf8],
1243
+ [95, 25, 'X', 'province_name', pl.Utf8],
1244
+ [120, 3, 'N', 'municipality_cadaster_code_2', pl.Utf8],
1245
+ [123, 3, 'N', 'municipality_ine_code', pl.Utf8],
1246
+ [126, 40, 'X', 'municipality_name', pl.Utf8],
1247
+ [166, 30, 'X', 'minor_entity_name', pl.Utf8],
1248
+ [196, 5, 'N', 'street_cadaster_code', pl.Utf8],
1249
+ [201, 5, 'X', 'street_type', pl.Utf8],
1250
+ [206, 25, 'X', 'street_name', pl.Utf8],
1251
+ [231, 4, 'N', 'street_number1', pl.Utf8],
1252
+ [235, 1, 'X', 'street_letter1', pl.Utf8],
1253
+ [236, 4, 'N', 'street_number2', pl.Utf8],
1254
+ [240, 1, 'X', 'street_letter2', pl.Utf8],
1255
+ [241, 5, 'N', 'km', pl.Utf8],
1256
+ [246, 4, 'X', 'building_block_name', pl.Utf8],
1257
+ [250, 2, 'X', 'building_stair_name', pl.Utf8],
1258
+ [252, 3, 'X', 'building_floor_name', pl.Utf8],
1259
+ [255, 3, 'X', 'building_door_name', pl.Utf8],
1260
+ [258, 25, 'X', 'street_unstructured', pl.Utf8],
1261
+ [283, 5, 'N', 'postal_code', pl.Utf8],
1262
+ [288, 2, 'X', 'district_code', pl.Utf8],
1263
+ [290, 3, 'N', 'alternative_municipality_cadaster_code', pl.Utf8],
1264
+ [293, 2, 'N', 'concentration_zone_code', pl.Utf8],
1265
+ [295, 3, 'N', 'polygon_code', pl.Utf8],
1266
+ [298, 5, 'N', 'parcel_code', pl.Utf8],
1267
+ [303, 5, 'X', 'site_cadastral_code', pl.Utf8],
1268
+ [308, 30, 'X', 'site_name', pl.Utf8],
1269
+ [368, 4, 'X', 'real_estate_notarial_deed_order', pl.Utf8],
1270
+ [372, 4, 'N', 'building_space_year', pl.Int16],
1271
+ [428, 1, 'X', 'building_space_use_type', pl.Utf8],
1272
+ [442, 10, 'N', 'building_space_total_area', pl.Float32],
1273
+ [452, 10, 'N', 'building_space_related_area', pl.Float32],
1274
+ [462, 9, 'N', 'building_space_participation_rate', pl.Float32]
1275
+ ]
1276
+
1277
+ building_space_use_types = {
1278
+ "1": "Buildings intended for electricity and gas production, oil refining, and nuclear power plants",
1279
+ "2": "Dams, waterfalls, and reservoirs",
1280
+ "3": "Highways, roads, and toll tunnels",
1281
+ "4": "Airports and commercial ports",
1282
+ "A": "Warehouse - Parking",
1283
+ "V": "Residential",
1284
+ "I": "Industrial",
1285
+ "O": "Offices",
1286
+ "C": "Commercial",
1287
+ "K": "Sports facilities",
1288
+ "T": "Entertainment venues",
1289
+ "G": "Leisure and Hospitality",
1290
+ "Y": "Healthcare and Charity",
1291
+ "E": "Cultural",
1292
+ "R": "Religious",
1293
+ "M": "Urbanization and landscaping works, undeveloped land",
1294
+ "P": "Singular building",
1295
+ "B": "Agricultural warehouse",
1296
+ "J": "Agricultural industrial",
1297
+ "Z": "Agricultural"
1298
+ }
1299
+
1300
+ # 16 - Registro de reparto de elementos comunes
1301
+ catstruct[16] = [
1302
+ [24, 2, 'N', 'codigo_delegacion_meh', pl.Utf8],
1303
+ [26, 3, 'N', 'codigo_municipio_dgc', pl.Utf8],
1304
+ [31, 14, 'X', 'parcela_catastral', pl.Utf8],
1305
+ [45, 4, 'N', 'numero_elemento', pl.Utf8],
1306
+ [49, 2, 'X', 'calificacion_catastral_subparcela_abstracta', pl.Utf8],
1307
+ [51, 4, 'N', 'numero_orden_segmento', pl.Utf8],
1308
+ [55, 59, 'N', 'b1', pl.Utf8],
1309
+ [114, 59, 'N', 'b2', pl.Utf8],
1310
+ [173, 59, 'N', 'b3', pl.Utf8],
1311
+ [232, 59, 'N', 'b4', pl.Utf8],
1312
+ [291, 59, 'N', 'b5', pl.Utf8],
1313
+ [350, 59, 'N', 'b6', pl.Utf8],
1314
+ [409, 59, 'N', 'b7', pl.Utf8],
1315
+ [468, 59, 'N', 'b8', pl.Utf8],
1316
+ [527, 59, 'N', 'b9', pl.Utf8],
1317
+ [586, 59, 'N', 'b10', pl.Utf8],
1318
+ [645, 59, 'N', 'b11', pl.Utf8],
1319
+ [704, 59, 'N', 'b12', pl.Utf8],
1320
+ [763, 59, 'N', 'b13', pl.Utf8],
1321
+ [822, 59, 'N', 'b14', pl.Utf8],
1322
+ [881, 59, 'N', 'b15', pl.Utf8]
1323
+ ]
1324
+
1325
+ # 17 - Registro de cultivos
1326
+ catstruct[17] = [
1327
+ [24, 2, 'N', 'codigo_delegacion_meh', pl.Utf8],
1328
+ [26, 3, 'N', 'codigo_municipio_dgc', pl.Utf8],
1329
+ [29, 2, 'X', 'naturaleza_suelo_ocupado', pl.Utf8], # 'UR' urbana, 'RU' rustica
1330
+ [31, 14, 'X', 'parcela_catastral', pl.Utf8],
1331
+ [45, 4, 'X', 'codigo_subparcela', pl.Utf8],
1332
+ [51, 4, 'N', 'numero_orden_fiscal_en_parcela', pl.Utf8],
1333
+ [55, 1, 'X', 'tipo_subparcela', pl.Utf8], # 'T' terreno, 'A' absracta, 'D' dominio publico
1334
+ [56, 10, 'N', 'superficie_subparcela_m2', pl.Float32],
1335
+ [66, 2, 'X', 'calificacion_catastral_o_clase_cultivo', pl.Utf8],
1336
+ [68, 40, 'X', 'denominacion_clase_cultivo', pl.Utf8],
1337
+ [108, 2, 'N', 'intensidad_productiva', pl.Utf8],
1338
+ [127, 3, 'X', 'codigo_modalidad_reparto', pl.Utf8] # [TA]C[1234]
1339
+ ]
1340
+
1341
+ # 46 - Registro de situaciones finales de titularidad
1342
+ catstruct[46] = [
1343
+ [24, 2, 'N', 'codigo_delegacion_meh', pl.Utf8],
1344
+ [26, 3, 'N', 'codigo_municipio_dgc', pl.Utf8],
1345
+ [29, 2, 'X', 'naturaleza_suelo_ocupado', pl.Utf8], # 'UR' urbana, 'RU' rustica
1346
+ [31, 14, 'X', 'parcela_catastral', pl.Utf8],
1347
+ [45, 4, 'X', 'codigo_subparcela', pl.Utf8],
1348
+ [49, 1, 'X', 'primer_carac_control', pl.Utf8],
1349
+ [50, 1, 'X', 'segundo_carac_control', pl.Utf8],
1350
+ [51, 2, 'X', 'codigo_derecho', pl.Utf8],
1351
+ [53, 5, 'N', 'porcentaje_derecho', pl.Utf8],
1352
+ [58, 3, 'N', 'ordinal_derecho', pl.Utf8],
1353
+ [61, 9, 'X', 'nif_titular', pl.Utf8],
1354
+ [70, 60, 'X', 'nombre_titular', pl.Utf8], # Primer apellido, segundo y nombre o razón social
1355
+ [130, 1, 'X', 'motivo_no_nif', pl.Utf8], # 1 Extranjero, 2 menor de edad, 9 otras situaciones
1356
+ [131, 2, 'N', 'codigo_provincia_ine', pl.Utf8],
1357
+ [133, 25, 'X', 'nombre_provincia', pl.Utf8],
1358
+ [158, 3, 'N', 'codigo_municipio_dgc', pl.Utf8],
1359
+ [161, 3, 'N', 'codigo_municipio_ine', pl.Utf8],
1360
+ [164, 40, 'X', 'nombre_municipio', pl.Utf8],
1361
+ [204, 30, 'X', 'nombre_entidad_menor', pl.Utf8],
1362
+ [235, 5, 'N', 'codigo_via_publica_dgc', pl.Utf8],
1363
+ [239, 5, 'X', 'tipo_via', pl.Utf8],
1364
+ [244, 25, 'X', 'nombre_via', pl.Utf8],
1365
+ [269, 4, 'N', 'primer_numero_policia', pl.Utf8],
1366
+ [273, 1, 'X', 'primera_letra', pl.Utf8],
1367
+ [274, 4, 'N', 'segundo_numero_policia', pl.Utf8],
1368
+ [278, 1, 'X', 'segunda_letra', pl.Utf8],
1369
+ [279, 5, 'N', 'kilometro_por_cien', pl.Utf8],
1370
+ [284, 4, 'X', 'bloque', pl.Utf8],
1371
+ [288, 2, 'X', 'escalera', pl.Utf8],
1372
+ [290, 3, 'X', 'planta', pl.Utf8],
1373
+ [293, 3, 'X', 'puerta', pl.Utf8],
1374
+ [296, 25, 'X', 'direccion_no_estructurada', pl.Utf8],
1375
+ [321, 5, 'N', 'codigo_postal', pl.Utf8],
1376
+ [326, 5, 'N', 'apartado_correos', pl.Utf8],
1377
+ [331, 9, 'X', 'nif_conyuge', pl.Utf8],
1378
+ [340, 9, 'X', 'nif_cb', pl.Utf8],
1379
+ [349, 20, 'X', 'complemento_titularidad', pl.Utf8]
1380
+ ]
1381
+
1382
+ # 47 - Registro de comunidad de bienes formalmente constituida presente en una situación final
1383
+ catstruct[47] = [
1384
+ [24, 2, 'N', 'codigo_delegacion_meh', pl.Utf8],
1385
+ [26, 3, 'N', 'codigo_municipio_dgc', pl.Utf8],
1386
+ [29, 2, 'X', 'naturaleza_suelo_ocupado', pl.Utf8], # 'UR' urbana, 'RU' rustica
1387
+ [31, 14, 'X', 'parcela_catastral', pl.Utf8],
1388
+ [45, 4, 'X', 'codigo_subparcela', pl.Utf8],
1389
+ [49, 1, 'X', 'primer_carac_control', pl.Utf8],
1390
+ [50, 1, 'X', 'segundo_carac_control', pl.Utf8],
1391
+ [51, 9, 'X', 'nif_comunidad_bienes', pl.Utf8],
1392
+ [60, 60, 'X', 'denominacion_razon_socil', pl.Utf8],
1393
+ [120, 2, 'N', 'codigo_provincia_ine', pl.Utf8],
1394
+ [122, 25, 'X', 'nombre_provincia', pl.Utf8],
1395
+ [147, 3, 'N', 'codigo_municipio_dgc', pl.Utf8],
1396
+ [150, 3, 'N', 'codigo_municipio_ine', pl.Utf8],
1397
+ [153, 40, 'X', 'nombre_municipio', pl.Utf8],
1398
+ [193, 30, 'X', 'nombre_entidad_menor', pl.Utf8],
1399
+ [223, 5, 'N', 'codigo_via_publica_dgc', pl.Utf8],
1400
+ [228, 5, 'X', 'tipo_via', pl.Utf8],
1401
+ [233, 25, 'X', 'nombre_via', pl.Utf8],
1402
+ [258, 4, 'N', 'primer_numero_policia', pl.Utf8],
1403
+ [262, 1, 'X', 'primera_letra', pl.Utf8],
1404
+ [263, 4, 'N', 'segundo_numero_policia', pl.Utf8],
1405
+ [267, 1, 'X', 'segunda_letra', pl.Utf8],
1406
+ [268, 5, 'N', 'kilometro_por_cien', pl.Utf8],
1407
+ [273, 4, 'X', 'bloque', pl.Utf8],
1408
+ [277, 2, 'X', 'escalera', pl.Utf8],
1409
+ [279, 3, 'X', 'planta', pl.Utf8],
1410
+ [282, 3, 'X', 'puerta', pl.Utf8],
1411
+ [285, 25, 'X', 'direccion_no_estructurada', pl.Utf8],
1412
+ [310, 5, 'N', 'codigo_postal', pl.Utf8],
1413
+ [315, 5, 'N', 'apartado_correos', pl.Utf8]
1414
+ ]
1415
+
1416
+ # 90 - Registro de cola
1417
+ catstruct[90] = [
1418
+ [10, 7, 'N', 'numero_registros_tipo_11', pl.Utf8],
1419
+ [24, 7, 'N', 'numero_registros_tipo_13', pl.Utf8],
1420
+ [31, 7, 'N', 'numero_registros_tipo_14', pl.Utf8],
1421
+ [38, 7, 'N', 'numero_registros_tipo_15', pl.Utf8],
1422
+ [45, 7, 'N', 'numero_registros_tipo_16', pl.Utf8],
1423
+ [52, 7, 'N', 'numero_registros_tipo_17', pl.Utf8],
1424
+ [59, 7, 'N', 'numero_registros_tipo_46', pl.Utf8],
1425
+ [66, 7, 'N', 'numero_registros_tipo_47', pl.Utf8]
1426
+ ]
1427
+
1428
+
1429
+ def parse_CAT_file(cadaster_code, CAT_files_dir, allowed_dataset_types = [14, 15]):
1430
+
1431
+ # Function to parse a single line into a dictionary for each record type
1432
+ def process_line(line, allowed_dataset_types):
1433
+ parsed_row = {}
1434
+
1435
+ line = line.encode('utf-8').decode('utf-8')
1436
+ line_type = int(line[0:2]) # Record type
1437
+
1438
+ # Only process if the record type is below 15 and known in catstruct
1439
+ if line_type in allowed_dataset_types and line_type in catstruct:
1440
+ row = []
1441
+ for campos in catstruct[line_type]:
1442
+ ini = campos[0] - 1 # Offset
1443
+ fin = ini + campos[1] # Length
1444
+ valor = line[ini:fin].strip() # Extracted value
1445
+ row.append(valor)
1446
+
1447
+ # Store parsed row with its type
1448
+ parsed_row[line_type] = row
1449
+
1450
+ return parsed_row
1451
+
1452
+
1453
+ # Function to combine parsed rows into Polars DataFrames
1454
+ def combine_dataframes(parsed_rows):
1455
+ # Initialize an empty dictionary to accumulate rows for each record type
1456
+ row_data = {dataset_type: [] for dataset_type in catstruct}
1457
+
1458
+ # Aggregate rows for each type from parsed rows
1459
+ for row_dict in parsed_rows:
1460
+ for dataset_type, row in row_dict.items():
1461
+ row_data[dataset_type].append(row)
1462
+
1463
+ # Create DataFrames from aggregated rows and schema
1464
+ combined_dfs = {}
1465
+ for dataset_type, rows in row_data.items():
1466
+ schema = {i[3]: i[4] for i in catstruct[dataset_type]}
1467
+ combined_dfs[dataset_type] = pl.DataFrame(rows, schema=schema, orient="row")
1468
+
1469
+ return combined_dfs
1470
+
1471
+
1472
+ # Main function to process the file in chunks and save as Parquet
1473
+ def process_file_in_chunks(inputfile, CAT_files_dir, cadaster_code, allowed_dataset_types):
1474
+ with open(inputfile, encoding='latin-1') as rf:
1475
+ lines = rf.readlines() # Read all lines at once for chunk processing
1476
+
1477
+ if isinstance(allowed_dataset_types, str) or isinstance(allowed_dataset_types,int):
1478
+ allowed_dataset_types = [int(allowed_dataset_types)]
1479
+ elif isinstance(allowed_dataset_types, list):
1480
+ allowed_dataset_types = [int(dt) for dt in allowed_dataset_types]
1481
+
1482
+ if not all([os.path.exists(f"{CAT_files_dir}/parquet/{cadaster_code}_{dataset_type}.parquet") for
1483
+ dataset_type in allowed_dataset_types]):
1484
+ # Process each line in parallel
1485
+ with utils.tqdm_joblib(tqdm(desc="Reading the CAT file...", total=len(lines))):
1486
+ parsed_rows = Parallel(n_jobs=-1)(
1487
+ delayed(process_line)(line, allowed_dataset_types) for line in lines
1488
+ )
1489
+ get_reusable_executor().shutdown(wait=True)
1490
+
1491
+ # Combine all parsed rows into DataFrames
1492
+ combined_dfs = combine_dataframes(parsed_rows)
1493
+
1494
+ # Save each DataFrame to Parquet
1495
+ for dataset_type, df in combined_dfs.items():
1496
+ if len(df)>1:
1497
+ output_path = f"{CAT_files_dir}/parquet/{cadaster_code}_{dataset_type}.parquet"
1498
+ df.write_parquet(output_path)
1499
+
1500
+ else:
1501
+ combined_dfs = {k:None for k in catstruct.keys()}
1502
+ for dataset_type in allowed_dataset_types:
1503
+ combined_dfs[dataset_type] = pl.read_parquet(f"{CAT_files_dir}/parquet/{cadaster_code}_{dataset_type}.parquet")
1504
+
1505
+ return combined_dfs
1506
+
1507
+
1508
+ def get_CAT_file_path(CAT_files_dir, cadaster_code, timeout=3600):
1509
+ CAT_file = None
1510
+ message_displayed = False # Track whether the message has been displayed
1511
+ task_time = 0
1512
+ start_time = time.time()
1513
+ while CAT_file is None or task_time < timeout:
1514
+ try:
1515
+ CAT_files = os.listdir(f"{CAT_files_dir}")
1516
+ CAT_files = sorted(
1517
+ CAT_files,
1518
+ key=lambda i: f"{i[:5]}_{i[-8:-4]}{i[-10:-8]}{i[-12:-10]}",
1519
+ reverse=True
1520
+ )
1521
+ CAT_files = [file for file in CAT_files if file.startswith(cadaster_code)]
1522
+ if len(CAT_files) > 0:
1523
+ CAT_file = CAT_files[0]
1524
+ return os.path.join(CAT_files_dir, CAT_file)
1525
+ else:
1526
+ if not message_displayed:
1527
+ sys.stderr.write(
1528
+ f"\nPlease, upload the CAT file in {CAT_files_dir} for municipality {cadaster_code} (cadaster code). "
1529
+ "\nYou can download them in subsets of provinces clicking in 'Downloads of alphanumeric information by province (CAT format)'"
1530
+ "\nof the following website: https://www.sedecatastro.gob.es/Accesos/SECAccDescargaDatos.aspx"
1531
+ )
1532
+ sys.stderr.flush()
1533
+ message_displayed = True
1534
+ # Check again after a short delay
1535
+ time.sleep(3)
1536
+ task_time = time.time() - start_time
1537
+ except KeyboardInterrupt:
1538
+ sys.stderr.write("\nProcess interrupted by user. Exiting gracefully...\n")
1539
+ return None
1540
+
1541
+ return CAT_file
1542
+
1543
+ # Ensure directories exist
1544
+ os.makedirs(f"{CAT_files_dir}", exist_ok=True)
1545
+ os.makedirs(f"{CAT_files_dir}/parquet", exist_ok=True)
1546
+
1547
+ inputfile = get_CAT_file_path(CAT_files_dir, cadaster_code)
1548
+
1549
+ if inputfile is not None:
1550
+ combined_dfs = process_file_in_chunks(inputfile, CAT_files_dir, cadaster_code, allowed_dataset_types)
1551
+ return combined_dfs