geolookup-plugin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +485 -0
- package/config.yaml +26 -0
- package/data/alabama.tar.gz +0 -0
- package/data/alaska.tar.gz +0 -0
- package/data/american samoa.tar.gz +0 -0
- package/data/arizona.tar.gz +0 -0
- package/data/arkansas.tar.gz +0 -0
- package/data/california.tar.gz +0 -0
- package/data/cnmi.tar.gz +0 -0
- package/data/colorado.tar.gz +0 -0
- package/data/connecticut.tar.gz +0 -0
- package/data/dc.tar.gz +0 -0
- package/data/delaware.tar.gz +0 -0
- package/data/florida.tar.gz +0 -0
- package/data/georgia.tar.gz +0 -0
- package/data/guam.tar.gz +0 -0
- package/data/hawaii.tar.gz +0 -0
- package/data/idaho.tar.gz +0 -0
- package/data/illinois.tar.gz +0 -0
- package/data/indiana.tar.gz +0 -0
- package/data/iowa.tar.gz +0 -0
- package/data/kansas.tar.gz +0 -0
- package/data/kentucky.tar.gz +0 -0
- package/data/louisiana.tar.gz +0 -0
- package/data/maine.tar.gz +0 -0
- package/data/maryland.tar.gz +0 -0
- package/data/massachusetts.tar.gz +0 -0
- package/data/michigan.tar.gz +0 -0
- package/data/minnesota.tar.gz +0 -0
- package/data/mississippi.tar.gz +0 -0
- package/data/missouri.tar.gz +0 -0
- package/data/montana.tar.gz +0 -0
- package/data/nebraska.tar.gz +0 -0
- package/data/nevada.tar.gz +0 -0
- package/data/new hampshire.tar.gz +0 -0
- package/data/new jersey.tar.gz +0 -0
- package/data/new mexico.tar.gz +0 -0
- package/data/new york.tar.gz +0 -0
- package/data/north carolina.tar.gz +0 -0
- package/data/north dakota.tar.gz +0 -0
- package/data/ohio.tar.gz +0 -0
- package/data/oklahoma.tar.gz +0 -0
- package/data/oregon.tar.gz +0 -0
- package/data/pennsylvania.tar.gz +0 -0
- package/data/puerto rico.tar.gz +0 -0
- package/data/rhode island.tar.gz +0 -0
- package/data/south carolina.tar.gz +0 -0
- package/data/south dakota.tar.gz +0 -0
- package/data/tennessee.tar.gz +0 -0
- package/data/texas.tar.gz +0 -0
- package/data/usvi.tar.gz +0 -0
- package/data/utah.tar.gz +0 -0
- package/data/vermont.tar.gz +0 -0
- package/data/virginia.tar.gz +0 -0
- package/data/washington.tar.gz +0 -0
- package/data/west virginia.tar.gz +0 -0
- package/data/wisconsin.tar.gz +0 -0
- package/data/wyoming.tar.gz +0 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/DataLoad.d.ts +26 -0
- package/dist/resources/DataLoad.js +141 -0
- package/dist/resources/DataLoad.js.map +1 -0
- package/dist/resources/Geolookup.d.ts +44 -0
- package/dist/resources/Geolookup.js +105 -0
- package/dist/resources/Geolookup.js.map +1 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
- package/schemas/README.md +11 -0
- package/schemas/schema.graphql +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026, Kyle Bernhardy
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
# Geolookup
|
|
2
|
+
|
|
3
|
+
A [Harper](https://www.harper.fast/) plugin that provides fast, tier-based reverse geocoding for the United States. Give it a latitude and longitude, and it will tell you where you are, down to the city, township, or county level. It won't judge you for being in New Jersey.
|
|
4
|
+
|
|
5
|
+
[](https://www.harper.fast/)
|
|
6
|
+
|
|
7
|
+
## How It Works
|
|
8
|
+
|
|
9
|
+
Geolookup converts a lat/lon coordinate into an [Uber H3](https://h3geo.org/) hexagonal cell index, then searches a pre-indexed table of cells to find the geographic locations that contain that point. The lookup walks from fine-grained resolution (H3 resolution 9, roughly a city block) up to coarse resolution (resolution 2, roughly a large region), checking for matches at each level until it finds results for all requested tiers.
|
|
10
|
+
|
|
11
|
+
The underlying geographic data is sourced from the [US Census TIGER/Line](https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html) shapefiles, converted to H3 hexagonal cells using [compact cell representation](#h3-compact-cells-and-why-they-matter).
|
|
12
|
+
|
|
13
|
+
## Tiers
|
|
14
|
+
|
|
15
|
+
Geographic locations in the US exist at different levels of administrative hierarchy. Geolookup organizes these into three tiers:
|
|
16
|
+
|
|
17
|
+
| Tier | Name | Census Entity | Coverage | Examples |
|
|
18
|
+
|------|------|---------------|----------|----------|
|
|
19
|
+
| **1** | `place` | Incorporated places and Census Designated Places (CDPs) | Partial. Only areas with an incorporated municipality or CDP designation. Rural and unincorporated areas often have no Tier 1 match. | "San Francisco", "Boise", "Chapel Hill" |
|
|
20
|
+
| **2** | `county_subdivision` | Minor Civil Divisions (MCDs) and Census County Divisions (CCDs) | **Full national coverage.** The Census Bureau ensures every square foot of the US falls within a county subdivision, creating statistical "unorganized territories" where no legal MCD exists. | "Springfield Township", "Falls Church city", "Northwest Arctic Borough" |
|
|
21
|
+
| **3** | `county` | Counties and county equivalents | **Full national coverage.** Every point in the US belongs to a county (or equivalent like a parish, borough, or independent city). | "Cook County", "Los Angeles County", "Orleans Parish" |
|
|
22
|
+
|
|
23
|
+
The practical takeaway: if you query for Tier 1 in the middle of a national forest, you may get nothing back. Tier 2 and Tier 3 will always return a result for any valid US coordinate. Plan your tier selection accordingly.
|
|
24
|
+
|
|
25
|
+
### Requesting Specific Tiers
|
|
26
|
+
|
|
27
|
+
The `tiers` query parameter controls which levels of geography are returned. You can request any combination:
|
|
28
|
+
|
|
29
|
+
| Value | Behavior |
|
|
30
|
+
|-------|----------|
|
|
31
|
+
| `all` (default) | Returns all three tiers |
|
|
32
|
+
| `1` | Place only |
|
|
33
|
+
| `2` | County subdivision only |
|
|
34
|
+
| `3` | County only |
|
|
35
|
+
| `1,3` | Place and county |
|
|
36
|
+
| `1,2,3` | Same as `all` |
|
|
37
|
+
|
|
38
|
+
If the `tiers` parameter is omitted, the service defaults to returning all tiers.
|
|
39
|
+
|
|
40
|
+
## Data Model
|
|
41
|
+
|
|
42
|
+
The schema defines two tables in the `geolookup` database, designed to work together for efficient spatial lookups.
|
|
43
|
+
|
|
44
|
+
```mermaid
|
|
45
|
+
erDiagram
|
|
46
|
+
Location {
|
|
47
|
+
ID id PK
|
|
48
|
+
Int tier
|
|
49
|
+
String name
|
|
50
|
+
String name_full
|
|
51
|
+
String state_name
|
|
52
|
+
String state_abbrev
|
|
53
|
+
String h3_index
|
|
54
|
+
String county_name
|
|
55
|
+
}
|
|
56
|
+
Cell {
|
|
57
|
+
ID h3_index PK
|
|
58
|
+
String tier_1 FK "place Location ID"
|
|
59
|
+
String tier_2 FK "county_subdivision Location ID"
|
|
60
|
+
String tier_3 FK "county Location ID"
|
|
61
|
+
}
|
|
62
|
+
DataLoadJob {
|
|
63
|
+
ID id PK
|
|
64
|
+
String state
|
|
65
|
+
String status
|
|
66
|
+
Int location_count
|
|
67
|
+
Int cell_count
|
|
68
|
+
String started_at
|
|
69
|
+
String completed_at
|
|
70
|
+
Int duration_ms
|
|
71
|
+
}
|
|
72
|
+
Location ||--o{ Cell : "place_cells (tier_1)"
|
|
73
|
+
Location ||--o{ Cell : "county_subdivision_cells (tier_2)"
|
|
74
|
+
Location ||--o{ Cell : "county_cells (tier_3)"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Location
|
|
78
|
+
|
|
79
|
+
The `Location` table stores geographic entities across all three tiers. Each record represents a single place, county subdivision, or county.
|
|
80
|
+
|
|
81
|
+
Key attributes:
|
|
82
|
+
|
|
83
|
+
| Field | Description |
|
|
84
|
+
|-------|-------------|
|
|
85
|
+
| `id` | Primary key |
|
|
86
|
+
| `tier` | Integer (1, 2, or 3) indicating the geographic level |
|
|
87
|
+
| `tier_label` | Human-readable tier name |
|
|
88
|
+
| `name` | Short name (e.g. "Springfield") |
|
|
89
|
+
| `name_full` | Full qualified name |
|
|
90
|
+
| `feature_type` | Census feature classification |
|
|
91
|
+
| `state_name` / `state_abbrev` | State information |
|
|
92
|
+
| `lat` / `lon` | Representative point for the location |
|
|
93
|
+
| `h3_index` | H3 cell index for the location's representative point |
|
|
94
|
+
| `country_code` | Country code (US) |
|
|
95
|
+
| `lsad` | Legal/Statistical Area Description code from Census |
|
|
96
|
+
| `county_name` / `county_fips` | Parent county info |
|
|
97
|
+
| `place_cells` | Relationship to Cell records (via `tier_1`) |
|
|
98
|
+
| `county_subdivision_cells` | Relationship to Cell records (via `tier_2`) |
|
|
99
|
+
| `county_cells` | Relationship to Cell records (via `tier_3`) |
|
|
100
|
+
|
|
101
|
+
### Cell
|
|
102
|
+
|
|
103
|
+
The `Cell` table is the spatial index. Each record represents a single H3 hexagonal cell and links to the Location(s) it belongs to at each tier.
|
|
104
|
+
|
|
105
|
+
| Field | Description |
|
|
106
|
+
|-------|-------------|
|
|
107
|
+
| `h3_index` | Primary key. The H3 cell index string. |
|
|
108
|
+
| `tier_1` | Location ID of the place this cell belongs to (if any) |
|
|
109
|
+
| `tier_2` | Location ID of the county subdivision this cell belongs to |
|
|
110
|
+
| `tier_3` | Location ID of the county this cell belongs to |
|
|
111
|
+
| `place` | Relationship to Location (from `tier_1`) |
|
|
112
|
+
| `county_subdivision` | Relationship to Location (from `tier_2`) |
|
|
113
|
+
| `county` | Relationship to Location (from `tier_3`) |
|
|
114
|
+
|
|
115
|
+
A single cell can belong to locations at multiple tiers simultaneously. For example, one H3 cell might be in the city of Denver (Tier 1), an MCD (Tier 2), and Denver County (Tier 3). The `@indexed` directive on `tier_1`, `tier_2`, and `tier_3` enables fast lookups from both directions: cell-to-location and location-to-cells.
|
|
116
|
+
|
|
117
|
+
### H3 Compact Cells and Why They Matter
|
|
118
|
+
|
|
119
|
+
The raw TIGER/Line shapefiles define geographic boundaries as polygons. To make these searchable via H3, each polygon is filled with H3 cells. A naive approach would store every cell at the finest resolution, but that would produce an enormous number of records.
|
|
120
|
+
|
|
121
|
+
Instead, Geolookup uses H3's **compact cell** representation. The `compactCells` operation replaces any group of 7 child cells that share the same parent with that single parent cell. This is applied recursively, producing a mixed-resolution set of cells that covers the exact same area with far fewer records. The [H3 documentation](https://h3geo.org/docs/core-library/restable/) shows the magnitude of this: a compact representation can be an order of magnitude smaller than its uncompacted equivalent.
|
|
122
|
+
|
|
123
|
+
This is why the lookup algorithm searches across resolutions 9 down to 2, rather than at a single fixed resolution. A query point might match a fine-grained resolution-9 cell in a densely covered urban area, or it might only match a coarser resolution-4 cell in a rural area where compaction was more aggressive. The algorithm generates the H3 index for the query point at resolution 9, then computes its parent cell at each coarser resolution, and searches for any of those cells in the database. The first match found at each tier is the answer.
|
|
124
|
+
|
|
125
|
+
This design gives you the best of both worlds: precise coverage without a bloated cell table.
|
|
126
|
+
|
|
127
|
+
## The Lookup Algorithm
|
|
128
|
+
|
|
129
|
+
```mermaid
|
|
130
|
+
flowchart TD
|
|
131
|
+
A["GET /Geolookup?lat=...&lon=...&tiers=..."] --> B[Parse lat, lon, tiers]
|
|
132
|
+
B --> C{Valid params?}
|
|
133
|
+
C -- No --> D[Return error]
|
|
134
|
+
C -- Yes --> E["Convert lat/lon to H3 cell at resolution 9"]
|
|
135
|
+
E --> F["Compute parent cells at resolutions 8 down to 2"]
|
|
136
|
+
F --> G["Search Cell table for any matching H3 index (OR)"]
|
|
137
|
+
G --> H{Cell found?}
|
|
138
|
+
H -- No more cells --> K[Return results collected so far]
|
|
139
|
+
H -- Yes --> I["Extract Location for each requested tier"]
|
|
140
|
+
I --> J{All requested tiers found?}
|
|
141
|
+
J -- Yes --> K
|
|
142
|
+
J -- No --> H
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Here is what happens when a request hits the Geolookup endpoint:
|
|
146
|
+
|
|
147
|
+
1. **Parse input.** Extract `lat`, `lon`, and `tiers` from query parameters.
|
|
148
|
+
2. **Generate H3 index.** Convert the coordinate to an H3 cell at resolution 9 using `latLngToCell()`.
|
|
149
|
+
3. **Build candidate set.** Compute the parent cell at each resolution from 8 down to 2 using `cellToParent()`. This produces 8 candidate cell indexes (resolutions 9, 8, 7, 6, 5, 4, 3, 2).
|
|
150
|
+
4. **Search cells.** Query the `Cell` table for any record matching one of the candidate H3 indexes. The query uses an OR condition across all candidates and includes relationship joins only for the requested tiers.
|
|
151
|
+
5. **Collect results.** As matching cells come back, extract the linked Location for each requested tier. Once all requested tiers have a result, stop early.
|
|
152
|
+
6. **Return.** Send back an object with keys for each requested tier (e.g. `place`, `county_subdivision`, `county`).
|
|
153
|
+
|
|
154
|
+
## Plugin Configuration
|
|
155
|
+
|
|
156
|
+
Geolookup is designed to be used as a Harper [plugin](https://docs.harperdb.io/docs/reference/components). The entry point is `src/index.ts`, which exports a `handleApplication()` function that Harper calls during startup.
|
|
157
|
+
|
|
158
|
+
```mermaid
|
|
159
|
+
flowchart LR
|
|
160
|
+
A[Harper Startup] --> B["handleApplication(scope)"]
|
|
161
|
+
B --> C{exposeGeoService?}
|
|
162
|
+
C -- Yes --> D["Register Geolookup at /{geoServiceName}"]
|
|
163
|
+
C -- No --> E[Skip]
|
|
164
|
+
B --> F{exposeDataLoadService?}
|
|
165
|
+
F -- Yes --> G["Register DataLoad at /{dataLoadServiceName}"]
|
|
166
|
+
F -- No --> H[Skip]
|
|
167
|
+
D --> I[Ready]
|
|
168
|
+
E --> I
|
|
169
|
+
G --> I
|
|
170
|
+
H --> I
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Installing as a Plugin
|
|
174
|
+
|
|
175
|
+
In the consuming application's `config.yaml`, reference the Geolookup component and provide configuration options:
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
'geolookup':
|
|
179
|
+
package: 'geolookup'
|
|
180
|
+
exposeGeoService: true
|
|
181
|
+
geoServiceName: 'geo'
|
|
182
|
+
exposeDataLoadService: true
|
|
183
|
+
dataLoadServiceName: 'dataload'
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Configuration Options
|
|
187
|
+
|
|
188
|
+
| Option | Type | Default | Description |
|
|
189
|
+
|--------|------|---------|-------------|
|
|
190
|
+
| `exposeGeoService` | `boolean` | `false` | When `true`, the Geolookup resource is registered and accessible via REST at the path specified by `geoServiceName`. When `false` or omitted, the plugin loads but does not expose a lookup endpoint. Useful if you want to import and use the `Geolookup` class programmatically without a public-facing REST route. |
|
|
191
|
+
| `geoServiceName` | `string` | - | The name under which the Geolookup resource is registered. This becomes the URL path segment for the endpoint (e.g. setting it to `"geo"` exposes the service at `/geo`). Required when `exposeGeoService` is `true`. |
|
|
192
|
+
| `exposeDataLoadService` | `boolean` | `false` | When `true`, the DataLoad resource is registered and accessible via REST at the path specified by `dataLoadServiceName`. Provides a bulk data loading endpoint for populating the `Location` and `Cell` tables from pre-packaged state data files. |
|
|
193
|
+
| `dataLoadServiceName` | `string` | - | The name under which the DataLoad resource is registered. This becomes the URL path segment for the endpoint (e.g. setting it to `"dataload"` exposes the service at `/dataload`). Required when `exposeDataLoadService` is `true`. |
|
|
194
|
+
|
|
195
|
+
### Direct Export
|
|
196
|
+
|
|
197
|
+
The `Geolookup` class is also exported directly from the plugin module, so consuming applications can import and use it in their own resources or custom logic without going through the REST endpoint.
|
|
198
|
+
|
|
199
|
+
## API Usage
|
|
200
|
+
|
|
201
|
+
### Basic Lookup (All Tiers)
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
curl "http://localhost:9926/Geolookup?lat=40.7128&lon=-74.0060"
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Response:
|
|
208
|
+
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"place": {
|
|
212
|
+
"id": "...",
|
|
213
|
+
"tier": 1,
|
|
214
|
+
"name": "New York",
|
|
215
|
+
"name_full": "New York city",
|
|
216
|
+
"state_name": "New York",
|
|
217
|
+
"state_abbrev": "NY",
|
|
218
|
+
"h3_index": "...",
|
|
219
|
+
"country_code": "US",
|
|
220
|
+
"county_name": "New York"
|
|
221
|
+
},
|
|
222
|
+
"county_subdivision": {
|
|
223
|
+
"id": "...",
|
|
224
|
+
"tier": 2,
|
|
225
|
+
"name": "Manhattan",
|
|
226
|
+
"name_full": "Manhattan borough",
|
|
227
|
+
"state_name": "New York",
|
|
228
|
+
"state_abbrev": "NY",
|
|
229
|
+
"h3_index": "...",
|
|
230
|
+
"country_code": "US",
|
|
231
|
+
"county_name": "New York"
|
|
232
|
+
},
|
|
233
|
+
"county": {
|
|
234
|
+
"id": "...",
|
|
235
|
+
"tier": 3,
|
|
236
|
+
"name": "New York County",
|
|
237
|
+
"name_full": "New York County",
|
|
238
|
+
"state_name": "New York",
|
|
239
|
+
"state_abbrev": "NY",
|
|
240
|
+
"h3_index": "...",
|
|
241
|
+
"country_code": "US",
|
|
242
|
+
"county_name": "New York"
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Single Tier
|
|
248
|
+
|
|
249
|
+
```sh
|
|
250
|
+
curl "http://localhost:9926/Geolookup?lat=40.7128&lon=-74.0060&tiers=3"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Response:
|
|
254
|
+
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"county": {
|
|
258
|
+
"id": "...",
|
|
259
|
+
"tier": 3,
|
|
260
|
+
"name": "New York County",
|
|
261
|
+
...
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Multiple Tiers
|
|
267
|
+
|
|
268
|
+
```sh
|
|
269
|
+
curl "http://localhost:9926/Geolookup?lat=40.7128&lon=-74.0060&tiers=1,3"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Response includes only `place` and `county` (no `county_subdivision`).
|
|
273
|
+
|
|
274
|
+
### Query Parameters
|
|
275
|
+
|
|
276
|
+
| Parameter | Required | Description |
|
|
277
|
+
|-----------|----------|-------------|
|
|
278
|
+
| `lat` | Yes | Latitude (decimal degrees) |
|
|
279
|
+
| `lon` | Yes | Longitude (decimal degrees) |
|
|
280
|
+
| `tiers` | No | Comma-separated tier numbers (`1`, `2`, `3`) or `all`. Defaults to `all`. |
|
|
281
|
+
|
|
282
|
+
## Data Loading
|
|
283
|
+
|
|
284
|
+
Geographic data is pre-packaged as `.tar.gz` files in the `data/` directory, one per state or territory. The `DataLoad` endpoint validates the requested state, creates a tracking job, and immediately returns the job ID. The actual data extraction and loading runs asynchronously in the background. Progress is tracked in the `DataLoadJob` table, which is exported and can be queried directly at any time.
|
|
285
|
+
|
|
286
|
+
### DataLoad Endpoint
|
|
287
|
+
|
|
288
|
+
> **Important:** The DataLoad endpoint is intended for initial data seeding only. Once all desired states have been loaded, set `exposeDataLoadService` to `false` in your `config.yaml` to disable the endpoint. There is no need to keep it exposed during normal operation.
|
|
289
|
+
|
|
290
|
+
**`GET /DataLoad?state={state}`**
|
|
291
|
+
|
|
292
|
+
Initiates a data load for the given state. The `state` parameter is case-insensitive (it is lowercased internally). The endpoint validates that a matching `.tar.gz` file exists before creating the job.
|
|
293
|
+
|
|
294
|
+
```sh
|
|
295
|
+
curl "http://localhost:9926/DataLoad?state=Wyoming"
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Response (returns immediately):
|
|
299
|
+
|
|
300
|
+
```json
|
|
301
|
+
{
|
|
302
|
+
"jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
The returned `jobId` can be used to check progress via the `DataLoadJob` endpoint.
|
|
307
|
+
|
|
308
|
+
If the state is invalid or no data file exists, an error is returned synchronously:
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
{
|
|
312
|
+
"error": "No data file found for state: wyoming"
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
#### What happens in the background
|
|
317
|
+
|
|
318
|
+
1. **Extracting** — The `.tar.gz` archive is extracted to the `data/` directory
|
|
319
|
+
2. **Loading locations** — All JSON files from the `{state}/Location/` folder are loaded into the `Location` table. The job's `location_count` is updated after each file.
|
|
320
|
+
3. **Loading cells** — All JSON files from the `{state}/Cell/` folder are loaded into the `Cell` table. The job's `cell_count` is updated after each file.
|
|
321
|
+
4. **Cleanup** — The extracted state folder is deleted (even on error)
|
|
322
|
+
|
|
323
|
+
All database writes within each file are wrapped in a Harper [transaction](https://docs.harperdb.io/docs/reference/transactions) for performance.
|
|
324
|
+
|
|
325
|
+
#### DataLoad Query Parameters
|
|
326
|
+
|
|
327
|
+
| Parameter | Required | Description |
|
|
328
|
+
|-----------|----------|-------------|
|
|
329
|
+
| `state` | Yes | Name of the state or territory to load (case-insensitive). Must match a `.tar.gz` file in the `data/` directory. |
|
|
330
|
+
|
|
331
|
+
### DataLoadJob Endpoint
|
|
332
|
+
|
|
333
|
+
**`GET /DataLoadJob/{jobId}`**
|
|
334
|
+
|
|
335
|
+
The `DataLoadJob` table is exported as a REST resource, so you can query it directly to check the status of a data load job using the `jobId` returned by the `DataLoad` endpoint.
|
|
336
|
+
|
|
337
|
+
```sh
|
|
338
|
+
curl "http://localhost:9926/DataLoadJob/a1b2c3d4-e5f6-7890-abcd-ef1234567890"
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Response:
|
|
342
|
+
|
|
343
|
+
```json
|
|
344
|
+
{
|
|
345
|
+
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
346
|
+
"state": "wyoming",
|
|
347
|
+
"status": "completed",
|
|
348
|
+
"error_message": null,
|
|
349
|
+
"location_count": 152,
|
|
350
|
+
"cell_count": 8432,
|
|
351
|
+
"started_at": "2026-03-06T12:00:00.000Z",
|
|
352
|
+
"completed_at": "2026-03-06T12:00:45.000Z",
|
|
353
|
+
"duration_ms": 45000
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
You can also list all jobs:
|
|
358
|
+
|
|
359
|
+
```sh
|
|
360
|
+
curl "http://localhost:9926/DataLoadJob"
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
#### DataLoadJob Fields
|
|
364
|
+
|
|
365
|
+
| Field | Description |
|
|
366
|
+
|-------|-------------|
|
|
367
|
+
| `id` | Job ID (UUID) |
|
|
368
|
+
| `state` | The state being loaded |
|
|
369
|
+
| `status` | Current job status (see table below) |
|
|
370
|
+
| `error_message` | Error details if status is `error`, otherwise `null` |
|
|
371
|
+
| `location_count` | Number of `Location` records loaded so far |
|
|
372
|
+
| `cell_count` | Number of `Cell` records loaded so far |
|
|
373
|
+
| `started_at` | ISO 8601 timestamp when the job was created |
|
|
374
|
+
| `completed_at` | ISO 8601 timestamp when the job finished (or errored) |
|
|
375
|
+
| `duration_ms` | Total elapsed time in milliseconds |
|
|
376
|
+
|
|
377
|
+
#### Job Statuses
|
|
378
|
+
|
|
379
|
+
```mermaid
|
|
380
|
+
stateDiagram-v2
|
|
381
|
+
[*] --> pending : Job created
|
|
382
|
+
pending --> extracting : Background processing starts
|
|
383
|
+
extracting --> loading_locations : Archive extracted
|
|
384
|
+
loading_locations --> loading_cells : All Location files loaded
|
|
385
|
+
loading_cells --> completed : All Cell files loaded
|
|
386
|
+
extracting --> error : Extraction fails
|
|
387
|
+
loading_locations --> error : Loading fails
|
|
388
|
+
loading_cells --> error : Loading fails
|
|
389
|
+
completed --> [*]
|
|
390
|
+
error --> [*]
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
| Status | Description |
|
|
394
|
+
|--------|-------------|
|
|
395
|
+
| `pending` | Job created, processing has not started |
|
|
396
|
+
| `extracting` | Extracting the `.tar.gz` archive |
|
|
397
|
+
| `loading_locations` | Loading records into the `Location` table |
|
|
398
|
+
| `loading_cells` | Loading records into the `Cell` table |
|
|
399
|
+
| `completed` | All data loaded successfully |
|
|
400
|
+
| `error` | An error occurred (see `error_message`) |
|
|
401
|
+
|
|
402
|
+
### Available States and Territories
|
|
403
|
+
|
|
404
|
+
The following states and territories have pre-packaged data files available for loading:
|
|
405
|
+
|
|
406
|
+
| States | | | |
|
|
407
|
+
|--------|--------|--------|--------|
|
|
408
|
+
| alabama | alaska | arizona | arkansas |
|
|
409
|
+
| california | colorado | connecticut | delaware |
|
|
410
|
+
| florida | georgia | hawaii | idaho |
|
|
411
|
+
| illinois | indiana | iowa | kansas |
|
|
412
|
+
| kentucky | louisiana | maine | maryland |
|
|
413
|
+
| massachusetts | michigan | minnesota | mississippi |
|
|
414
|
+
| missouri | montana | nebraska | nevada |
|
|
415
|
+
| new hampshire | new jersey | new mexico | new york |
|
|
416
|
+
| north carolina | north dakota | ohio | oklahoma |
|
|
417
|
+
| oregon | pennsylvania | rhode island | south carolina |
|
|
418
|
+
| south dakota | tennessee | texas | utah |
|
|
419
|
+
| vermont | virginia | washington | west virginia |
|
|
420
|
+
| wisconsin | wyoming | | |
|
|
421
|
+
|
|
422
|
+
| Territories | |
|
|
423
|
+
|-------------|-------------|
|
|
424
|
+
| american samoa | cnmi |
|
|
425
|
+
| dc | guam |
|
|
426
|
+
| puerto rico | usvi |
|
|
427
|
+
|
|
428
|
+
## Development
|
|
429
|
+
|
|
430
|
+
### Prerequisites
|
|
431
|
+
|
|
432
|
+
- [Node.js](https://nodejs.org/) v24+ (see `.nvmrc`)
|
|
433
|
+
- [Harper](https://docs.harperdb.io/docs/deployments/install-harper) installed globally: `npm install -g harperdb`
|
|
434
|
+
|
|
435
|
+
### Setup
|
|
436
|
+
|
|
437
|
+
After cloning the repo, install the agent skills used for development:
|
|
438
|
+
|
|
439
|
+
```sh
|
|
440
|
+
npm run agent:skills:update
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### Running Locally
|
|
444
|
+
|
|
445
|
+
```sh
|
|
446
|
+
npm run dev
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
This starts the Harper dev server at [http://localhost:9926](http://localhost:9926).
|
|
450
|
+
|
|
451
|
+
### Testing
|
|
452
|
+
|
|
453
|
+
```sh
|
|
454
|
+
npm test # run all tests
|
|
455
|
+
npm run test:watch # run tests in watch mode
|
|
456
|
+
node --test test/geolookup.test.js # run a single test file
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Tests use the Node.js built-in test runner (`node:test`) and `node:assert/strict`.
|
|
460
|
+
|
|
461
|
+
### Linting and Formatting
|
|
462
|
+
|
|
463
|
+
```sh
|
|
464
|
+
npm run lint # ESLint
|
|
465
|
+
npm run format # Prettier
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
## Deployment
|
|
469
|
+
|
|
470
|
+
Configure your `.env` file with your [Harper Fabric](https://fabric.harper.fast/) cluster credentials (see `.env.example`), then:
|
|
471
|
+
|
|
472
|
+
```sh
|
|
473
|
+
npm run deploy
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
A GitHub Actions workflow (`.github/workflow/deploy.yaml`) is also included for CI/CD deployment via `workflow_dispatch`.
|
|
477
|
+
|
|
478
|
+
## Links
|
|
479
|
+
|
|
480
|
+
- [Harper Documentation](https://docs.harperdb.io/docs)
|
|
481
|
+
- [Harper Fabric](https://fabric.harper.fast/)
|
|
482
|
+
- [Harper Components Reference](https://docs.harperdb.io/docs/reference/components)
|
|
483
|
+
- [Harper Resource Class Reference](https://docs.harperdb.io/docs/reference/resources)
|
|
484
|
+
- [H3: Uber's Hexagonal Hierarchical Spatial Index](https://h3geo.org/)
|
|
485
|
+
- [US Census TIGER/Line Shapefiles](https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html)
|