diff options
author | Jeff Garrett <jeff@jgarrett.org> | 2007-10-30 03:14:52 +0000 |
---|---|---|
committer | Jeff Garrett <jeff@jgarrett.org> | 2007-10-30 03:14:52 +0000 |
commit | 3ed44c8afe148a537778c7d6ceda80db79ea73bd (patch) | |
tree | a1f3d263fdabcff8db76edf32fcbbdc0761ef529 | |
parent | 0b4f5408c5106c8df0403068d1399ae3d3064114 (diff) |
Add list of TIGER states
src/Makefile.am
src/import_tiger.c
src/tiger.c
Use list of TIGER states instead of hard-coded array
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | data/Makefile.am | 4 | ||||
-rw-r--r-- | data/tiger-states.txt | 56 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/import_tiger.c | 85 | ||||
-rw-r--r-- | src/tiger.c | 71 | ||||
-rw-r--r-- | src/tiger.h | 36 |
7 files changed, 184 insertions, 80 deletions
@@ -1,5 +1,14 @@ 2007-10-30 Jeff Garrett <jeff@jgarrett.org> + * data/Makefile.am: + * data/tiger-states.txt: Add list of TIGER states + * src/Makefile.am + * src/import_tiger.c + * src/tiger.c + * src/tiger.h: Use list of TIGER states instead of hard-coded array + +2007-10-30 Jeff Garrett <jeff@jgarrett.org> + * src/import_tiger.c: Allow remote URIs in import_tiger_from_uri 2007-09-09 Jeff Garrett <jeff@jgarrett.org> diff --git a/data/Makefile.am b/data/Makefile.am index a2d1991..b871c94 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -14,11 +14,15 @@ desktop_DATA = $(DESKTOP_FILES) styledir = $(pkgdatadir) style_DATA = layers.xml +tigerdir = $(pkgdatadir) +tiger_DATA = tiger-states.txt + install-data-local: EXTRA_DIST = \ $(glade_DATA) \ $(style_DATA) \ + $(tiger_DATA) \ $(DESKTOP_IN_FILES) \ $(NULL) diff --git a/data/tiger-states.txt b/data/tiger-states.txt new file mode 100644 index 0000000..822f51e --- /dev/null +++ b/data/tiger-states.txt @@ -0,0 +1,56 @@ +01 AL Alabama +02 AK Alaska +04 AZ Arizona +05 AR Arkansas +06 CA California +08 CO Colorado +09 CT Connecticut +10 DE Delaware +11 DC District of Columbia +12 FL Florida +13 GA Georgia +15 HI Hawaii +16 ID Idaho +17 IL Illinois +18 IN Indiana +19 IA Iowa +20 KS Kansas +21 KY Kentucky +22 LA Louisiana +23 ME Maine +24 MD Maryland +25 MA Massachusetts +26 MI Michigan +27 MN Minnesota +28 MS Mississippi +29 MO Missouri +30 MT Montana +31 NE Nebraska +32 NV Nevada +33 NH New Hampshire +34 NJ New Jersey +35 NM New Mexico +36 NY New York +37 NC North Carolina +38 ND North Dakota +39 OH Ohio +40 OK Oklahoma +41 OR Oregon +42 PA Pennsylvania +44 RI Rhode Island +45 SC South Carolina +46 SD South Dakota +47 TN Tennessee +48 TX Texas +49 UT Utah +50 VT Vermont +51 VA Virginia +53 WA Washington +54 WV West Virginia +55 WI Wisconsin +56 WY Wyoming +60 AS American Samoa +66 GU Guam +69 MP Northern Mariana Islands +72 PR Puerto Rico +78 VI Virgin Islands diff --git a/src/Makefile.am b/src/Makefile.am index 9277bf9..1488fa1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,7 +53,8 @@ roadster_SOURCES = \ road.c\ animator.c\ tooltipwindow.c\ - test_poly.c + test_poly.c\ + tiger.c roadster_LDADD = \ $(GNOME_LIBS) \ diff --git a/src/import_tiger.c b/src/import_tiger.c index fe9dc79..408206d 100644 --- a/src/import_tiger.c +++ b/src/import_tiger.c @@ -31,6 +31,7 @@ #include "import_tiger.h" #include "importwindow.h" #include "road.h" +#include "tiger.h" #ifdef USE_GNOME_VFS #include <gnome-vfs-2.0/libgnomevfs/gnome-vfs.h> @@ -55,13 +56,6 @@ #define ROWS_PER_PULSE (18000) // call import_progress_pulse() after this many rows parsed #define CALLBACKS_PER_PULSE (30) // call " after this many iterations over hash tables (writing to DB) -typedef struct { - gchar* pszCode; - gchar* pszName; -} state_t; - -extern state_t g_aStates[79]; - gint g_nStateID = 0; // this is set during import process typedef enum { @@ -1276,9 +1270,12 @@ static gboolean import_tiger_from_directory(const gchar* pszDirectoryPath, gint // did we read all files? if(bSuccess) { gint nStateID = (nTigerSetNumber / 1000); // int division (eg. turn 25017 into 25) - if(nStateID < G_N_ELEMENTS(g_aStates)) { + GHashTable *states = tiger_get_states(); + struct tiger_state *st; + if ((st = g_hash_table_lookup(states, &nStateID))) + { gint nCountryID = 1; // USA is #1 *gag* - db_insert_state(g_aStates[nStateID].pszName, g_aStates[nStateID].pszCode, nCountryID, &g_nStateID); + db_insert_state(st->name, st->abbrev, nCountryID, &g_nStateID); } g_assert(G_N_ELEMENTS(apszExtensions) == 7); @@ -1428,73 +1425,3 @@ static void debug_print_string(char* str, gint len) g_print("\n"); } #endif - -state_t g_aStates[79] = { - {"", ""}, // NOTE: these are in the proper order to line up with the TIGER data's FIPS code. don't mess with them. :) -/* 1 */ {"AL", "Alabama"}, -/* 2 */ {"AK", "Alaska"}, -/* 3 */ {"", ""}, // unused -/* 4 */ {"AZ", "Arizona"}, -/* 5 */ {"AR", "Arkansas"}, -/* 6 */ {"CA", "California"}, -/* 7 */ {"", ""}, -/* 8 */ {"CO", "Colorado"}, -/* 9 */ {"CT", "Connecticut"}, -/* 10 */ {"DE", "Delaware"}, -/* 11 */ {"DC", "District of Columbia"}, -/* 12 */ {"FL", "Florida"}, -/* 13 */ {"GA", "Georgia"}, -/* 14 */ {"", ""}, -/* 15 */ {"HI", "Hawaii"}, -/* 16 */ {"ID", "Idaho"}, -/* 17 */ {"IL", "Illinois"}, -/* 18 */ {"IN", "Indiana"}, -/* 19 */ {"IA", "Iowa"}, -/* 20 */ {"KS", "Kansas"}, -/* 21 */ {"KY", "Kentucky"}, -/* 22 */ {"LA", "Louisiana"}, -/* 23 */ {"ME", "Maine"}, -/* 24 */ {"MD", "Maryland"}, -/* 25 */ {"MA", "Massachusetts"}, -/* 26 */ {"MI", "Michigan"}, -/* 27 */ {"MN", "Minnesota"}, -/* 28 */ {"MS", "Mississippi"}, -/* 29 */ {"MO", "Missouri"}, -/* 30 */ {"MT", "Montana"}, -/* 31 */ {"NE", "Nebraska"}, -/* 32 */ {"NV", "Nevade"}, -/* 33 */ {"NH", "New Hampshire"}, -/* 34 */ {"NJ", "New Jersey"}, -/* 35 */ {"NM", "New Mexico"}, -/* 36 */ {"NY", "New York"}, -/* 37 */ {"NC", "North Carolina"}, -/* 38 */ {"ND", "North Dakota"}, -/* 39 */ {"OH", "Ohio"}, -/* 40 */ {"OK", "Oklahoma"}, -/* 41 */ {"OR", "Oregon"}, -/* 42 */ {"PA", "Pennsylvania"}, -/* 43 */ {"", ""}, -/* 44 */ {"RI", "Rhode Island"}, -/* 45 */ {"SC", "South Carolina"}, -/* 46 */ {"SD", "South Dakota"}, -/* 47 */ {"TN", "Tennessee"}, -/* 48 */ {"TX", "Texas"}, -/* 49 */ {"UT", "Utah"}, -/* 50 */ {"VT", "Vermont"}, -/* 51 */ {"VA", "Virginia"}, -/* 52 */ {"", ""}, -/* 53 */ {"WA", "Washington"}, -/* 54 */ {"WV", "West Virginia"}, -/* 55 */ {"WI", "Wisconsin"}, -/* 56 */ {"WY", "Wyoming"}, -/* 57-59 */ {"", ""},{"", ""},{"", ""}, -/* 60 */ {"AS", "American Samoa"}, -/* 61-65 */ {"", ""},{"", ""},{"", ""},{"", ""},{"", ""}, -/* 66 */ {"GU", "Guam"}, -/* 67-68 */ {"", ""}, {"", ""}, -/* 69 */ {"MP", "Northern Mariana Islands"}, -/* 70-71 */ {"", ""},{"", ""}, -/* 72 */ {"PR", "Puerto Rico"}, -/* 73-77 */ {"", ""},{"", ""},{"", ""},{"", ""},{"", ""}, -/* 78 */ {"VI", "Virgin Islands"}, -}; diff --git a/src/tiger.c b/src/tiger.c new file mode 100644 index 0000000..c6241e5 --- /dev/null +++ b/src/tiger.c @@ -0,0 +1,71 @@ +/* + * tiger.c + * TIGER helper functions + * + * Copyright 2007 Jeff Garrett <jeff@jgarrett.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <glib.h> +#include "config.h" +#include "tiger.h" + + +#define TIGER_STATES_FILE DATADIR "/tiger-states.txt" + +GHashTable *state_list; + + +GHashTable *tiger_get_states() +{ + gchar *contents, **lines, **iter, **tokens; + struct tiger_state *st; + gint *fips_code; + + if (state_list) + return state_list; + + if (!g_file_get_contents(TIGER_STATES_FILE, &contents, NULL, NULL)) + { + g_warning("Cannot read TIGER states file %s\n", TIGER_STATES_FILE); + return NULL; + } + + state_list = g_hash_table_new(g_int_hash, g_int_equal); + + /* The data file of TIGER states is tab-delimited with fields + * for the state FIPS code, the abbreviation, and the state name. + */ + lines = g_strsplit(contents, "\n", 0); + for (iter = lines; iter && **iter; iter++) + { + st = g_new0(struct tiger_state, 1); + fips_code = g_new0(gint, 1); + + tokens = g_strsplit(*iter, "\t", 0); + *fips_code = g_ascii_strtoull(tokens[0], NULL, 10); + st->abbrev = g_strdup(tokens[1]); + st->name = g_strdup(tokens[2]); + + g_hash_table_insert(state_list, fips_code, st); + + g_strfreev(tokens); + } + g_strfreev(lines); + g_free(contents); + + return state_list; +} diff --git a/src/tiger.h b/src/tiger.h new file mode 100644 index 0000000..969021e --- /dev/null +++ b/src/tiger.h @@ -0,0 +1,36 @@ +/* + * tiger.h + * TIGER helper functions + * + * Copyright 2007 Jeff Garrett <jeff@jgarrett.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __TIGER_H +#define __TIGER_H + +#include <glib.h> + + +struct tiger_state { + gchar *name; + gchar *abbrev; +}; + + +GHashTable *tiger_get_states(); + +#endif |