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 which results in the coordinate mobing to that boundaries official location, obfuscating where the location actually is.
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.4.tar.gz (108.5 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.4-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jigglecoord-0.0.4.tar.gz
  • Upload date:
  • Size: 108.5 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.4.tar.gz
Algorithm Hash digest
SHA256 a9ca3fe391ba146ab189bb8335a919ef8740f587f76656e4e1e6a8164cb6f981
MD5 559b8f41717b4b7b546c8cce12b5dffe
BLAKE2b-256 a0f4d0bb5fdade695a76fff6584540336ae4031deb539dea1f5b2cd9229de882

See more details on using hashes here.

Provenance

The following attestation bundles were made for jigglecoord-0.0.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: jigglecoord-0.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba042c916a59df67a88b2810f042f4581188b87234efae1f7bb5cb969d0c3ee6
MD5 38d91c49edc62064441f9c35f3496ee3
BLAKE2b-256 72ffcc1a76afbd7b67e2b89b4ceb82bbfac71807ca9bcef56b3ebc8956942cbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for jigglecoord-0.0.4-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