Skip to main content

Geo2Zip is a Python package that provides a fast and efficient way to find the closest US ZIP code for a given latitude and longitude. It uses a KDTree for quick nearest-neighbor lookup, making it suitable for geospatial queries.

Project description

Geo2Zip

Build and Test

Geo2Zip is a Python package that provides a fast and efficient way to find the closest US ZIP code for a given latitude and longitude. It uses a KDTree for quick nearest-neighbor lookup, making it suitable for geospatial queries.

Current version: 0.1.2

Features

  • Quickly find the closest ZIP code for a given latitude and longitude.
  • Efficient spatial indexing using KDTree.
  • Easy-to-use command-line interface.

Installation

Prerequisites

  • Python 3.7 or higher
  • pip

Install the package

  1. Clone the repository:

    git clone https://github.com/jlopex/geo2zip.git
    cd geo2zip
    
  2. Install the package and its dependencies:

    pip install -e .
    
  3. Install development dependencies (for testing):

    pip install -e .[dev]
    

Usage

Command Line Interface

You can use the geo2zip command to find the closest ZIP code for a given latitude and longitude.

geo2zip <latitude> <longitude>

Example:

geo2zip 37.7749 -122.4194

This command will output the closest ZIP code to the provided coordinates.

As a Python Library

You can also use the Geo2Zip class directly in your Python code:

from geo2zip import Geo2Zip

# Initialize with the path to your data file
geo2zip = Geo2Zip('path/to/geo_zip/data/geo_zip.csv')

# Find the closest ZIP code
latitude = 37.7749
longitude = -122.4194
closest_zip = geo2zip.find_closest_zip(latitude, longitude)
print(f"The closest ZIP code to ({latitude}, {longitude}) is {closest_zip}")

Data

The dataset used for ZIP codes and their coordinates is extracted from the 2023 US Gazetteer Files. The CSV file is included in the package at geo2zip/data/geo2zip.csv.

Testing

Simple and stupid Tests are written using pytest. To run the tests, execute the following command:

pytest tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geo2zip-0.1.2.tar.gz (378.9 kB view details)

Uploaded Source

Built Distribution

geo2zip-0.1.2-py3-none-any.whl (376.9 kB view details)

Uploaded Python 3

File details

Details for the file geo2zip-0.1.2.tar.gz.

File metadata

  • Download URL: geo2zip-0.1.2.tar.gz
  • Upload date:
  • Size: 378.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for geo2zip-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8cffe1507dd74e5845ce9070b2a7818d56491c0d1196e6a14b2e4172d25243ca
MD5 d8fd4f0d60fb4258a844c59e6237aac7
BLAKE2b-256 0a07a25f5f6834a7d0ba8b5eb8352275236e33730778bf4fc2ac51e1ca621cdc

See more details on using hashes here.

File details

Details for the file geo2zip-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: geo2zip-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 376.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for geo2zip-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a91241c3a84bc255291d4988aef6cc5d6bf89897a57e0b24a44eb3e1e0612ca
MD5 dd3a70c74bc0cfe35d61cc9abf003081
BLAKE2b-256 0c1a806006ae453d6e17e40c2e0284f238507a50c82c2d61d461857a6973c5f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page