us_geo 1.0.3 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/MIT_LICENSE.txt +21 -0
  4. data/README.md +77 -60
  5. data/UPDATING_TO_VERSION_2.md +172 -0
  6. data/VERSION +1 -0
  7. data/db/migrate/20190221054200_create_regions.rb +4 -2
  8. data/db/migrate/20190221054300_create_divisions.rb +4 -2
  9. data/db/migrate/20190221054400_create_states.rb +4 -2
  10. data/db/migrate/20190221054500_create_combined_statistical_areas.rb +4 -2
  11. data/db/migrate/20190221054600_create_core_based_statistical_areas.rb +4 -2
  12. data/db/migrate/20190221054650_create_metropolitan_divisions.rb +4 -2
  13. data/db/migrate/20190221054700_create_counties.rb +4 -3
  14. data/db/migrate/20190221054800_create_zctas.rb +4 -2
  15. data/db/migrate/20190221054900_create_zcta_counties.rb +4 -2
  16. data/db/migrate/20190221055000_create_urban_areas.rb +4 -2
  17. data/db/migrate/20190221055100_create_urban_area_counties.rb +4 -4
  18. data/db/migrate/20190221055200_create_zcta_urban_areas.rb +4 -4
  19. data/db/migrate/20190221060000_create_places.rb +4 -2
  20. data/db/migrate/20190221061000_create_place_counties.rb +4 -2
  21. data/db/migrate/20190221062000_create_zcta_places.rb +4 -4
  22. data/db/migrate/20190221063000_create_county_subdivisions.rb +4 -2
  23. data/db/migrate/20220722000000_allow_null_zcta_counties_demographics.rb +23 -0
  24. data/db/migrate/20220722000200_allow_null_zcta_places_demographics.rb +23 -0
  25. data/db/migrate/20230414000000_add_zcta_primary_place.rb +13 -0
  26. data/db/migrate/20230414000200_add_demographics_to_regions.rb +28 -0
  27. data/db/migrate/20230414000300_add_demographics_to_divisions.rb +28 -0
  28. data/db/migrate/20230414000400_add_demographics_to_states.rb +28 -0
  29. data/db/migrate/20230414000700_add_short_name_to_core_based_statistical_areas.rb +22 -0
  30. data/db/migrate/20230414000750_add_short_name_to_combined_statistical_areas.rb +22 -0
  31. data/db/migrate/20230414000800_create_zcta_mappings.rb +18 -0
  32. data/db/migrate/20230417000100_create_zcta_county_subdivisions.rb +22 -0
  33. data/db/migrate/20230417000200_add_unique_name_index_to_county_subdivisions.rb +26 -0
  34. data/db/migrate/20230417000250_add_zcta_primary_county_subdivision.rb +13 -0
  35. data/db/migrate/20230417000300_create_urban_area_county_subdivisions.rb +23 -0
  36. data/db/migrate/20230417000400_allow_null_urban_area_counties_demographics.rb +23 -0
  37. data/db/migrate/20230417000500_allow_null_zcta_urban_areas_demographics.rb +23 -0
  38. data/db/migrate/20230417000600_add_additional_time_zone_name_to_counties.rb +13 -0
  39. data/db/migrate/20230426000100_add_index_on_zctas_geoids.rb +18 -0
  40. data/db/schema.rb +303 -0
  41. data/explorer_app/.gitattributes +7 -0
  42. data/explorer_app/.gitignore +34 -0
  43. data/explorer_app/Gemfile +38 -0
  44. data/explorer_app/Rakefile +6 -0
  45. data/explorer_app/app/assets/images/.keep +0 -0
  46. data/explorer_app/app/assets/stylesheets/application.css +1 -0
  47. data/explorer_app/app/controllers/application_controller.rb +64 -0
  48. data/explorer_app/app/controllers/combined_statistical_areas_controller.rb +12 -0
  49. data/explorer_app/app/controllers/concerns/.keep +0 -0
  50. data/explorer_app/app/controllers/core_based_statistical_areas_controller.rb +36 -0
  51. data/explorer_app/app/controllers/counties_controller.rb +22 -0
  52. data/explorer_app/app/controllers/county_subdivisions_controller.rb +23 -0
  53. data/explorer_app/app/controllers/divisions_controller.rb +27 -0
  54. data/explorer_app/app/controllers/home_controller.rb +6 -0
  55. data/explorer_app/app/controllers/metropolitan_divisions_controller.rb +27 -0
  56. data/explorer_app/app/controllers/places_controller.rb +23 -0
  57. data/explorer_app/app/controllers/regions_controller.rb +13 -0
  58. data/explorer_app/app/controllers/states_controller.rb +25 -0
  59. data/explorer_app/app/controllers/urban_areas_controller.rb +24 -0
  60. data/explorer_app/app/controllers/zctas_controller.rb +23 -0
  61. data/explorer_app/app/helpers/application_helper.rb +137 -0
  62. data/explorer_app/app/models/application_record.rb +3 -0
  63. data/explorer_app/app/models/concerns/.keep +0 -0
  64. data/explorer_app/app/views/combined_statistical_areas/_table.html.erb +18 -0
  65. data/explorer_app/app/views/combined_statistical_areas/index.html.erb +7 -0
  66. data/explorer_app/app/views/combined_statistical_areas/show.html.erb +52 -0
  67. data/explorer_app/app/views/core_based_statistical_areas/_table.html.erb +32 -0
  68. data/explorer_app/app/views/core_based_statistical_areas/index.html.erb +19 -0
  69. data/explorer_app/app/views/core_based_statistical_areas/show.html.erb +60 -0
  70. data/explorer_app/app/views/counties/_table.html.erb +64 -0
  71. data/explorer_app/app/views/counties/show.html.erb +96 -0
  72. data/explorer_app/app/views/county_subdivisions/_table.html.erb +48 -0
  73. data/explorer_app/app/views/county_subdivisions/show.html.erb +84 -0
  74. data/explorer_app/app/views/divisions/_table.html.erb +24 -0
  75. data/explorer_app/app/views/divisions/index.html.erb +3 -0
  76. data/explorer_app/app/views/divisions/show.html.erb +3 -0
  77. data/explorer_app/app/views/home/index.html.erb +23 -0
  78. data/explorer_app/app/views/layouts/application.html.erb +34 -0
  79. data/explorer_app/app/views/metropolitan_divisions/_table.html.erb +42 -0
  80. data/explorer_app/app/views/metropolitan_divisions/index.html.erb +8 -0
  81. data/explorer_app/app/views/metropolitan_divisions/show.html.erb +46 -0
  82. data/explorer_app/app/views/places/_table.html.erb +47 -0
  83. data/explorer_app/app/views/places/show.html.erb +92 -0
  84. data/explorer_app/app/views/regions/_table.html.erb +18 -0
  85. data/explorer_app/app/views/regions/index.html.erb +7 -0
  86. data/explorer_app/app/views/regions/show.html.erb +3 -0
  87. data/explorer_app/app/views/shared/_breadcrumbs.html.erb +13 -0
  88. data/explorer_app/app/views/shared/_demographics_cells.html.erb +5 -0
  89. data/explorer_app/app/views/shared/_demographics_headers.html.erb +5 -0
  90. data/explorer_app/app/views/states/_table.html.erb +31 -0
  91. data/explorer_app/app/views/states/index.html.erb +7 -0
  92. data/explorer_app/app/views/states/show.html.erb +54 -0
  93. data/explorer_app/app/views/urban_areas/_table.html.erb +45 -0
  94. data/explorer_app/app/views/urban_areas/index.html.erb +19 -0
  95. data/explorer_app/app/views/urban_areas/show.html.erb +68 -0
  96. data/explorer_app/app/views/zctas/_table.html.erb +60 -0
  97. data/explorer_app/app/views/zctas/show.html.erb +104 -0
  98. data/explorer_app/bin/bundle +109 -0
  99. data/explorer_app/bin/rails +4 -0
  100. data/explorer_app/bin/rake +4 -0
  101. data/explorer_app/bin/setup +33 -0
  102. data/explorer_app/config/application.rb +37 -0
  103. data/explorer_app/config/boot.rb +3 -0
  104. data/explorer_app/config/database.yml +13 -0
  105. data/explorer_app/config/environment.rb +5 -0
  106. data/explorer_app/config/environments/development.rb +59 -0
  107. data/explorer_app/config/initializers/filter_parameter_logging.rb +8 -0
  108. data/explorer_app/config/locales/en.yml +2 -0
  109. data/explorer_app/config/puma.rb +43 -0
  110. data/explorer_app/config/routes.rb +56 -0
  111. data/explorer_app/config.ru +6 -0
  112. data/explorer_app/db/seeds.rb +7 -0
  113. data/explorer_app/lib/assets/.keep +0 -0
  114. data/explorer_app/lib/tasks/.keep +0 -0
  115. data/explorer_app/log/.keep +0 -0
  116. data/explorer_app/public/404.html +67 -0
  117. data/explorer_app/public/422.html +67 -0
  118. data/explorer_app/public/500.html +66 -0
  119. data/explorer_app/public/apple-touch-icon-precomposed.png +0 -0
  120. data/explorer_app/public/apple-touch-icon.png +0 -0
  121. data/explorer_app/public/favicon.ico +0 -0
  122. data/explorer_app/public/robots.txt +1 -0
  123. data/explorer_app/tmp/.keep +0 -0
  124. data/explorer_app/tmp/pids/.keep +0 -0
  125. data/lib/tasks/us_geo/us_geo.rake +44 -3
  126. data/lib/us_geo/area.rb +44 -0
  127. data/lib/us_geo/base_record.rb +22 -16
  128. data/lib/us_geo/combined_statistical_area.rb +18 -8
  129. data/lib/us_geo/core_based_statistical_area.rb +24 -12
  130. data/lib/us_geo/county.rb +67 -16
  131. data/lib/us_geo/county_subdivision.rb +43 -7
  132. data/lib/us_geo/division.rb +17 -7
  133. data/lib/us_geo/metropolitan_area.rb +1 -5
  134. data/lib/us_geo/metropolitan_division.rb +17 -9
  135. data/lib/us_geo/micropolitan_area.rb +1 -5
  136. data/lib/us_geo/place.rb +61 -11
  137. data/lib/us_geo/place_county.rb +1 -4
  138. data/lib/us_geo/population.rb +26 -0
  139. data/lib/us_geo/region.rb +18 -8
  140. data/lib/us_geo/state.rb +32 -11
  141. data/lib/us_geo/urban_area.rb +46 -16
  142. data/lib/us_geo/urban_area_county.rb +4 -21
  143. data/lib/us_geo/urban_area_county_subdivision.rb +51 -0
  144. data/lib/us_geo/urban_cluster.rb +1 -5
  145. data/lib/us_geo/urbanized_area.rb +1 -5
  146. data/lib/us_geo/version.rb +1 -1
  147. data/lib/us_geo/zcta.rb +90 -13
  148. data/lib/us_geo/zcta_county.rb +5 -22
  149. data/lib/us_geo/zcta_county_subdivision.rb +51 -0
  150. data/lib/us_geo/zcta_mapping.rb +35 -0
  151. data/lib/us_geo/zcta_place.rb +5 -12
  152. data/lib/us_geo/zcta_urban_area.rb +3 -20
  153. data/lib/us_geo.rb +34 -31
  154. data/us_geo.gemspec +36 -0
  155. metadata +126 -129
  156. data/Gemfile +0 -5
  157. data/Gemfile.lock +0 -75
  158. data/Rakefile +0 -18
  159. data/db/migrate/20190221054490_create_designated_market_areas.rb +0 -16
  160. data/lib/us_geo/demographics.rb +0 -25
  161. data/lib/us_geo/designated_market_area.rb +0 -30
  162. data/spec/spec_helper.rb +0 -22
  163. data/spec/us_geo/base_record_spec.rb +0 -67
  164. data/spec/us_geo/combined_statistical_area_spec.rb +0 -33
  165. data/spec/us_geo/core_based_statistical_area_spec.rb +0 -56
  166. data/spec/us_geo/county_spec.rb +0 -131
  167. data/spec/us_geo/county_subdivision_spec.rb +0 -37
  168. data/spec/us_geo/demographics_spec.rb +0 -19
  169. data/spec/us_geo/designated_market_area_spec.rb +0 -29
  170. data/spec/us_geo/division_spec.rb +0 -37
  171. data/spec/us_geo/metropolitan_division_spec.rb +0 -41
  172. data/spec/us_geo/place_county_spec.rb +0 -39
  173. data/spec/us_geo/place_spec.rb +0 -71
  174. data/spec/us_geo/region_spec.rb +0 -36
  175. data/spec/us_geo/state_spec.rb +0 -70
  176. data/spec/us_geo/urban_area_county_spec.rb +0 -82
  177. data/spec/us_geo/urban_area_spec.rb +0 -98
  178. data/spec/us_geo/zcta_county_spec.rb +0 -82
  179. data/spec/us_geo/zcta_place_spec.rb +0 -82
  180. data/spec/us_geo/zcta_spec.rb +0 -99
  181. data/spec/us_geo/zcta_urban_area_spec.rb +0 -82
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1558db467c74232d766fbb9f54b31549d75e7891509ac4d9c12f4c1be213ec89
4
- data.tar.gz: 516c03eca942611fe80a47e556efc7d201f8cdca829d82465bf1a326da8e5bdb
3
+ metadata.gz: 73084a715b73e960f52bf49b61e83d9bf68814a95a5ba9a6c702e721f9fe4c14
4
+ data.tar.gz: 3e525d12df7a407afdfd67116a1f54f8c17de9def115a433fb0678b215267eff
5
5
  SHA512:
6
- metadata.gz: da1ce0e7b45bc892cfffb8990703e2369468676698b23b5dcf0f870949e9e9d9ec411d0ed9c04893cf828f5d97dd981c7f8dc30c9479cf02b78965191b4cc110
7
- data.tar.gz: eb911802a12dd31b41cf48c7f43ce8bc44e714e9d996b72327414ba2758ad600586576fcf4720c36a2f0af6b8bf5e5dfca28660dce86dbdd897d9cedd8a468c1
6
+ metadata.gz: 4a2c90967678930d21c7c3560d785a4fb8551f71cf017f1e9a8ef975f637bb215b3ef90376140a67cdbd6740f1ae4206407f7da25ef027804d8b788a525c73b8
7
+ data.tar.gz: e1ec086a0af3dff1ad76af089caa510af3175f2b82f5afa6489752bd562dbb6662cc374cd6b55a0ec6392f3e289318c93387b2a6b9b0b684fe15e2422a2955e5
data/CHANGELOG.md ADDED
@@ -0,0 +1,88 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 2.0.1
8
+
9
+ ### Added
10
+
11
+ - Indexes on `us_geo_zctas` on `primary_place_geoid` and on `primary_county_subdivision_geoid`.
12
+
13
+ ## 2.0.0
14
+
15
+ ### Changed
16
+
17
+ - Data is now based on the 2020 U.S. Census
18
+ * ZCTAs have been both added and removed
19
+ * Places have been both added and removed
20
+ * Some counties and subdivisions have been renamed
21
+ * A number of smaller urban areas have been removed
22
+ * Former U.S. territories (Micronesia, Palau, and Marshall Islands) have been removed
23
+
24
+ - Population and housing unit numbers are now based on the 2021 [American Community Survey Five Year Estimates](https://www.census.gov/programs-surveys/acs).
25
+
26
+ - Entities that are legally independent of other county subdivisions are included as both county subdivisions and places.
27
+
28
+ - Areas in the CSV data files are now in square miles instead of square meters to match the data after it is imported into a database.
29
+
30
+ ### Added
31
+
32
+ - ZCTA's are now associated with a primary place defined as the place with the most overlapping land area with the ZCTA.
33
+
34
+ - ZCTAS's are now associated with county subdivisions and have a primary county subdivision which is the one with the moste land area overlapping the ZCTA.
35
+
36
+ - 2010 ZCTAs can still be used to lookup the active ZCTA through the ZCTAMapping model.
37
+
38
+ - Core Based Statistical Areas and Combined Statistical Areas now have a short name which is the name of just the largest city in the area. This makes them a little easier to refer to by name.
39
+
40
+ - All Geographic entity models now have land area, water area, population, and housing units columns.
41
+
42
+ - Urban Areas are now associated with county subdivisions.
43
+
44
+ - Counties can now have multiple time zones. You can still call `time_zone` to get a single time zone for a county, but it is more accurate to call `time_zones` instead. There are only a handful of counties that span time zones and none are heavily populated (the largest is Coconino County, AZ with 145K people).
45
+
46
+ ### Removed
47
+
48
+ - The Designated Market Area model has been removed. This data was a crude mapping from counties to DMA's and was not accurate since it didn't respect the actual borders. The table and foreign keys to it will not be removed if they are already in your database. See the [updating guide](UPDATING_TO_VERSION_2.md) form more details.
49
+
50
+ - Population and housing unit data has been removed from the overlap models used to join entities (i.e. `ZctaCounty`, `ZctaPlace`, `PlaceCounty`). This information is no longer available directly from the Census relationship files. Only the overlapping land and water area is now available.
51
+
52
+ - The `USGeo::Demographics` module has been removed. The functionality is split into `USGeo::Area` and `USGeo::Population`.
53
+
54
+ - Dropped support for ActiveRecord 5.0 and 5.1
55
+
56
+ - Dropped support for Ruby 2.5.
57
+
58
+ ### Fixed
59
+
60
+ - Fixed arithmetic for converting area from square miles to kilometers.
61
+
62
+ ## 1.0.3
63
+
64
+ ### Added
65
+
66
+ - Make dependencies compatible with Rails 6
67
+
68
+ ## 1.0.2
69
+
70
+ ### Added
71
+
72
+ - Add missing metropolitan division codes to counties
73
+
74
+ ### Changed
75
+
76
+ - Fix short name logic to be more conservative in how it shortens names
77
+
78
+ ## 1.0.1
79
+
80
+ ### Changed
81
+
82
+ - Fix logic to enforce place short name limit on databases that don't have character limits.
83
+
84
+ ## 1.0.0
85
+
86
+ ### Added
87
+
88
+ - Initial release
data/MIT_LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Brian Durand
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,50 +1,57 @@
1
1
  # USGeo
2
2
 
3
3
  [![Build Status](https://travis-ci.com/bdurand/us_geo.svg?branch=master)](https://travis-ci.com/bdurand/us_geo)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/a01ffc7f707686416c0d/maintainability)](https://codeclimate.com/github/bdurand/us_geo/maintainability)
4
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
5
5
 
6
- This gem provides a variety of U.S. geographic data ActiveRecord models. It is designed to provide a normalized way to access the data from a relational database. This is by no means a complete set of data. The primary purpose it was built is to provide a way to match most ZIP codes to higher level geographic entities.
6
+ This gem provides a variety of U.S. geographic data ActiveRecord models. It is designed to provide a normalized way to access the data from a relational database. This is by no means a complete set of data.
7
+
8
+ The primary purpose it was built for is to provide a way to match ZIP codes to higher level geographic entities.
9
+
10
+ You can use the data from this gem in non-Ruby probjects. The data is provided as [CSV files](./data/2020_dist/) which you can import into any database or spreadsheet. You can see the database structure in the [schema.rb file](./db/schema.rb).
7
11
 
8
12
  ## Entities
9
13
 
10
- All of the entities except for DMA are defined by the U.S. Census Bureau. For more details.
14
+ All of the entities are defined by the U.S. Census Bureau. For more details.
11
15
 
12
16
  https://www2.census.gov/geo/pdfs/reference/geodiagram.pdf
13
17
  https://www2.census.gov/geo/pdfs/reference/GARM/Ch2GARM.pdf
14
18
 
15
- All entities in the system are keyed using external identifier.
19
+ [![](https://mermaid.ink/img/pako:eNqFVEFuwjAQ_IrlM_kAQpVa0iNS1YhLlcvGXqglx0a2U4lS_t7EDlESlpALZmZ2s5qd-MKFlcjXXGjwPldwdFCXhrVPRNgnHpU1pRljufpR_g4tAgRkU2xrGxPOFFY0lSTbfIkAU-RDg8B5D4dv4FF2L1U-KAH61SHMVXWlzBPRDoOzJ6tVAEOwSiyxo1ralL2rqMIIq1-UD6itbnxAd2M6T9gmy14GQyl0YulU0FvYgfHIxr0SnhYdiXzS5fYvUnHJCU_7ng-VzuzBVEkzt5xt_rJsYaexZraIpzW3ccgI9PMtvfARS1hHxYAwZqHfUpCGCKVVpu-DIEY7njHjMUiK2NEkocnsUZYHRR_UOwFf8RpdDUq2d8ulKyh5-MYaS75ujxIP0OhQ8tJcW2lzkm2W3qUK1vH1AbTHFYcm2OJsxAAkVX9HDSjGql1_i3U_13-31qQd?type=png)](https://mermaid.live/edit#pako:eNqFVEFuwjAQ_IrlM_kAQpVa0iNS1YhLlcvGXqglx0a2U4lS_t7EDlESlpALZmZ2s5qd-MKFlcjXXGjwPldwdFCXhrVPRNgnHpU1pRljufpR_g4tAgRkU2xrGxPOFFY0lSTbfIkAU-RDg8B5D4dv4FF2L1U-KAH61SHMVXWlzBPRDoOzJ6tVAEOwSiyxo1ralL2rqMIIq1-UD6itbnxAd2M6T9gmy14GQyl0YulU0FvYgfHIxr0SnhYdiXzS5fYvUnHJCU_7ng-VzuzBVEkzt5xt_rJsYaexZraIpzW3ccgI9PMtvfARS1hHxYAwZqHfUpCGCKVVpu-DIEY7njHjMUiK2NEkocnsUZYHRR_UOwFf8RpdDUq2d8ulKyh5-MYaS75ujxIP0OhQ8tJcW2lzkm2W3qUK1vH1AbTHFYcm2OJsxAAkVX9HDSjGql1_i3U_13-31qQd)
20
+
21
+ All entities in the system are keyed using external identifiers.
16
22
 
17
- * The various `geoid` columns reference the id used by the U.S. Census Bureau.
23
+ * The various `geoid` columns reference the id used by the [U.S. Census Bureau](https://www.census.gov/programs-surveys/geography/guidance/geo-identifiers.html).
18
24
 
19
- * The `gnis_id` columns are the official ID's assigned by the U.S. Board on Geographic Names https://geonames.usgs.gov.
25
+ * The `gnis_id` columns are the official ID's assigned by the [U.S. Board on Geographic Names](https://geonames.usgs.gov).
20
26
 
21
27
 
22
28
  There are no foreign key constraints defined on the tables. This is intentional so that you can only import as much data as you need if you don't need the whole set.
23
29
 
24
- The data set currently contains
30
+ The data set currently contains:
25
31
 
26
32
  * 4 Regions
27
33
  * 9 Divisions
28
- * 59 States and Territories
29
- * 210 Designated Market Areas
34
+ * 56 States and Territories
30
35
  * 175 Combined Statistical Areas
31
- * 938 Core Based Statistical Areas
36
+ * 939 Core Based Statistical Areas
32
37
  * 31 Metropolitan Divisions
33
- * 3223 Counties or equivalents
34
- * 36429 County Subdivisions
35
- * 3601 Urban Areas
36
- * 30187 Places
37
- * 33120 ZIP Code Tabulation Areas
38
+ * 3234 Counties or equivalents
39
+ * 35,657 County Subdivisions
40
+ * 2,313 Urban Areas
41
+ * 31,846 Places
42
+ * 33,791 ZIP Code Tabulation Areas
38
43
 
39
- In addition, there entity to entity mapping tables:
44
+ The population, number of housing units, land area, and water area is supplied for all geographic entities.
40
45
 
41
- * 44388 ZCTA to County
42
- * 17389 ZCTA to Urban Area
43
- * 49843 ZCTA to Place
44
- * 4945 Urban Area to County
45
- * 31492 Place to County
46
+ In addition, there entity to entity mapping tables containing information about how entities overlap with each other:
46
47
 
47
- The land and water area for all entities is given in square miles.
48
+ * 46,953 ZCTA to County
49
+ * 109,549 ZCTA to County Subdivision
50
+ * 14,455 ZCTA to Urban Area
51
+ * 53,131 ZCTA to Place
52
+ * 33,276 Place to County
53
+ * 33,09 County to Urban Area
54
+ * 11,755 County Subdivison to Urban Area
48
55
 
49
56
  ### Region
50
57
 
@@ -56,29 +63,23 @@ A grouping of states within a region.
56
63
 
57
64
  ### State
58
65
 
59
- Includes both states and territories and the District of Columbia.
66
+ Includes both states, territories, and the District of Columbia.
60
67
 
61
- ### Designated Market Area (DMA)
68
+ ### Core Based Statistical Area (CBSA)
62
69
 
63
- Media marketing areas of counties served by the same over the air radio and television signals. DMA's are not official government designations and are defined by the Nielsen Company.
70
+ A grouping of counties around an urban core defined by commuting patterns. CBSA's are split into metropolitan (population > 50,000) and micropolitan areas. Counties within a CBSA are either identified as being core or outlyer counties. Not all counties belong to a CBSA.
64
71
 
65
72
  ### Combined Statistical Areas
66
73
 
67
74
  Groupings of adjacent CBSA's with regional ties to each other.
68
75
 
69
- ### Core Based Statistical Area (CBSA)
70
-
71
- A grouping of counties around an urban core defined by commuting patterns. CBSA's are split into metropolitan (population > 50,000) and micropolitan areas. Counties within a CBSA are either identified as being core or outlyer counties. Not all counties belong to a CBSA.
72
-
73
76
  ### Metropolitan Division
74
77
 
75
- The largest CBSAs (New York, Chicago, etc.) are split into metropolitan divisions.
78
+ The largest CBSAs (New York, Chicago, etc.) are further split into metropolitan divisions based around the largest regional cities.
76
79
 
77
80
  ### County (or county equivalent)
78
81
 
79
- Basic organizational unit of states and territories. The actual name of the unit can vary depending on the state (i.e. parishes is Louisiana).
80
-
81
- County data is only provided for states, the District of Columbia, Puerto Rico. It is not provided for other U.S. territories.
82
+ Basic organizational unit of states and territories. The actual name of the unit can vary depending on the state (i.e. parishes is Louisiana). This also includes cities that are independent of any county.
82
83
 
83
84
  ### County Subdivision
84
85
 
@@ -88,59 +89,61 @@ Subdivision of counties. These could be minor civil divisions like townships or
88
89
 
89
90
  Urbanized areas or clusters. Areas with 2,500 to 50,000 inhabitants is considered an urban cluster while more than 50,000 is an urbanized area. Urban areas can span counties, but the one with the majority of the population is identified as the primary county.
90
91
 
91
- Urban area data is only provided for states, the District of Columbia, Puerto Rico. It is not provided for other U.S. territories.
92
-
93
92
  ### Place
94
93
 
95
- A place is an organized area within a state usually corresponding to a city, town, village, etc. Places are within a single state, but may span counties. If a place spans multiple counties, the county with the most population will be identified as the primary county. Places may belong to an urban area.
94
+ A place is an organized area within a state usually corresponding to a city, town, village, etc. Places are within a single state, but may span counties. If a place spans multiple counties, the county with the most land area will be identified as the primary county.
96
95
 
97
96
  ### ZIP Code Tabulation Area (ZCTA)
98
97
 
99
98
  Approximate equivalent to U.S. Postal Service ZIP codes, but designed for geographic and demographic purposes rather than mail routing. Not all postal ZIP codes are mapped to ZCTAs (i.e. ZIP codes mapped to a single building) and the borders of ZCTAs smooth out some of the irregularities of ZIP codes. Otherwise, they are mostly interchangeable.
100
99
 
101
- ZCTAs can span counties, urban areas, places. The primary county and primary urban area will be the ones that contain most of the ZCTA's population.
100
+ ZCTAs can span counties, county subdivisions, and places. A primary county, county subdivision, and place are identified for ZCTA's. This will be the one that includes most of the ZCTA's land area.
102
101
 
103
102
  ZCTA data is only provided for states, the District of Columbia, Puerto Rico. It is not provided for other U.S. territories.
104
103
 
104
+ The U.S. Postal Service adds and removes ZIP Codes as necessary for the efficient delivery of mail. The U.S. Census Bureau updates the ZCTA's to reflect these changes during the decenniel census. The list of retired 2010 ZCTA's can still be used via the `USGeo::Zcta.for_zipcode` method. If you search on a retired ZIP code with this method, it will return the ZCTA with the most land overlap with the retired ZIP code.
105
+
106
+ ## Installation
105
107
 
106
- ## Usage
108
+ _Note: if you are not using Rails, then replace all the `rails` commands below with `rake`_
107
109
 
108
110
  First add to you Gemfile:
109
111
 
110
112
  `gem us_geo`
111
113
 
112
- Install the migrations:
114
+ Install the migrations.
113
115
 
114
116
  ```bash
115
- rake us_geo_engine:install:migrations
117
+ rails us_geo_engine:install:migrations
118
+ rails db:migrate
116
119
  ```
117
120
 
118
- Import the data:
121
+ Import the data.
119
122
 
120
123
  ```bash
121
- rake us_geo:import:all
124
+ rails us_geo:import:all
122
125
  ```
123
126
 
124
127
  Or, if you only want to import some subset of the data, you can run any number of the following.
125
128
 
126
129
  ```bash
127
- rake us_geo:import:regions
128
- rake us_geo:import:divisions
129
- rake us_geo:import:states
130
- rake us_geo:import:designated_market_areas
131
- rake us_geo:import:combined_statistical_areas
132
- rake us_geo:import:core_based_statistical_areas
133
- rake us_geo:import:metropolitan_divisions
134
- rake us_geo:import:counties
135
- rake us_geo:import:county_subdivisions
136
- rake us_geo:import:urban_areas
137
- rake us_geo:import:places
138
- rake us_geo:import:zctas
139
- rake us_geo:import:place_counties
140
- rake us_geo:import:urban_area_counties
141
- rake us_geo:import:zcta_counties
142
- rake us_geo:import:zcta_places
143
- rake us_geo:import:zcta_urban_areas
130
+ rails us_geo:import:regions
131
+ rails us_geo:import:divisions
132
+ rails us_geo:import:states
133
+ rails us_geo:import:combined_statistical_areas
134
+ rails us_geo:import:core_based_statistical_areas
135
+ rails us_geo:import:metropolitan_divisions
136
+ rails us_geo:import:counties
137
+ rails us_geo:import:county_subdivisions
138
+ rails us_geo:import:urban_areas
139
+ rails us_geo:import:places
140
+ rails us_geo:import:zctas
141
+ rails us_geo:import:urban_area_counties
142
+ rails us_geo:import:urban_area_county_subdivisions
143
+ rails us_geo:import:place_counties
144
+ rails us_geo:import:zcta_counties
145
+ rails us_geo:import:zcta_county_subdivisions
146
+ rails us_geo:import:zcta_places
144
147
  ```
145
148
 
146
149
  By default this will download the data from files hosted with the project on GitHub and insert/update into the database. If any entity records are found that don't exist in the data files, the `removed` flag on the database rows will be set to `TRUE`.
@@ -151,4 +154,18 @@ You can also load the data programatically by simply calling the `load!` method
151
154
 
152
155
  All records imported from the data files will have their status set to 1 (imported). Any records that were previously imported, but that are no longer in the data file, will have their status changed to -1 (removed) to indicate that they are no longer in the official data set. Finally, records added to the tables manually will have their status set to 0 (manual). It is perfectly acceptable to augment the data set to, for example, add new Postal Service ZIP codes that did not exist during the last census.
153
156
 
154
- This gem can be used outside of a Rails application. You'll just need to copy the migrations by hand and install the import rake tasks.
157
+ You can cleanup all previously imported records that are no longer in the current data set by running:
158
+
159
+ ```bash
160
+ rails us_geo:import:cleanup
161
+ ```
162
+
163
+ ## Contributing
164
+
165
+ Open a pull request on GitHub.
166
+
167
+ Please use the [standardrb](https://github.com/testdouble/standard) syntax and lint your code with `standardrb --fix` before submitting.
168
+
169
+ ## License
170
+
171
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,172 @@
1
+ # Version 2 Update Guide
2
+
3
+ ## Update Data
4
+
5
+ When updating from version 1.x of the gem, first install and run the new database migrations:
6
+
7
+ _Note: if you are not using Rails, then replace all the `rails` commands below with `rake`_
8
+
9
+ ```bash
10
+ rails us_geo_engine:install:migrations
11
+ rails db:migrate
12
+ ```
13
+
14
+ Then re-import the data:
15
+
16
+ ```bash
17
+ rails us_geo:import:all
18
+ ```
19
+
20
+ Or, if you only want to import some subset of the data, you can run any number of the following:
21
+
22
+ ```bash
23
+ rails us_geo:import:regions
24
+ rails us_geo:import:divisions
25
+ rails us_geo:import:states
26
+ rails us_geo:import:combined_statistical_areas
27
+ rails us_geo:import:core_based_statistical_areas
28
+ rails us_geo:import:metropolitan_divisions
29
+ rails us_geo:import:counties
30
+ rails us_geo:import:county_subdivisions
31
+ rails us_geo:import:places
32
+ rails us_geo:import:zctas
33
+ rails us_geo:import:urban_areas
34
+ rails us_geo:import:place_counties
35
+ rails us_geo:import:zcta_counties
36
+ rails us_geo:import:zcta_county_subdivisions
37
+ rails us_geo:import:zcta_places
38
+ rails us_geo:import:zcta_urban_areas
39
+ rails us_geo:import:urban_area_counties
40
+ rails us_geo:import:urban_area_county_subdivisions
41
+ ```
42
+
43
+ ## Data Changes
44
+
45
+ A number of records have been removed in the 2020 data set. These records are marked with a `status` of -1 in the record. Removed records can still be found by queries and will show up in `belongs_to` associations. However, they will not be returned by any `has_many` associations.
46
+
47
+ For instance, if a County Subdivision was removed in the new data set, you could still find it with `CountySubdivision.find`, but calling `county.subdivisions` would not return it. If you want to keep specific records, you can change the `status` to 0 to indicate it was manually added.
48
+
49
+ You can see how many removed rows are in each table by running:
50
+
51
+ ```bash
52
+ rails us_geo:import:removed_counts
53
+ ```
54
+
55
+ You can export data from the removed rows to JSON by running:
56
+
57
+ ```bash
58
+ rails us_geo:import:dump_removed
59
+ ```
60
+
61
+ You can delete the removed rows by running:
62
+
63
+ ```bash
64
+ rails us_geo:import:cleanup
65
+ ```
66
+
67
+ ## Database Changes
68
+
69
+ There were a few database changes made in version 2. The tables and columns will not be automatically dropped from the database. If you were making use of those values, you can continue to do so. However, they will not be updated in the imported data and support for them has been removed from the code.
70
+
71
+ ### Option 1: Cleaning up the database
72
+
73
+ If you wish to remove the tables and colums, you can add this migration to do so:
74
+
75
+ ```ruby
76
+ class CleanupUsGeoVersion1Tables < ActiveRecord::Migration[5.0]
77
+ disable_ddl_transaction!
78
+
79
+ def up
80
+ drop_table :us_geo_designated_market_areas
81
+
82
+ remove_column :us_geo_counties, :dma_code
83
+
84
+ remove_column :us_geo_zcta_counties, :population
85
+ remove_column :us_geo_zcta_counties, :housing_units
86
+
87
+ remove_column :us_geo_zcta_places, :population
88
+ remove_column :us_geo_zcta_places, :housing_units
89
+
90
+ remove_column :us_geo_zcta_urban_areas, :population
91
+ remove_column :us_geo_zcta_urban_areas, :housing_units
92
+
93
+ remove_column :us_geo_urban_area_counties, :population
94
+ remove_column :us_geo_urban_area_counties, :housing_units
95
+ end
96
+
97
+ def down
98
+ raise ActiveRecord::IrreversibleMigration
99
+ end
100
+ end
101
+ ```
102
+
103
+ If you are using these tables in a production environment, you should instruct the models to ignore columns before dropping them. You can do that by deploying an initializer with this code *before* running the migration to drop the columns:
104
+
105
+ ```
106
+ USGeo::County.ignored_columns = %w[dma_code]
107
+ USGeo::ZctaCounty.ignored_columns = %w[population housing_units]
108
+ USGeo::ZctaPlace.ignored_columns = %w[population housing_units]
109
+ USGeo::ZctaUrbanArea.ignored_columns = %w[population housing_units]
110
+ USGeo::UrbanAreaCounty.ignored_columns = %w[population housing_units]
111
+ ```
112
+
113
+ ### Option 2: Restoring the model
114
+
115
+ You can restore the previous models and methods if you wish to continue using them with this code.
116
+
117
+ ```ruby
118
+ module USGeo
119
+ class DesignatedMarketArea < BaseRecord
120
+ include Population
121
+ include Area
122
+
123
+ self.primary_key = "code"
124
+
125
+ has_many :counties, foreign_key: :dma_code, inverse_of: :designated_market_area
126
+ end
127
+ end
128
+
129
+ USGeo::County.belongs_to :designated_market_area, foreign_key: :dma_code, optional: true, inverse_of: :counties
130
+
131
+ module USGeo
132
+ class ZctaPlace
133
+ include Population
134
+
135
+ def percent_zcta_population
136
+ population.to_f / zcta.population.to_f
137
+ end
138
+
139
+ def percent_place_population
140
+ population.to_f / place.population.to_f
141
+ end
142
+ end
143
+ end
144
+
145
+ module USGeo
146
+ class ZctaCounty
147
+ include Population
148
+
149
+ def percent_zcta_population
150
+ population.to_f / zcta.population.to_f
151
+ end
152
+
153
+ def percent_county_population
154
+ population.to_f / county.population.to_f
155
+ end
156
+ end
157
+ end
158
+
159
+ module USGeo
160
+ class ZctaUrbanArea
161
+ include Population
162
+
163
+ def percent_zcta_population
164
+ population.to_f / zcta.population.to_f
165
+ end
166
+
167
+ def percent_urban_area_population
168
+ population.to_f / urban_area.population.to_f
169
+ end
170
+ end
171
+ end
172
+ ```
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.1
@@ -1,6 +1,9 @@
1
- class CreateRegions < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateRegions < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_regions)
6
+
4
7
  create_table :us_geo_regions, id: false do |t|
5
8
  t.integer :id, primary_key: true, null: false, limit: 1
6
9
  t.string :name, null: false, limit: 30, index: {unique: true}
@@ -12,5 +15,4 @@ class CreateRegions < ActiveRecord::Migration[5.0]
12
15
  def down
13
16
  drop_table :us_geo_regions
14
17
  end
15
-
16
18
  end
@@ -1,6 +1,9 @@
1
- class CreateDivisions < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateDivisions < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_divisions)
6
+
4
7
  create_table :us_geo_divisions, id: false do |t|
5
8
  t.integer :id, primary_key: true, null: false, limit: 1
6
9
  t.integer :region_id, null: false, limit: 1, index: true
@@ -13,5 +16,4 @@ class CreateDivisions < ActiveRecord::Migration[5.0]
13
16
  def down
14
17
  drop_table :us_geo_divisions
15
18
  end
16
-
17
19
  end
@@ -1,6 +1,9 @@
1
- class CreateStates < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateStates < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_states)
6
+
4
7
  create_table :us_geo_states, id: false do |t|
5
8
  t.string :code, primary_key: true, null: false, limit: 2
6
9
  t.string :name, null: false, limit: 30, index: {unique: true}
@@ -16,5 +19,4 @@ class CreateStates < ActiveRecord::Migration[5.0]
16
19
  def down
17
20
  drop_table :us_geo_states
18
21
  end
19
-
20
22
  end
@@ -1,6 +1,9 @@
1
- class CreateCombinedStatisticalAreas < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateCombinedStatisticalAreas < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_combined_statistical_areas)
6
+
4
7
  create_table :us_geo_combined_statistical_areas, id: false do |t|
5
8
  t.string :geoid, primary_key: true, null: false, limit: 3
6
9
  t.string :name, null: false, limit: 60, index: {unique: true}
@@ -16,5 +19,4 @@ class CreateCombinedStatisticalAreas < ActiveRecord::Migration[5.0]
16
19
  def down
17
20
  drop_table :us_geo_combined_statistical_areas
18
21
  end
19
-
20
22
  end
@@ -1,6 +1,9 @@
1
- class CreateCoreBasedStatisticalAreas < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateCoreBasedStatisticalAreas < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_core_based_statistical_areas)
6
+
4
7
  create_table :us_geo_core_based_statistical_areas, id: false do |t|
5
8
  t.string :geoid, primary_key: true, null: false, limit: 5
6
9
  t.string :csa_geoid, limit: 5, index: true
@@ -20,5 +23,4 @@ class CreateCoreBasedStatisticalAreas < ActiveRecord::Migration[5.0]
20
23
  def down
21
24
  drop_table :us_geo_core_based_statistical_areas
22
25
  end
23
-
24
26
  end
@@ -1,6 +1,9 @@
1
- class CreateMetropolitanDivisions < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateMetropolitanDivisions < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_metropolitan_divisions)
6
+
4
7
  create_table :us_geo_metropolitan_divisions, id: false do |t|
5
8
  t.string :geoid, primary_key: true, null: false, limit: 5
6
9
  t.string :cbsa_geoid, limit: 5, index: true
@@ -17,5 +20,4 @@ class CreateMetropolitanDivisions < ActiveRecord::Migration[5.0]
17
20
  def down
18
21
  drop_table :us_geo_metropolitan_divisions
19
22
  end
20
-
21
23
  end
@@ -1,6 +1,9 @@
1
- class CreateCounties < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateCounties < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_counties)
6
+
4
7
  create_table :us_geo_counties, id: false do |t|
5
8
  t.string :geoid, primary_key: true, limit: 5, null: false
6
9
  t.integer :gnis_id, null: false, index: true
@@ -12,7 +15,6 @@ class CreateCounties < ActiveRecord::Migration[5.0]
12
15
  t.boolean :central, default: false
13
16
  t.string :fips_class_code, null: false, limit: 2
14
17
  t.string :time_zone_name, null: true, limit: 30
15
- t.string :dma_code, limit: 3, null: true, index: true
16
18
  t.float :land_area, null: true
17
19
  t.float :water_area, null: true
18
20
  t.integer :population, null: true
@@ -30,5 +32,4 @@ class CreateCounties < ActiveRecord::Migration[5.0]
30
32
  def down
31
33
  drop_table :us_geo_counties
32
34
  end
33
-
34
35
  end