Skip to content

Commit 337ba87

Browse files
committed
fixed missing export for list_all_geoids function
1 parent c88d6af commit 337ba87

File tree

12 files changed

+967
-38
lines changed

12 files changed

+967
-38
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,40 @@ DB.with_connection() do conn
9191
end
9292
```
9393

94+
### Populating Predefined GEOID Sets
95+
96+
The package includes a script to populate the database with predefined GEOID sets:
97+
98+
```bash
99+
# Navigate to the package directory
100+
cd ~/.julia/packages/GeoIDs/[version]/scripts
101+
102+
# Run the script
103+
./populate-geoids
104+
105+
# With verbose output
106+
./populate-geoids --verbose
107+
108+
# Force recreation of existing sets
109+
./populate-geoids --force
110+
```
111+
112+
Alternatively, you can run the Julia script directly:
113+
114+
```bash
115+
julia ~/.julia/packages/GeoIDs/[version]/scripts/populate_geoids.jl
116+
```
117+
118+
The predefined sets include:
119+
- Eastern/Western US counties
120+
- South Florida counties
121+
- Midwest counties
122+
- Mountain West counties
123+
- Great Plains counties
124+
- Colorado Basin counties
125+
- Counties east/west of the 100th meridian
126+
- And more
127+
94128
## Basic Usage
95129

96130
```julia

create_predefined_sets.jl

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env julia
2+
3+
"""
4+
create_predefined_sets.jl
5+
6+
This script creates predefined GEOID sets in the database.
7+
Run it directly from a Julia REPL or command line:
8+
9+
```
10+
julia create_predefined_sets.jl
11+
```
12+
"""
13+
14+
# Make sure GeoIDs package is available
15+
using Pkg
16+
try
17+
using GeoIDs
18+
catch
19+
# If running from the package directory, add the package in dev mode
20+
pkg"activate ."
21+
pkg"instantiate"
22+
using GeoIDs
23+
end
24+
25+
# List of available predefined sets
26+
function list_predefined_sets()
27+
println("\nAvailable predefined GEOID sets:")
28+
println("------------------------------")
29+
30+
# Sort sets by name for better display
31+
set_names = sort(collect(keys(GeoIDs.PredefinedSets.PREDEFINED_SETS)))
32+
33+
for name in set_names
34+
desc = GeoIDs.PredefinedSets.PREDEFINED_SETS[name][2]
35+
geoids = GeoIDs.PredefinedSets.PREDEFINED_SETS[name][1]
36+
println("$name: $desc ($(length(geoids)) GEOIDs)")
37+
end
38+
end
39+
40+
# Create a single set
41+
function create_one_set(set_name)
42+
if !haskey(GeoIDs.PredefinedSets.PREDEFINED_SETS, set_name)
43+
println("Error: Unknown set '$set_name'")
44+
list_predefined_sets()
45+
return false
46+
end
47+
48+
geoids, description = GeoIDs.PredefinedSets.PREDEFINED_SETS[set_name]
49+
50+
try
51+
GeoIDs.Store.create_geoid_set(set_name, description, geoids)
52+
println("Created set '$set_name' with $(length(geoids)) GEOIDs")
53+
return true
54+
catch e
55+
println("Error creating set '$set_name': $e")
56+
return false
57+
end
58+
end
59+
60+
# Create all sets
61+
function create_all_sets()
62+
println("Creating all predefined GEOID sets...")
63+
64+
success_count = 0
65+
failure_count = 0
66+
67+
for (name, (geoids, desc)) in GeoIDs.PredefinedSets.PREDEFINED_SETS
68+
try
69+
GeoIDs.Store.create_geoid_set(name, desc, geoids)
70+
println(" ✓ Created '$name' with $(length(geoids)) GEOIDs")
71+
success_count += 1
72+
catch e
73+
println(" ✗ Failed to create '$name': $(typeof(e))")
74+
failure_count += 1
75+
end
76+
end
77+
78+
println("\nSummary: Created $success_count sets, failed to create $failure_count sets")
79+
end
80+
81+
# Process command line arguments or show menu
82+
if length(ARGS) > 0
83+
if ARGS[1] == "all"
84+
create_all_sets()
85+
elseif ARGS[1] == "list"
86+
list_predefined_sets()
87+
else
88+
for set_name in ARGS
89+
create_one_set(set_name)
90+
end
91+
end
92+
else
93+
# Interactive menu
94+
println("\nGeoIDS Predefined Sets Manager")
95+
println("=============================")
96+
println("This tool helps create predefined GEOID sets in your database.")
97+
98+
list_predefined_sets()
99+
100+
println("\nOptions:")
101+
println("1. Create all predefined sets")
102+
println("2. Create a specific set")
103+
println("3. Exit")
104+
105+
print("\nEnter your choice (1-3): ")
106+
choice = readline()
107+
108+
if choice == "1"
109+
create_all_sets()
110+
elseif choice == "2"
111+
print("Enter set name: ")
112+
set_name = readline()
113+
create_one_set(set_name)
114+
else
115+
println("Exiting.")
116+
end
117+
end

list_geoid_sets.jl

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env julia
2+
3+
"""
4+
list_geoid_sets.jl
5+
6+
This script lists GEOID sets in the database.
7+
Run it directly from a Julia REPL or command line:
8+
9+
```
10+
julia list_geoid_sets.jl
11+
```
12+
"""
13+
14+
# Make sure GeoIDs package is available
15+
using Pkg
16+
try
17+
using GeoIDs
18+
using DataFrames
19+
using PrettyTables
20+
catch
21+
# If running from the package directory, add the package in dev mode
22+
pkg"activate ."
23+
pkg"instantiate"
24+
pkg"add DataFrames PrettyTables"
25+
using GeoIDs
26+
using DataFrames
27+
using PrettyTables
28+
end
29+
30+
# List all GEOID sets
31+
function list_all_sets()
32+
try
33+
sets = GeoIDs.Store.list_geoid_sets()
34+
35+
if isempty(sets)
36+
println("No GEOID sets found in the database.")
37+
return
38+
end
39+
40+
println("\nGEOID Sets in Database:")
41+
println("======================")
42+
43+
# Sort by set name for better display
44+
sort!(sets, :set_name)
45+
46+
# Print as a table
47+
pretty_table(sets,
48+
header=["Set Name", "Description", "Version", "GEOIDs", "Created", "Updated", "Current"],
49+
tf=tf_unicode_rounded,
50+
alignment=:l)
51+
catch e
52+
println("Error listing GEOID sets: $e")
53+
end
54+
end
55+
56+
# List all GEOIDs and the sets they belong to
57+
function list_all_geoids()
58+
try
59+
geoids = GeoIDs.list_all_geoids()
60+
61+
if isempty(geoids)
62+
println("No GEOIDs found in any sets.")
63+
return
64+
end
65+
66+
println("\nGEOIDs and their Sets:")
67+
println("=====================")
68+
69+
# Print as a table
70+
pretty_table(geoids,
71+
header=["GEOID", "Sets Count", "Belongs to Sets"],
72+
tf=tf_unicode_rounded,
73+
alignment=:l)
74+
catch e
75+
println("Error listing GEOIDs: $e")
76+
end
77+
end
78+
79+
# List sets containing a specific GEOID
80+
function list_sets_for_geoid(geoid)
81+
try
82+
sets = GeoIDs.which_sets(geoid)
83+
84+
if isempty(sets)
85+
println("GEOID '$geoid' not found in any sets.")
86+
return
87+
end
88+
89+
println("\nSets containing GEOID '$geoid':")
90+
println("============================")
91+
92+
# Print as a table
93+
pretty_table(sets,
94+
header=["Set Name", "Version", "Description", "Current"],
95+
tf=tf_unicode_rounded,
96+
alignment=:l)
97+
catch e
98+
println("Error listing sets for GEOID $geoid: $e")
99+
end
100+
end
101+
102+
# Process command line arguments or show menu
103+
if length(ARGS) > 0
104+
if ARGS[1] == "sets"
105+
list_all_sets()
106+
elseif ARGS[1] == "geoids"
107+
list_all_geoids()
108+
elseif ARGS[1] == "which" && length(ARGS) > 1
109+
list_sets_for_geoid(ARGS[2])
110+
else
111+
println("Usage:")
112+
println(" $PROGRAM_FILE sets # List all GEOID sets")
113+
println(" $PROGRAM_FILE geoids # List all GEOIDs and their sets")
114+
println(" $PROGRAM_FILE which GEOID # List sets containing GEOID")
115+
end
116+
else
117+
# Interactive menu
118+
println("\nGeoIDS Information Manager")
119+
println("========================")
120+
println("This tool helps you view information about GEOID sets in your database.")
121+
122+
println("\nOptions:")
123+
println("1. List all GEOID sets")
124+
println("2. List all GEOIDs and their sets")
125+
println("3. Find which sets contain a specific GEOID")
126+
println("4. Exit")
127+
128+
print("\nEnter your choice (1-4): ")
129+
choice = readline()
130+
131+
if choice == "1"
132+
list_all_sets()
133+
elseif choice == "2"
134+
list_all_geoids()
135+
elseif choice == "3"
136+
print("Enter GEOID: ")
137+
geoid = readline()
138+
list_sets_for_geoid(geoid)
139+
else
140+
println("Exiting.")
141+
end
142+
end

scripts/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# GeoIDs.jl Scripts
2+
3+
This directory contains utility scripts for the GeoIDs.jl package.
4+
5+
## populate_geoids.jl
6+
7+
This script populates the GeoIDs database tables with all predefined datasets from the PredefinedSets module. It should be run once to initialize the database with standard geographic region definitions.
8+
9+
### Usage
10+
11+
```bash
12+
julia populate_geoids.jl [--force] [--verbose]
13+
```
14+
15+
### Options
16+
17+
- `--force`: Forcibly recreate sets even if they already exist
18+
- `--verbose`: Print detailed information about each operation
19+
20+
### Example
21+
22+
Basic usage:
23+
24+
```bash
25+
julia populate_geoids.jl
26+
```
27+
28+
Verbose output with forced recreation:
29+
30+
```bash
31+
julia populate_geoids.jl --force --verbose
32+
```
33+
34+
### Execution Through GeoIDs Module
35+
36+
The script functionality is also automatically executed when you first load the GeoIDs module through the `initialize_predefined_geoid_sets()` function called in the module's `__init__()`. However, this script provides more detailed feedback and control over the process.
37+
38+
### Requirements
39+
40+
This script requires:
41+
42+
1. A properly configured PostgreSQL database
43+
2. The GeoIDs.jl package installed and accessible in your Julia environment
44+
3. The required database tables (created automatically if they don't exist)
45+
46+
### Environment Variables
47+
48+
The script uses the following environment variables to connect to the database:
49+
50+
- `GEOIDS_DB_NAME`: Database name (defaults to "tiger")
51+
- `GEOIDS_DB_HOST`: Database host (defaults to "localhost")
52+
- `GEOIDS_DB_PORT`: Database port (defaults to "5432")
53+
54+
No username/password authentication is used by default, as the script assumes socket authentication.

scripts/populate-geoids

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Find the directory this script is in
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5+
6+
# Call the Julia script with the same arguments
7+
julia "$SCRIPT_DIR/populate_geoids.jl" "$@"

0 commit comments

Comments
 (0)