Skip to main content

A library for converting geographic coordinates to grid identifiers (GIDs) and performing spatial operations.

Project description

Geosquare Grid

Geosquare Grid is a Python library that provides methods for converting between geographic coordinates (longitude and latitude) and grid identifiers (GIDs). It also includes functionality for spatial operations and geometry handling, making it a useful tool for geospatial analysis and mapping applications.

Features

  • Convert longitude/latitude to GID and vice versa.
  • Retrieve bounds for grid cells.
  • Get geometries for grid cells.
  • Find all grid cells that overlap with specified geometries.
  • Easy integration with QGIS for geospatial applications.

Installation

You can install the Geosquare Grid library using pip:

pip install geosquare-grid

Usage

Here is a simple example of how to use the Geosquare Grid library:

from geosquare_grid import GeosquareGrid

# Initialize the GeosquareGrid object
grid = GeosquareGrid()

# Convert longitude and latitude to GID
gid = grid.lonlat_to_gid(longitude=106.8938638928753022, latitude=-6.2608983083383016, level=5)
print(f"GID: {gid}")

# Convert GID back to longitude and latitude
longitude, latitude = grid.gid_to_lonlat(gid)
print(f"Longitude: {longitude}, Latitude: {latitude}")

# Get bounds for the grid cell
bounds = grid.get_bounds()
print(f"Bounds: {bounds}")

Methods

lonlat_to_gid

Converts geographic coordinates to a geospatial grid identifier (GID).

Parameters:

  • longitude (float): Longitude in decimal degrees (-180 to 180).
  • latitude (float): Latitude in decimal degrees (-90 to 90).
  • level (int): Precision level (1-14).

Returns:

  • str: Grid identifier.

gid_to_lonlat

Converts a grid ID to geographic coordinates.

Parameters:

  • gid (str): Grid identifier.

Returns:

  • Tuple[float, float]: Longitude and latitude of the grid cell's lower-left corner.

gid_to_bound

Converts a grid ID to its geographical bounds.

Parameters:

  • gid (str): Grid identifier.

Returns:

  • Tuple[float, float, float, float]: Bounding box (min_longitude, min_latitude, max_longitude, max_latitude).

get_bounds

Returns the geographic boundary of the grid cell.

Returns:

  • Tuple[float, float, float, float]: Bounding box (min_longitude, min_latitude, max_longitude, max_latitude).

polyfill

Finds all grid cells that intersect with a polygon.

Parameters:

  • geometry (Polygon): Polygon geometry to fill.
  • size (Union[int, List[int]]): Grid cell size or range of sizes.
  • start (str): Starting cell identifier (default: "2").
  • fullcover (bool): If True, only fully contained cells are returned.

Returns:

  • List[str]: List of grid cell identifiers.

Grid Cell Resolution Reference

Size (meter) Level Approximate Cell Dimensions
10000000 1 Country-sized
1000000 3 Large region
100000 5 City-sized
10000 7 Neighborhood
5000 8 Block-sized
1000 9 Block-sized
500 10 Large building
100 11 Building complex
50 12 Building
10 13 Building
5 14 Room-sized

Documentation

For more detailed documentation, including advanced usage and API reference, please refer to the docs.

Versioning

This project uses automatic versioning based on Git tags with setuptools_scm.

How it works:

  • The version is automatically determined from Git tags
  • Development versions include the commit hash (e.g., 1.0.0.dev0+g1234567)
  • Release versions match the Git tag exactly (e.g., 1.0.0)

Creating a new release:

  1. Create and push a Git tag:
    git tag -a v1.0.0 -m "Release version 1.0.0"
    git push origin --tags
    
  2. The GitHub Actions workflow will automatically build and publish to PyPI when a release is created

Version management script:

Use the included script for version management:

# Show current version
python scripts/version_manager.py --current

# Create a new tag
python scripts/version_manager.py --create-tag v1.0.0 --message "Release version 1.0.0"

License

This project is licensed under the GPL-3.0 license. See the LICENSE file for more details.

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

geosquare_grid-1.1.1.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

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

geosquare_grid-1.1.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file geosquare_grid-1.1.1.tar.gz.

File metadata

  • Download URL: geosquare_grid-1.1.1.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for geosquare_grid-1.1.1.tar.gz
Algorithm Hash digest
SHA256 252a9a4ae1f1c6d5d4ef1b29e21b9d759cd2e4d0cdf5018b97cb4dd7e93af47a
MD5 552c03d22c91fbacdc6244b953eb9f15
BLAKE2b-256 5c6284249ff94d4ea1e90abc386c6d89a90fe4f9eb51f5bc525a93742fcf0e3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for geosquare_grid-1.1.1.tar.gz:

Publisher: python-publish.yml on geosquareai/geosquare-grid

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

File details

Details for the file geosquare_grid-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: geosquare_grid-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for geosquare_grid-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23ffc6f02c75af489723c8abaebfcf409f445ace6cc61e55bf65323ae695a0e9
MD5 eb4504b47e2f82cee53408cd0ec5b341
BLAKE2b-256 0b84268ba9054ded401dd5afcf04ab4ee54ddd249d4d110895603de2219b8be4

See more details on using hashes here.

Provenance

The following attestation bundles were made for geosquare_grid-1.1.1-py3-none-any.whl:

Publisher: python-publish.yml on geosquareai/geosquare-grid

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