docs: def build_metadata_db(
      zcta_geometry=False,
      iecc_climate_zone_geometry=True,
      iecc_moisture_regime_geometry=True,
      ba_climate_zone_geometry=True,
      ca_climate_zone_geometry=True,
  ):
      """ Build database of metadata from primary sources.
  
      Downloads primary sources, clears existing DB, and rebuilds from scratch.
  
      Parameters
      ----------
      zcta_geometry : bool, optional
          Whether or not to include ZCTA geometry in database.
      iecc_climate_zone_geometry : bool, optional
          Whether or not to include IECC Climate Zone geometry in database.
      iecc_moisture_regime_geometry : bool, optional
          Whether or not to include IECC Moisture Regime geometry in database.
      ba_climate_zone_geometry : bool, optional
          Whether or not to include Building America Climate Zone geometry in database.
      ca_climate_zone_geometry : bool, optional
          Whether or not to include California Building Climate Zone Area geometry in database.
      """
  
      try:
          import shapely
      except ImportError:
          raise ImportError("Loading polygons requires shapely.")
  
      try:
          from bs4 import BeautifulSoup
      except ImportError:
          raise ImportError("Scraping TMY3 station data requires beautifulsoup4.")
  
      try:
          import pyproj
      except ImportError:
          raise ImportError("Computing distances requires pyproj.")
  
      try:
          import simplejson
      except ImportError:
          raise ImportError("Writing geojson requires simplejson.")
  
      download_path = _download_primary_sources()
      conn = metadata_db_connection_proxy.reset_database()
  
      # Load data into memory
      print("Loading ZCTAs")
      zcta_metadata = _load_zcta_metadata(download_path)
  
      print("Loading counties")
      county_metadata = _load_county_metadata(download_path)
  
      print("Merging county climate zones")
      (
          iecc_climate_zone_metadata,
          iecc_moisture_regime_metadata,
          ba_climate_zone_metadata,
      ) = _create_merged_climate_zones_metadata(county_metadata)
  
      print("Loading CA climate zones")
      ca_climate_zone_metadata = _load_CA_climate_zone_metadata(download_path)
  
      print("Loading ISD station metadata")
      isd_station_metadata = _load_isd_station_metadata(download_path)
  
      print("Loading ISD station file metadata")
      isd_file_metadata = _load_isd_file_metadata(download_path, isd_station_metadata)
  
      print("Loading TMY3 station metadata")
      tmy3_station_metadata = _load_tmy3_station_metadata(download_path)
  
      print("Loading CZ2010 station metadata")
      cz2010_station_metadata = _load_cz2010_station_metadata()
  
      # Augment data in memory
      print("Computing ISD station quality")
      # add rough station quality to station metadata
      # (all months in last 5 years have at least 600 points)
      _compute_isd_station_quality(isd_station_metadata, isd_file_metadata)
  
      print("Mapping ZCTAs to climate zones")
      # add county and ca climate zone mappings
      _map_zcta_to_climate_zones(
          zcta_metadata,
          iecc_climate_zone_metadata,
          iecc_moisture_regime_metadata,
          ba_climate_zone_metadata,
          ca_climate_zone_metadata,
      )
  
      print("Mapping ISD stations to climate zones")
      # add county and ca climate zone mappings
      _map_isd_station_to_climate_zones(
          isd_station_metadata,
          iecc_climate_zone_metadata,
          iecc_moisture_regime_metadata,
          ba_climate_zone_metadata,
          ca_climate_zone_metadata,
      )
  
      # Write tables
      print("Creating table structures")
      _create_table_structures(conn)
  
      print("Writing ZCTA data")
      _write_zcta_metadata_table(conn, zcta_metadata, geometry=zcta_geometry)
  
      print("Writing IECC climate zone data")
      _write_iecc_climate_zone_metadata_table(
          conn, iecc_climate_zone_metadata, geometry=iecc_climate_zone_geometry
      )
  
      print("Writing IECC moisture regime data")
      _write_iecc_moisture_regime_metadata_table(
          conn, iecc_moisture_regime_metadata, geometry=iecc_moisture_regime_geometry
      )
  
      print("Writing BA climate zone data")
      _write_ba_climate_zone_metadata_table(
          conn, ba_climate_zone_metadata, geometry=ba_climate_zone_geometry
      )
  
      print("Writing CA climate zone data")
      _write_ca_climate_zone_metadata_table(
          conn, ca_climate_zone_metadata, geometry=ca_climate_zone_geometry
      )
  
      print("Writing ISD station metadata")
      _write_isd_station_metadata_table(conn, isd_station_metadata)
  
      print("Writing ISD file metadata")
      _write_isd_file_metadata_table(conn, isd_file_metadata)
  
      print("Writing TMY3 station metadata")
      _write_tmy3_station_metadata_table(conn, tmy3_station_metadata)
  
      print("Writing CZ2010 station metadata")
      _write_cz2010_station_metadata_table(conn, cz2010_station_metadata)
  
      print("Cleaning up...")
      shutil.rmtree(download_path)
  
      print("\u2728  Completed! \u2728")