Skip to main content

A Python package to introduce slight perturbations to coordinates.

Project description

JiggleCoord: A geocoding utility for python

GIF

Summary

This package provides a robust solution for reverse geocoding geographical coordinates (returns the address details and merges them into a dataframe), a task often complicated by points falling on administrative boundaries. It intelligently addresses this challenge by employing a "snowflake" perturbation strategy, where it systematically tests nearby coordinates to "escape" the boundary and find a valid, non-ambiguous location. This functionality is seamlessly integrated with pandas DataFrames, allowing for efficient and reliable geocoding of large datasets for data science and analysis.

Features

  • Smart Geocoding: Automatically handles cases where a coordinate falls on a geographical boundary.
  • "Snowflake" Perturbation: When a boundary is detected, the package generates a small, structured grid of surrounding points to find the nearest valid location using the Haversine formula.
  • DataFrame Integration: Seamlessly processes large datasets by integrating directly with pandas DataFrames.
  • Rate-Limited: Uses geopy's built-in rate limiter to respect API usage policies.

Installation

You can install the package directly from PyPI:

pip install JiggleCoord

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

  • pandas
  • geopy

Quickstart

Full output

Example 1: Geocoding all rows from a DataFrame

print("--- Example 1: Geocoding All Rows ---")
sample_df_all = pd.DataFrame({
    'latitude': [40.7128, 51.5074, 38.8977],
    'longitude': [-74.0060, -0.1278, -77.0365]
})

# The function will geocode all coordinates since `geocode_on` is not specified
all_results = geopy_df_geocoder(
    sample_df_all,
    latitude_col='latitude',
    longitude_col='longitude',
    perturb_levels=2,
    perturb_distance=500
)
print("\nDataFrame after geocoding all rows:")
print(all_results[['latitude', 'longitude', 'display_name', 'status', 'perturbation_layer']])

Example 2: Geocoding specific rows based on a condition

print("\n--- Example 2: Geocoding Specific Rows (Boundary Condition) ---")
sample_df_selective = pd.DataFrame({
    'id': [1, 2, 3],
    'latitude': [40.7128, 38.8977, 51.5074],
    'longitude': [-74.0060, -77.0365, -0.1278],
    'class': ['place', 'boundary', 'place'],
    'type': ['city', 'administrative', 'city']
})

# The function will only process the row where 'class' is 'boundary'
selective_results = geopy_df_geocoder(
    sample_df_selective,
    latitude_col='latitude',
    longitude_col='longitude',
    geocode_on="`class` == 'boundary'",
    perturb_levels=2,
    perturb_distance=500
)
print("\nDataFrame after selectively geocoding 'boundary' rows:")
print(selective_results[['id', 'latitude', 'longitude', 'class', 'status', 'perturbation_layer', 'display_name']]) 

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

jigglecoord-0.0.3.tar.gz (108.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jigglecoord-0.0.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file jigglecoord-0.0.3.tar.gz.

File metadata

  • Download URL: jigglecoord-0.0.3.tar.gz
  • Upload date:
  • Size: 108.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jigglecoord-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3c3ee2842817258bff2c7376965cd5a5d1740b9332a5516890bc117d671bfaa4
MD5 aaa55cbd00d51a41b9d4a6e9ba9352bc
BLAKE2b-256 469293bcab0cd8a0c84647562d0a08814de1f431d10087ec25dae4eca88ea2bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for jigglecoord-0.0.3.tar.gz:

Publisher: python-publish.yml on ssopic/JiggleCoord

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jigglecoord-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: jigglecoord-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jigglecoord-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ac914ffbc76803a2b30b37f0418abfb5525e2b31ef27031037464f17f477e91
MD5 aaaa780073feb427ef3c868d0ff7ac49
BLAKE2b-256 00eb70c2de421805f1a6b5ef2dba4d7e5e63fa7f9f667ba68f053a6e317be174

See more details on using hashes here.

Provenance

The following attestation bundles were made for jigglecoord-0.0.3-py3-none-any.whl:

Publisher: python-publish.yml on ssopic/JiggleCoord

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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