Create Building Inventory from NSI data#

Building inventories are essential components for evaluating community resilience and accurately quantifying potential damages resulting from natural hazards. However, developing detailed and accurate building inventories presents significant challenges, primarily due to limited community resources and frequently incomplete data attributes essential for damage modeling. This notebook outlines a robust solution implemented within the Interdependent Networked Community Resilience Modeling Environment (IN-CORE), a computational platform created by the NIST Center of Excellence for Community Resilience Planning. Utilizing the US Army Corps of Engineers’ National Structure Inventory (NSI), this integrated system efficiently generates community-specific building inventories by employing county-level FIPS codes coupled with tailored algorithms designed for IN-CORE. The automated inventories produced contain critical structural attributes necessary for accurately assessing resilience against earthquakes, tsunamis, floods, and hurricanes. The streamlined inventory generation process greatly enhances the capability of communities to perform comprehensive resilience modeling and supports future expansions targeting additional hazards and finer attribute resolutions.

import os

from pyincore_data.nsiparser import NsiParser
from pyincore_data.nsibuildinginventory import NsiBuildingInventory
from pyincore_data.utils.nsiutil import NsiUtil

Create NSI GeodataFrame by county FIPS code#

You can create a building inventory by using a single FIPS code of the county

fips = '15005'
gdf = NsiParser.create_nsi_gdf_by_county_fips(fips)
print(gdf.head())
Requesting data for 15005 from NSI endpoint
Creating FIPS-related columns
                      geometry      fd_id                   bid    occtype  \
0  POINT (-156.98387 21.18893)  594360262  73H552Q8+HFC-2-2-3-3       RES5   
1  POINT (-156.98055 21.18677)  594360224  73H552P9+PQ4-2-2-1-2  RES1-1SNB   
2  POINT (-156.98195 21.19164)  594360225  73H552R9+M63-6-7-7-6  RES1-2SNB   
3  POINT (-156.97948 21.19230)  594360226  73H552RC+W6C-1-1-2-1      RES3C   
4  POINT (-156.97976 21.19328)  594360227  73H552VC+839-3-4-3-4       RES5   

  st_damcat bldgtype found_type           cbfips  pop2amu65  pop2amo65  ...  \
0       COM        M          I  150050319001015          1          0  ...   
1       RES        C          C  150050319001033          0          0  ...   
2       RES        W          I  150050319001026          1          0  ...   
3       RES        S          S  150050319001027          5          0  ...   
4       COM        C          C  150050319001027          0          0  ...   

   o65disable  u65disable           x          y ground_elv ground_elv_m  \
0        0.38           0 -156.983870  21.188934  59.208809    18.046844   
1        0.38           0 -156.980552  21.186771  72.205031    22.008093   
2        0.38           0 -156.981951  21.191636  62.314834    18.993561   
3        0.38           0 -156.979481  21.192303  65.616800    20.000000   
4        0.38           0 -156.979755  21.193278  65.616800    20.000000   

                                   guid   fips  statefips  countyfips  
0  a985b4b2-509d-4540-81e6-f024516d8ff0  15005         15         005  
1  da5ca5d0-1fd9-41bf-978f-4110d54668ab  15005         15         005  
2  c12b2685-cff5-4ceb-986b-b35afceb084c  15005         15         005  
3  ef392c57-504e-48b5-a743-8b028a1430c2  15005         15         005  
4  0fb85ac9-0b2f-4952-8d00-aa93baabe62e  15005         15         005  

[5 rows x 34 columns]

Convert the created NSI building inventory to a shapefile file#

After creating a building inventory geedataframe, this can be converted to ESRI Shapefile

gdf.to_file('output.shp', driver='ESRI Shapefile')

Convert the created NSI building inventory to a geopackage file#

Building inventory geodataframe can be saved as GeoPakcage file

gdf.to_file('output.gpkg', driver='GPKG')

Create NSI GeodataFrame by counties’ FIPS code list#

Building inventory can be created by using the mutiple FIPS code by providing them as a list format

fips_list = ['15005', '29001', '01001']
gdf = NsiParser.create_nsi_gdf_by_counties_fips_list(fips_list)
print(gdf.head())
Processing FIPS: 15005
Requesting data for 15005 from NSI endpoint
Creating FIPS-related columns
Processing FIPS: 29001
Requesting data for 29001 from NSI endpoint
Creating FIPS-related columns
Processing FIPS: 01001
Requesting data for 01001 from NSI endpoint
Creating FIPS-related columns
                      geometry      fd_id                   bid    occtype  \
0  POINT (-156.98387 21.18893)  594360262  73H552Q8+HFC-2-2-3-3       RES5   
1  POINT (-156.98055 21.18677)  594360224  73H552P9+PQ4-2-2-1-2  RES1-1SNB   
2  POINT (-156.98195 21.19164)  594360225  73H552R9+M63-6-7-7-6  RES1-2SNB   
3  POINT (-156.97948 21.19230)  594360226  73H552RC+W6C-1-1-2-1      RES3C   
4  POINT (-156.97976 21.19328)  594360227  73H552VC+839-3-4-3-4       RES5   

  st_damcat bldgtype found_type           cbfips  pop2amu65  pop2amo65  ...  \
0       COM        M          I  150050319001015          1          0  ...   
1       RES        C          C  150050319001033          0          0  ...   
2       RES        W          I  150050319001026          1          0  ...   
3       RES        S          S  150050319001027          5          0  ...   
4       COM        C          C  150050319001027          0          0  ...   

   o65disable  u65disable           x          y ground_elv ground_elv_m  \
0        0.38         0.0 -156.983870  21.188934  59.208809    18.046844   
1        0.38         0.0 -156.980552  21.186771  72.205031    22.008093   
2        0.38         0.0 -156.981951  21.191636  62.314834    18.993561   
3        0.38         0.0 -156.979481  21.192303  65.616800    20.000000   
4        0.38         0.0 -156.979755  21.193278  65.616800    20.000000   

                                   guid   fips  statefips  countyfips  
0  a4b5f1fd-ec8b-474b-9cfa-3e3775d4fe36  15005         15         005  
1  393f11af-4ba0-4036-a582-2d1430f23465  15005         15         005  
2  93ff4579-dbbc-4f84-a72f-179aea3a9e7a  15005         15         005  
3  96b952ed-c457-4be6-98f7-8d20c5d4932c  15005         15         005  
4  7fd749fc-02f9-4330-b983-c67cdb1678bc  15005         15         005  

[5 rows x 34 columns]

Get County FIPS by the state name#

State FIPS code value can be found by the state name

state = 'illinois'
fips_list = NsiParser.get_county_fips_by_state(state)
print(fips_list)
[{'county': 'Alexander County, Illinois', 'fips': '17003'}, {'county': 'Boone County, Illinois', 'fips': '17007'}, {'county': 'Brown County, Illinois', 'fips': '17009'}, {'county': 'Calhoun County, Illinois', 'fips': '17013'}, {'county': 'Carroll County, Illinois', 'fips': '17015'}, {'county': 'Champaign County, Illinois', 'fips': '17019'}, {'county': 'Clark County, Illinois', 'fips': '17023'}, {'county': 'Clay County, Illinois', 'fips': '17025'}, {'county': 'Coles County, Illinois', 'fips': '17029'}, {'county': 'Cook County, Illinois', 'fips': '17031'}, {'county': 'Cumberland County, Illinois', 'fips': '17035'}, {'county': 'DeKalb County, Illinois', 'fips': '17037'}, {'county': 'Douglas County, Illinois', 'fips': '17041'}, {'county': 'Edgar County, Illinois', 'fips': '17045'}, {'county': 'Edwards County, Illinois', 'fips': '17047'}, {'county': 'Fayette County, Illinois', 'fips': '17051'}, {'county': 'Ford County, Illinois', 'fips': '17053'}, {'county': 'Fulton County, Illinois', 'fips': '17057'}, {'county': 'Gallatin County, Illinois', 'fips': '17059'}, {'county': 'Grundy County, Illinois', 'fips': '17063'}, {'county': 'Hancock County, Illinois', 'fips': '17067'}, {'county': 'Hardin County, Illinois', 'fips': '17069'}, {'county': 'Henry County, Illinois', 'fips': '17073'}, {'county': 'Iroquois County, Illinois', 'fips': '17075'}, {'county': 'Jasper County, Illinois', 'fips': '17079'}, {'county': 'Jefferson County, Illinois', 'fips': '17081'}, {'county': 'Jersey County, Illinois', 'fips': '17083'}, {'county': 'Jo Daviess County, Illinois', 'fips': '17085'}, {'county': 'Johnson County, Illinois', 'fips': '17087'}, {'county': 'Kane County, Illinois', 'fips': '17089'}, {'county': 'Kankakee County, Illinois', 'fips': '17091'}, {'county': 'Kendall County, Illinois', 'fips': '17093'}, {'county': 'Knox County, Illinois', 'fips': '17095'}, {'county': 'Lake County, Illinois', 'fips': '17097'}, {'county': 'LaSalle County, Illinois', 'fips': '17099'}, {'county': 'Lawrence County, Illinois', 'fips': '17101'}, {'county': 'Lee County, Illinois', 'fips': '17103'}, {'county': 'Livingston County, Illinois', 'fips': '17105'}, {'county': 'Logan County, Illinois', 'fips': '17107'}, {'county': 'McDonough County, Illinois', 'fips': '17109'}, {'county': 'McHenry County, Illinois', 'fips': '17111'}, {'county': 'McLean County, Illinois', 'fips': '17113'}, {'county': 'Macon County, Illinois', 'fips': '17115'}, {'county': 'Macoupin County, Illinois', 'fips': '17117'}, {'county': 'Madison County, Illinois', 'fips': '17119'}, {'county': 'Marshall County, Illinois', 'fips': '17123'}, {'county': 'Mason County, Illinois', 'fips': '17125'}, {'county': 'Menard County, Illinois', 'fips': '17129'}, {'county': 'Mercer County, Illinois', 'fips': '17131'}, {'county': 'Montgomery County, Illinois', 'fips': '17135'}, {'county': 'Morgan County, Illinois', 'fips': '17137'}, {'county': 'Ogle County, Illinois', 'fips': '17141'}, {'county': 'Perry County, Illinois', 'fips': '17145'}, {'county': 'Piatt County, Illinois', 'fips': '17147'}, {'county': 'Pope County, Illinois', 'fips': '17151'}, {'county': 'Pulaski County, Illinois', 'fips': '17153'}, {'county': 'Randolph County, Illinois', 'fips': '17157'}, {'county': 'Richland County, Illinois', 'fips': '17159'}, {'county': 'St. Clair County, Illinois', 'fips': '17163'}, {'county': 'Sangamon County, Illinois', 'fips': '17167'}, {'county': 'Schuyler County, Illinois', 'fips': '17169'}, {'county': 'Shelby County, Illinois', 'fips': '17173'}, {'county': 'Stark County, Illinois', 'fips': '17175'}, {'county': 'Tazewell County, Illinois', 'fips': '17179'}, {'county': 'Union County, Illinois', 'fips': '17181'}, {'county': 'Wabash County, Illinois', 'fips': '17185'}, {'county': 'Warren County, Illinois', 'fips': '17187'}, {'county': 'Wayne County, Illinois', 'fips': '17191'}, {'county': 'Whiteside County, Illinois', 'fips': '17195'}, {'county': 'Will County, Illinois', 'fips': '17197'}, {'county': 'Winnebago County, Illinois', 'fips': '17201'}, {'county': 'Woodford County, Illinois', 'fips': '17203'}, {'county': 'Adams County, Illinois', 'fips': '17001'}, {'county': 'Bond County, Illinois', 'fips': '17005'}, {'county': 'Bureau County, Illinois', 'fips': '17011'}, {'county': 'Cass County, Illinois', 'fips': '17017'}, {'county': 'Christian County, Illinois', 'fips': '17021'}, {'county': 'Clinton County, Illinois', 'fips': '17027'}, {'county': 'Crawford County, Illinois', 'fips': '17033'}, {'county': 'De Witt County, Illinois', 'fips': '17039'}, {'county': 'DuPage County, Illinois', 'fips': '17043'}, {'county': 'Effingham County, Illinois', 'fips': '17049'}, {'county': 'Franklin County, Illinois', 'fips': '17055'}, {'county': 'Greene County, Illinois', 'fips': '17061'}, {'county': 'Hamilton County, Illinois', 'fips': '17065'}, {'county': 'Henderson County, Illinois', 'fips': '17071'}, {'county': 'Jackson County, Illinois', 'fips': '17077'}, {'county': 'Marion County, Illinois', 'fips': '17121'}, {'county': 'Massac County, Illinois', 'fips': '17127'}, {'county': 'Monroe County, Illinois', 'fips': '17133'}, {'county': 'Moultrie County, Illinois', 'fips': '17139'}, {'county': 'Peoria County, Illinois', 'fips': '17143'}, {'county': 'Pike County, Illinois', 'fips': '17149'}, {'county': 'Putnam County, Illinois', 'fips': '17155'}, {'county': 'Rock Island County, Illinois', 'fips': '17161'}, {'county': 'Saline County, Illinois', 'fips': '17165'}, {'county': 'Scott County, Illinois', 'fips': '17171'}, {'county': 'Stephenson County, Illinois', 'fips': '17177'}, {'county': 'Vermilion County, Illinois', 'fips': '17183'}, {'county': 'Washington County, Illinois', 'fips': '17189'}, {'county': 'White County, Illinois', 'fips': '17193'}, {'county': 'Williamson County, Illinois', 'fips': '17199'}]

Get FIPS code by state name and county name#

County FIPS code can be found by using the state name and county name

state = 'illinois'
county = 'champaign'
fips = NsiParser.get_fips_by_state_and_county(state, county)
print(fips)
17019

Define the NSI building inventory conversion region by FIPS#

The region is a mandatory variable when creating the building inventory data. There are three values for this: EastCoast, WestCoast, and Midwest. This region information can be bound by providing the county FIPS code

fips = '15005'
region = NsiUtil.determine_region_by_fips(fips)
print(region)
WestCoast is used to generate building inventory
WestCoast

Create building inventory by GeoJson#

You can convert the geojson downloaded from NSI site directly to the building inventory

in_json = os.path.join('nsi_test_data', 'nsi_test.json')
gdf = NsiBuildingInventory.convert_nsi_to_building_inventory_from_geojson(in_json, "westCoast")
print(gdf.head())
Total fallback occurrences: 87
Total number of records: 11940
Percentage of unmatched records: 0.73%
Total empty rows: 0
                                          fd_id                      bid  \
guid                                                                       
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe  577902630     867G4495+R8P-0-0-0-0   
a978c079-451f-45c6-a770-aa2f2d23b8d5  577568214     867F4WVW+FF8-5-8-5-9   
0b668a9c-44ac-45e6-9859-36bbf1aa727e  577568270     867F4XR4+G4H-5-5-4-4   
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee  577568798  867F4WMR+RX9-20-10-15-9   
b4298a1c-3d52-4042-a306-4632fcfc12ff  577568885     867F4XJ4+W79-3-2-3-1   

                                        occtype st_damcat bldgtype found_type  \
guid                                                                            
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe  RES1-3SNB       RES        W          S   
a978c079-451f-45c6-a770-aa2f2d23b8d5  RES1-1SNB       RES        W          C   
0b668a9c-44ac-45e6-9859-36bbf1aa727e      RES3A       RES        M          C   
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee       COM8       COM        W          S   
b4298a1c-3d52-4042-a306-4632fcfc12ff      RES3A       RES        W          C   

                                               cbfips  pop2amu65  pop2amo65  \
guid                                                                          
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe  471570096003016          1          1   
a978c079-451f-45c6-a770-aa2f2d23b8d5  471570042002006          2          0   
0b668a9c-44ac-45e6-9859-36bbf1aa727e  471570114003009         10          3   
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee  471570042002055          1          0   
b4298a1c-3d52-4042-a306-4632fcfc12ff  471570114003049         21          5   

                                      pop2pmu65  ...  ground_elv_m   fips  \
guid                                             ...                        
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe          1  ...     87.864059  47157   
a978c079-451f-45c6-a770-aa2f2d23b8d5          2  ...     80.782883  47157   
0b668a9c-44ac-45e6-9859-36bbf1aa727e          8  ...     79.753975  47157   
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee         25  ...     77.824608  47157   
b4298a1c-3d52-4042-a306-4632fcfc12ff          1  ...     76.475227  47157   

                                      statefips countyfips  \
guid                                                         
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe         47        157   
a978c079-451f-45c6-a770-aa2f2d23b8d5         47        157   
0b668a9c-44ac-45e6-9859-36bbf1aa727e         47        157   
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee         47        157   
b4298a1c-3d52-4042-a306-4632fcfc12ff         47        157   

                                                        geometry  struct_typ  \
guid                                                                           
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe  POINT (-89.89168 35.11959)          W1   
a978c079-451f-45c6-a770-aa2f2d23b8d5  POINT (-90.05380 35.14366)          W1   
0b668a9c-44ac-45e6-9859-36bbf1aa727e  POINT (-90.04464 35.14132)          W1   
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee  POINT (-90.05752 35.13455)         C2L   
b4298a1c-3d52-4042-a306-4632fcfc12ff  POINT (-90.04426 35.13229)          W1   

                                      no_stories  year_built     dgn_lvl  \
guid                                                                       
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe           3        1981  Low - Code   
a978c079-451f-45c6-a770-aa2f2d23b8d5           1        1939  Pre - Code   
0b668a9c-44ac-45e6-9859-36bbf1aa727e           1        1957  Pre - Code   
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee           1        1939  Pre - Code   
b4298a1c-3d52-4042-a306-4632fcfc12ff           1        1957  Pre - Code   

                                      exact_match  
guid                                               
94a9a3b5-3a22-4c0f-9ee4-8ac65ae830fe          Yes  
a978c079-451f-45c6-a770-aa2f2d23b8d5          Yes  
0b668a9c-44ac-45e6-9859-36bbf1aa727e          Yes  
f2d5966b-c332-485d-9c6e-9bdcc9e6f2ee          Yes  
b4298a1c-3d52-4042-a306-4632fcfc12ff          Yes  

[5 rows x 38 columns]

Create building inventory by GeoPackage#

GeoPackage data downloaded from NSI site can be directly converted to building inventory

in_gpkg = os.path.join('nsi_test_data', 'nsi_test.gpkg')
gdf = NsiBuildingInventory.convert_nsi_to_building_inventory_from_gpkg(in_gpkg, "westCoast")
print(gdf.head())
Total fallback occurrences: 87
Total number of records: 11940
Percentage of unmatched records: 0.73%
Total empty rows: 0
                                          fd_id                      bid  \
guid                                                                       
6161be42-6835-48d5-8897-798386c073e0  577902630     867G4495+R8P-0-0-0-0   
851fc011-7d86-4a97-8f68-b31dd9a613e7  577568214     867F4WVW+FF8-5-8-5-9   
b682262e-c9f7-4085-9cec-dfccf8316ca6  577568270     867F4XR4+G4H-5-5-4-4   
1adc98dc-9217-4e6f-a1fc-d1835d8831cf  577568798  867F4WMR+RX9-20-10-15-9   
dab2d50f-3d45-425f-ba2d-a6a94b6e0489  577568885     867F4XJ4+W79-3-2-3-1   

                                        occtype st_damcat bldgtype found_type  \
guid                                                                            
6161be42-6835-48d5-8897-798386c073e0  RES1-3SNB       RES        W          S   
851fc011-7d86-4a97-8f68-b31dd9a613e7  RES1-1SNB       RES        W          C   
b682262e-c9f7-4085-9cec-dfccf8316ca6      RES3A       RES        M          C   
1adc98dc-9217-4e6f-a1fc-d1835d8831cf       COM8       COM        W          S   
dab2d50f-3d45-425f-ba2d-a6a94b6e0489      RES3A       RES        W          C   

                                               cbfips  pop2amu65  pop2amo65  \
guid                                                                          
6161be42-6835-48d5-8897-798386c073e0  471570096003016          1          1   
851fc011-7d86-4a97-8f68-b31dd9a613e7  471570042002006          2          0   
b682262e-c9f7-4085-9cec-dfccf8316ca6  471570114003009         10          3   
1adc98dc-9217-4e6f-a1fc-d1835d8831cf  471570042002055          1          0   
dab2d50f-3d45-425f-ba2d-a6a94b6e0489  471570114003049         21          5   

                                      pop2pmu65  ...  ground_elv_m   fips  \
guid                                             ...                        
6161be42-6835-48d5-8897-798386c073e0          1  ...     87.864059  47157   
851fc011-7d86-4a97-8f68-b31dd9a613e7          2  ...     80.782883  47157   
b682262e-c9f7-4085-9cec-dfccf8316ca6          8  ...     79.753975  47157   
1adc98dc-9217-4e6f-a1fc-d1835d8831cf         25  ...     77.824608  47157   
dab2d50f-3d45-425f-ba2d-a6a94b6e0489          1  ...     76.475227  47157   

                                      statefips countyfips  \
guid                                                         
6161be42-6835-48d5-8897-798386c073e0         47        157   
851fc011-7d86-4a97-8f68-b31dd9a613e7         47        157   
b682262e-c9f7-4085-9cec-dfccf8316ca6         47        157   
1adc98dc-9217-4e6f-a1fc-d1835d8831cf         47        157   
dab2d50f-3d45-425f-ba2d-a6a94b6e0489         47        157   

                                                        geometry  struct_typ  \
guid                                                                           
6161be42-6835-48d5-8897-798386c073e0  POINT (-89.89168 35.11959)          W1   
851fc011-7d86-4a97-8f68-b31dd9a613e7  POINT (-90.05380 35.14366)          W1   
b682262e-c9f7-4085-9cec-dfccf8316ca6  POINT (-90.04464 35.14132)          W1   
1adc98dc-9217-4e6f-a1fc-d1835d8831cf  POINT (-90.05752 35.13455)         C2L   
dab2d50f-3d45-425f-ba2d-a6a94b6e0489  POINT (-90.04426 35.13229)          W1   

                                      no_stories  year_built     dgn_lvl  \
guid                                                                       
6161be42-6835-48d5-8897-798386c073e0           3        1981  Low - Code   
851fc011-7d86-4a97-8f68-b31dd9a613e7           1        1939  Pre - Code   
b682262e-c9f7-4085-9cec-dfccf8316ca6           1        1957  Pre - Code   
1adc98dc-9217-4e6f-a1fc-d1835d8831cf           1        1939  Pre - Code   
dab2d50f-3d45-425f-ba2d-a6a94b6e0489           1        1957  Pre - Code   

                                      exact_match  
guid                                               
6161be42-6835-48d5-8897-798386c073e0          Yes  
851fc011-7d86-4a97-8f68-b31dd9a613e7          Yes  
b682262e-c9f7-4085-9cec-dfccf8316ca6          Yes  
1adc98dc-9217-4e6f-a1fc-d1835d8831cf          Yes  
dab2d50f-3d45-425f-ba2d-a6a94b6e0489          Yes  

[5 rows x 38 columns]