Convert latitude and longitude to U.S. state using geospatial lookup.
Project description
latlng-to-state
Quickly find U.S. states or regions from latitude/longitude coordinates using built-in geospatial data. latlng-to-state is a lightweight Python package for geospatial point-in-geometry analysis. It enables you to determine whether a given latitude/longitude point falls within or intersects any polygon geometry — such as U.S. states or other regions.
The package includes built-in datasets for:
- 🗺️ U.S. state geometries (from U.S. Census)
- 📍 U.S. ZIP code centroids (from U.S. Census)
It works seamlessly with GeoPandas and shapely, making it easy to integrate spatial logic into data pipelines, geocoding workflows, and location-based applications.
Disclaimer: This repository is primarily for tutorial and example purposes, demonstrating PyPI package development and GitHub Actions workflows.
🔧 Features
- 🗺️ Spatial Lookup: Determine if a lat/lng point is contained within or intersects with a polygon (e.g., a U.S. state).
- 📦 Built-in Data: Includes preloaded U.S. state geometries and U.S zip codes (as a
.parquetfile). - 🧪 Clean API: Simple utility functions for integrating geospatial logic into your own workflows.
- 🧱 Modular Design: Organized into utilities and core logic for easy extension.
📦 Installation & Dependencies
pip install latlng-to-state
Requires Python ≥ 3.9
This will automatically install the necessary dependencies, including:
geopandasshapelypandaspyarrow
🚀 Quickstart
import geopandas as gpd
from latlng_to_state.datasets import load_us_state_geometry
from latlng_to_state.core.lookup import lookup_geometry_by_point
# Load built-in U.S. state geometries
gdf = load_us_state_geometry()
# Sample lat/lng in Texas
lat, lng = 31.9686, -99.9018
# Lookup state name
state_name = lookup_geometry_by_point(lat, lng, gdf, check_type="contain", return_col="state")
print(state_name) # Output: Texas
lookup_geometry_by_point
lookup_geometry_by_point(
lat: float,
lng: float,
gdf: geopandas.GeoDataFrame,
check_type: Optional[str] = None,
return_col: str = "NAME"
) -> Optional[Union[str, int, float]]
Check whether a given lat/lng point falls inside or intersects with any geometry in a GeoDataFrame.
lat,lng: Coordinates of the point.gdf: AGeoDataFramecontaining geometries (e.g., U.S. states).check_type:"contain","intersect", orNone(tries contain then intersect).return_col: Column to return (e.g.,"NAME"for state name).
Returns the matched value from the return_col column, or None if no match.
load_us_state_geometry
from latlng_to_state.datasets import (
load_us_state_geometry
, load_us_zipcode_centroid
)
gdf = load_us_state_geometry()
Loads the built-in U.S. state geometry data as a GeoDataFrame.
📁 Included Data
The package includes:
- A U.S. state geometry and U.S. zipcode centroid dataset (in
parquetformat) bundled underlatlng_to_state/datasets/data.
💡 Data Source Disclosure
The U.S. state geometries and zipcode centroid data included in this package are sourced from the U.S. Census Bureau and are in the public domain. While efforts have been made to ensure data accuracy, this package is provided "as is" without any warranties. Users should verify the data suitability for their specific applications.
📄 License
This project is licensed under the MIT License.
🧑💻 Contributing
Contributions welcome! Feel free to open issues or submit PRs on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file latlng_to_state-0.0.1.tar.gz.
File metadata
- Download URL: latlng_to_state-0.0.1.tar.gz
- Upload date:
- Size: 5.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd501958dfb3d6c4c217b9c1212696b718c8d77e3c3f247592f8330bd4ae09fe
|
|
| MD5 |
87b1367f12607c366bef686a2ef569d2
|
|
| BLAKE2b-256 |
dfd477c692ac4f6ba68ae3cd6291711c1310196e888bbce57f0d2725819275b0
|
Provenance
The following attestation bundles were made for latlng_to_state-0.0.1.tar.gz:
Publisher:
prod_deploy.yml on AdamIH1/latlng-to-state
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
latlng_to_state-0.0.1.tar.gz -
Subject digest:
dd501958dfb3d6c4c217b9c1212696b718c8d77e3c3f247592f8330bd4ae09fe - Sigstore transparency entry: 732080091
- Sigstore integration time:
-
Permalink:
AdamIH1/latlng-to-state@0ece9a5e53201fcbe5c35e87006fedd4c4b83464 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AdamIH1
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
prod_deploy.yml@0ece9a5e53201fcbe5c35e87006fedd4c4b83464 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file latlng_to_state-0.0.1-py3-none-any.whl.
File metadata
- Download URL: latlng_to_state-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c15655ed0bd7e01f39698ebb24fa3abda2c0b73357347ac98de000ad4a4129e1
|
|
| MD5 |
747e23597fbc32c93bedd7726c81fd2e
|
|
| BLAKE2b-256 |
80c070b88d76c8eacbd7b15f5b352057354bcb94e8aa751487c81d4946f921e9
|
Provenance
The following attestation bundles were made for latlng_to_state-0.0.1-py3-none-any.whl:
Publisher:
prod_deploy.yml on AdamIH1/latlng-to-state
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
latlng_to_state-0.0.1-py3-none-any.whl -
Subject digest:
c15655ed0bd7e01f39698ebb24fa3abda2c0b73357347ac98de000ad4a4129e1 - Sigstore transparency entry: 732080096
- Sigstore integration time:
-
Permalink:
AdamIH1/latlng-to-state@0ece9a5e53201fcbe5c35e87006fedd4c4b83464 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AdamIH1
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
prod_deploy.yml@0ece9a5e53201fcbe5c35e87006fedd4c4b83464 -
Trigger Event:
workflow_dispatch
-
Statement type: