-- DBMS: bigquery
CREATE TABLE `bigquery-public-data.sunroof_solar.solar_potential_by_postal_code`
(
  region_name STRING OPTIONS(description="Postal Code"),
  state_name STRING OPTIONS(description="Name of the state containing that region"),
  lat_max FLOAT64 OPTIONS(description="maximum latitude for that region"),
  lat_min FLOAT64 OPTIONS(description="minimum latitude for that region"),
  lng_max FLOAT64 OPTIONS(description="maximum longitude for that region"),
  lng_min FLOAT64 OPTIONS(description="minimum longitude for that region"),
  lat_avg FLOAT64 OPTIONS(description="average latitude for that region"),
  lng_avg FLOAT64 OPTIONS(description="average longitude for that region"),
  yearly_sunlight_kwh_kw_threshold_avg FLOAT64 OPTIONS(description="75% of the optimimum sunlight in the county containing that zip code"),
  count_qualified INT64 OPTIONS(description="# of buildings in Google Maps that are suitable for solar"),
  percent_covered FLOAT64 OPTIONS(description="% of buildings in Google Maps covered by Project Sunroof"),
  percent_qualified FLOAT64 OPTIONS(description="% of buildings covered by Project Sunroof that are suitable for solar"),
  number_of_panels_n INT64 OPTIONS(description="# of solar panels potential for north-facing roof space in that region, assuming 1.650m x 0.992m panels"),
  number_of_panels_s INT64 OPTIONS(description="# of solar panels potential for south-facing roof space in that region, assuming 1.650m x 0.992m panels"),
  number_of_panels_e INT64 OPTIONS(description="# of solar panels potential for east-facing roof space in that region, assuming 1.650m x 0.992m panels"),
  number_of_panels_w INT64 OPTIONS(description="# of solar panels potential for west-facing roof space in that region, assuming 1.650m x 0.992m panels"),
  number_of_panels_f INT64 OPTIONS(description="# of solar panels potential for flat roof space in that region, assuming 1.650m x 0.992m panels"),
  number_of_panels_median INT64 OPTIONS(description="# of panels that fit on the median roof"),
  number_of_panels_total INT64 OPTIONS(description="# of solar panels potential for all roof space in that region, assuming 1.650m 0.992m panels"),
  kw_median FLOAT64 OPTIONS(description="kW of solar potential for the median building in that region (assuming 250 watts per panel)"),
  kw_total FLOAT64 OPTIONS(description="# of kW of solar potential for all roof types in that region (assuming 250 watts per panel)"),
  yearly_sunlight_kwh_n FLOAT64 OPTIONS(description="total solar energy generation potential for north-facing roof space in that region"),
  yearly_sunlight_kwh_s FLOAT64 OPTIONS(description="total solar energy generation potential for south-facing roof space in that region"),
  yearly_sunlight_kwh_e FLOAT64 OPTIONS(description="total solar energy generation potential for east-facing roof space in that region"),
  yearly_sunlight_kwh_w FLOAT64 OPTIONS(description="total solar energy generation potential for west-facing roof space in that region"),
  yearly_sunlight_kwh_f FLOAT64 OPTIONS(description="total solar energy generation potential for flat roof space in that region"),
  yearly_sunlight_kwh_median FLOAT64 OPTIONS(description="kWh/kw/yr for the median roof, in DC (not AC) terms"),
  yearly_sunlight_kwh_total FLOAT64 OPTIONS(description="total solar energy generation potential for all roof space in that region"),
  install_size_kw_buckets STRING OPTIONS(description="# of buildings with potential for various installation size buckets. Format is a JSON array, where each element is a tuple containing (1) lower bound of bucket, in kW, and (2) number of buildings in that bucket."),
  carbon_offset_metric_tons FLOAT64 OPTIONS(description="The potential carbon dioxide abatement of the solar capacity that meets the technical potential criteria. The calculation uses eGRID subregion CO2 equivalent non-baseload output emission rates. https://www.epa.gov/sites/production/files/2015-10/documents/egrid2012_summarytables_0.pdf"),
  existing_installs_count INT64 OPTIONS(description="# of buildings estimated to have a solar installation, at time of data collection"),
  center_point GEOGRAPHY
)
OPTIONS(
  description="Sunroof Solar Potential By Postal Code"
);

INSERT INTO `bigquery-public-data.sunroof_solar.solar_potential_by_postal_code` (region_name, state_name, lat_max, lat_min, lng_max, lng_min, lat_avg, lng_avg, yearly_sunlight_kwh_kw_threshold_avg, count_qualified, percent_covered, percent_qualified, number_of_panels_n, number_of_panels_s, number_of_panels_e, number_of_panels_w, number_of_panels_f, number_of_panels_median, number_of_panels_total, kw_median, kw_total, yearly_sunlight_kwh_n, yearly_sunlight_kwh_s, yearly_sunlight_kwh_e, yearly_sunlight_kwh_w, yearly_sunlight_kwh_f, yearly_sunlight_kwh_median, yearly_sunlight_kwh_total, install_size_kw_buckets, carbon_offset_metric_tons, existing_installs_count, center_point) VALUES ('19149', 'Pennsylvania', 40.0512295, 40.0268795, -75.0413555, -75.0925965, 40.03740444034173, -75.06570517465477, 997.9, 4602, 90.10262747837301, 27.44349692885682, 3408, 5878, 5145, 3187, 146724, 11, 164342, 2.75, 41085.5, 903130.3143676757, 1850868.9417785641, 1576590.637451172, 858083.7263000489, 43827579.56188964, 3332.078649902344, 49016253.18178705, '[[0,3888],[5,430],[10,80],[15,39],[20,24],[25,12],[30,7],[35,14],[40,7],[45,8],[50,3],[55,5],[60,6],[65,7],[70,1],[75,7],[80,2],[85,1],[90,4],[95,2],[100,4],[105,2],[110,1],[120,1],[125,3],[130,1],[135,1],[140,2],[145,1],[155,1],[160,2],[165,2],[190,2],[195,1],[220,1],[240,1],[285,2],[290,2],[300,1],[305,1],[320,1],[330,1],[340,1],[380,1],[385,1],[430,1],[445,1],[460,1],[475,1],[560,2],[565,1],[570,1],[575,1],[640,1],[735,1],[750,1],[830,1],[875,1],[1070,1],[1240,1],[1305,1],[1320,1]]', 31147.899202816374, 3, 'POINT(-75.0657051746548 40.0374044403417)'), ('19120', 'Pennsylvania', 40.0527086, 40.0124032, -75.0969875, -75.1387471, 40.034398293281114, -75.12088724350596, 997.9, 6086, 89.83364996988091, 31.392170010832, 7557, 16061, 12854, 10272, 216962, 12, 263706, 3.0, 65926.5, 1950522.665570069, 5073438.2647094745, 3776295.318957522, 2820022.264160157, 64645035.345489465, 3572.8123046875, 78265313.85888669, '[[0,4877],[5,722],[10,107],[15,67],[20,40],[25,37],[30,34],[35,18],[40,14],[45,11],[50,11],[55,8],[60,7],[65,9],[70,9],[75,5],[80,5],[85,6],[90,4],[95,5],[100,7],[105,3],[110,4],[115,1],[120,5],[125,5],[130,2],[135,1],[140,2],[145,3],[150,2],[155,3],[160,3],[165,1],[175,2],[180,3],[185,1],[190,1],[195,2],[200,1],[220,1],[230,1],[235,1],[240,3],[255,2],[265,1],[295,1],[300,2],[315,1],[320,2],[345,1],[350,1],[365,1],[385,1],[410,1],[415,1],[435,1],[445,1],[755,1],[810,1],[815,1],[820,1],[865,1],[960,1],[1110,1],[1140,1],[1180,1],[1230,1],[1300,1],[1345,1],[1995,1],[2220,1],[4045,1]]', 49734.52577275326, 2, 'POINT(-75.120887243506 40.0343982932811)'), ('19132', 'Pennsylvania', 40.0058933, 39.9863578, -75.1506389, -75.1906974, 39.995681490757846, -75.16964515924501, 997.9, 5157, 88.18197464287763, 33.55019191984907, 4664, 13486, 9191, 8378, 174776, 12, 210495, 3.0, 52623.75, 1198443.5034301754, 4355742.144921876, 2644355.2062500007, 2354783.737200928, 51760215.24395752, 3379.915637207031, 62313539.835760504, '[[0,4250],[5,463],[10,78],[15,68],[20,37],[25,24],[30,22],[35,23],[40,18],[45,16],[50,12],[55,9],[60,14],[65,6],[70,7],[75,5],[80,4],[85,6],[90,7],[100,7],[105,2],[110,2],[115,2],[120,5],[125,3],[130,1],[135,3],[140,2],[150,2],[155,1],[160,3],[165,3],[170,2],[180,3],[185,1],[195,4],[200,1],[215,2],[235,1],[245,1],[250,1],[255,2],[260,1],[270,1],[285,3],[305,1],[315,1],[325,1],[355,1],[360,1],[375,2],[390,1],[400,1],[445,2],[450,2],[460,1],[470,1],[475,1],[480,1],[510,2],[525,1],[610,1],[680,1],[730,1],[790,1],[840,1],[845,1],[890,1],[1080,1],[1465,1]]', 39597.80137777116, 0, 'POINT(-75.169645159245 39.9956814907579)'), ('19134', 'Pennsylvania', 40.0073335, 39.977417, -75.0872131, -75.1310049, 39.992451062913055, -75.1119347717865, 997.9, 7551, 90.75466914560974, 35.15690473973368, 10910, 23038, 14457, 17419, 378488, 12, 444312, 3.0, 111078.0, 2835591.965725709, 7368521.89238281, 3994669.8953613285, 5198415.904962159, 113110773.37730098, 3582.464453125, 132507973.03573295, '[[0,5795],[5,831],[10,179],[15,117],[20,87],[25,61],[30,50],[35,35],[40,32],[45,31],[50,27],[55,23],[60,19],[65,19],[70,10],[75,16],[80,11],[85,6],[90,6],[95,12],[100,3],[105,10],[110,7],[115,9],[120,2],[125,6],[130,7],[135,5],[140,8],[145,2],[155,2],[160,3],[165,2],[170,3],[175,2],[180,1],[185,3],[190,3],[195,1],[200,2],[205,1],[210,1],[215,4],[220,6],[225,4],[230,1],[235,5],[240,2],[245,4],[260,1],[270,1],[275,2],[280,2],[285,1],[290,1],[295,3],[300,2],[305,1],[310,1],[315,3],[320,2],[340,2],[360,3],[395,1],[420,1],[430,2],[440,1],[445,3],[455,1],[465,1],[480,1],[490,1],[495,1],[505,1],[520,1],[545,1],[565,1],[570,1],[585,1],[600,1],[615,2],[635,1],[670,1],[675,2],[685,1],[700,1],[710,1],[720,1],[730,1],[740,1],[745,1],[785,1],[825,1],[900,1],[1035,1],[1040,1],[1075,1],[1085,1],[1105,2],[1205,1],[1245,1],[1310,1],[1365,1],[1450,1],[1705,1],[1880,1],[2300,1]]', 84203.60022989493, 3, 'POINT(-75.1119347717865 39.9924510629131)'), ('19138', 'Pennsylvania', 40.0714515, 40.0399482, -75.1470133, -75.176449, 40.056626771542405, -75.15694927825842, 997.9, 4256, 93.05634604439385, 37.186544342507645, 2417, 6650, 5865, 2916, 100013, 12, 117861, 3.0, 29465.25, 632613.0408996582, 2038110.6297119139, 1696291.3066040033, 820237.5260009766, 29609031.535632323, 3545.397314453125, 34796284.038848825, '[[0,3505],[5,529],[10,57],[15,29],[20,12],[25,16],[30,7],[35,8],[40,7],[45,10],[50,7],[55,7],[60,4],[65,5],[70,4],[75,3],[80,4],[85,3],[90,5],[95,4],[115,4],[125,2],[130,2],[140,1],[150,1],[165,1],[170,1],[185,1],[195,1],[210,1],[235,1],[240,1],[255,1],[265,1],[275,1],[285,1],[335,1],[355,1],[400,1],[485,1],[505,1],[630,1],[715,1],[780,1],[1445,1]]', 22111.668630709424, 3, 'POINT(-75.1569492782584 40.0566267715424)');