You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-54Lines changed: 38 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,54 +2,70 @@
2
2
3
3
Zipcode data is free from the various governments around the world. Yet so many organizations, reputable or not, want to charge money for it.
4
4
5
-
We originally pulled down all the US census data we could find, parsed it and exported it into .csv files.
5
+
## History
6
6
7
-
In 2017 we began using [GeoNames](http://www.geonames.org) data, which is licensed under Creative Commons:
7
+
In 2011, we originally pulled down all the US census data we could find, parsed it and exported it into 3 .csv files. Later, we wrote 3 rake tasks to automate this process.
8
8
9
-
We thank [GeoNames](http://www.geonames.org) for sharing, and urge you to [visit their site](http://www.geonames.org) and support their work.
9
+
In 2017 we began using [GeoNames](http://www.geonames.org) data, which is licensed under Creative Commons. We are grateful to [GeoNames](http://www.geonames.org) for sharing, and urge you to [visit their site](http://www.geonames.org) and support their work.
10
+
11
+
In 2018 we refactored the project and made it into a Ruby gem with a command-line executable for automating this process.
10
12
11
13
## What's Included
12
14
13
-
There are three rake tasks which automatically download the latest zipcode data from the country that you specify. Not all countries are accounted for. Please check [GeoNames](http://download.geonames.org/export/zip/) to see a list of supported country zip files.
15
+
* An executable: `free_zipcode_data` - which automates the process of downloading and process the zipcode data from GeoNames. Not all countries are accounted for. Please check [GeoNames](http://download.geonames.org/export/zip/) to see a list of supported country zip files.
14
16
15
-
Each zipcode is correlated with estimated or zip-centroid, latitude and longitude coordinates. Where applicable, county/province, state and community are also correlated.
17
+
Each zipcode is correlated with estimated or zip-centroid, latitude and longitude coordinates. Where applicable, country, county/province, state and community are also correlated.
16
18
17
19
See the GeoNames [readme.txt](http://download.geonames.org/export/zip/readme.txt) file for more information.
18
20
19
21
## Usage
20
22
23
+
First, you need to install Ruby and Rubygems. Though that is not a difficult task, it is beyond the scope of this README. A search engine of your choice will help discover how to do this. Once you have done that:
Determine the countries you want to use at [GeoNames](http://download.geonames.org/export/zip/), or just use the rake task without any `country` argument to get zipcode data for all countries...
29
+
Determine the 2-letter country codes for the countries you want to use at [GeoNames](http://download.geonames.org/export/zip/), or don't specify a country to get all zipcodes for all available countries...
30
+
31
+
### Command Line Options
32
+
28
33
```bash
29
-
# download will pull down the zipcodes for the specified country
30
-
$ rake data:download[country]
31
-
# rake data:download[US] - For US-only zipcodes
32
-
# rake data:download[GB_full.csv] - All UK data zipcodes:
33
-
# rake data:download - ALL zipcodes
34
+
Options:
35
+
-w, --work-dir=<s> REQUIRED: Specify your work/build directory, where the SQLite and .csv files will be built
36
+
-f, --country=<s> Specify the country code for processing, or all countries if not specified
The rake tasks cascade, from the bottom up. So if you run `rake data:populate_db`, it will automatically call `rake data:build`if the .csv files are missing, which will call `rake data:download`if the .zip files are missing.
49
63
50
64
## SQLite3 Database
51
65
52
-
The rake task `rake data:populate_db[country]` will create an SQLite3 database with the following tables, and populate each one:
66
+
The executable will generate an SQLite3 database in the specified directory `--work-dir` but it will not generate the `.csv` files by default. Specify `--generate-files`if you want those as well.
67
+
68
+
By default the tables will be named as follows. To override the table names see the command line options above.
53
69
54
70
```sql
55
71
create table countries (
@@ -79,7 +95,6 @@ create table zipcodes (
79
95
id integer not null primary key,
80
96
code varchar(10) not null,
81
97
state_id integer,
82
-
county_id integer,
83
98
city varchar(255),
84
99
area_code varchar(3),
85
100
lat float,
@@ -90,41 +105,10 @@ create table zipcodes (
90
105
91
106
Both `lat` and `lon`, geocodes, are populated for each zipcode record.
92
107
93
-
## Development
94
-
95
-
If you want to run the specs or do development work, set `GEM_ENV='development'`
96
-
97
108
## Data License
98
109
99
110
The zipcode data is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>, carried forward from [GeoNames](http://www.geonames.org).<br />
0 commit comments