8000 GitHub - AZHenley/coord2state: coord2state.js maps latitude and longitude coordinates to their corresponding US state
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

AZHenley/coord2state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coord2state

coord2state is a single-file JS library with no dependencies for quickly looking up which state a given latitude and longitude point is in. You can read my blog post about why I built this: Mapping latitude and longitude to country, state, or city

Installation

You can install it via NPM:

npm install coord2state

Or include it directly with a CDN:

<script src="https://unpkg.com/coord2state/dist/coord2state.min.js"></script>

Usage

Once the script is loaded, simply call getState(lat, lon), like so:

const state = getState(40.7128, -74.0060); // returns "NY"

Building

To generate the JS library, install geopandas and run build_state_lookup.py:

python3 scripts/build_state_lookup.py \
  --shapefile tl_2024_us_state.shp \
  --template src/coord2state.template.js \
  --tolerance 0.01 \           
  --out dist/coord2state.js

You can then minify it using:

terser dist/coord2state.js \
  --compress \
  --mangle \
  --output dist/coord2state.min.js \
  --comments false

Evaluate

The Jupyter notebook for evaluating the borders is benchmark_borders.ipynb

bordersnotebook

For comparing the vertices, run count_points.py:

python3 scripts/count_points.py

For generating the border comparison visualizations, run visualize_state.py:

python3 scripts/visualize_state.py
open compare.png

borderstexas50

About

coord2state.js maps latitude and longitude coordinates to their corresponding US state

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0