Skip to main content

geo-gremlin GeoGremlin logo

Bunch of geo related stuff:

  • download tiles from WMS
  • makes polygons orthogonal
  • resolves geometries overlaps
  • etc.

Install

pip install "geo-gremlin[vector,raster]"

If you need any GDAL-based helpers (like run_gdal_retiling, gdal_imread), install GDAL in two steps:

  1. Install system GDAL separately (for example via brew on macOS or conda).
  2. Install Python bindings with the same version as your system GDAL to avoid ABI/version mismatch:

CLI

WMS tile operations

geo-gremlin install-bash-completion

Install bash compeltion for CLI into ~/.bashrc file. Run it once after install.


geo-gremlin download_wms_tiles
geo-gremlin download_wms_tiles \
    WMS_SERVER \
    ZOOM_LEVEL \
    BOUNDS_FN \
    OUTPUT_DIR \
    [--n-workers=100] \
    [--first-n-tiles=N] \
    [--wld-suffix=.wld]

Download map tiles intersecting a GeoJSON boundary. Tiles outside the exact boundary are masked, and a world file is created for every downloaded image. Tiles are loaded in EPSG:3857 projection (web-mercator).

geo-gremlin download_wms_tiles \
    "esri" \
    19 \
    data/test-wms/bounds.geojson \
    ./test

This creates the downloaded tiles in test/esri_19/.

Parameters:

  • WMS_SERVER: tile provider: "esri", "google", "bing", "yandex", or "mapbox".
  • ZOOM_LEVEL: zoom level used to select tiles, 19 is usually the best you can get.
  • BOUNDS_FN: path to a vector file defining the download boundary as Polygon feature.
  • OUTPUT_DIR: parent directory for the generated <server>_<zoom> folder.
  • --n-workers: number of concurrent download workers. Defaults to 100.
  • --first-n-tiles: optionally limit the number of downloaded tiles.
  • --wld-suffix: suffix used for generated world files. Defaults to .wld.

geo-gremlin merge_wms_tiles
geo-gremlin merge-wms-tiles \
    INPUT_DIR \
    [--output=OUTPUT_TIF] \
    [--crs=EPSG:3857]

Merge georeferenced PNG or WebP tiles into a single GeoTIFF.

geo-gremlin merge-wms-tiles test/esri_19/

When --output is omitted, this example creates test/esri_19.tif.

Parameters:

  • INPUT_DIR: directory containing image tiles and their world files.
  • --output: output GeoTIFF path. By default, a .tif file is created alongside the input directory.
  • --crs: coordinate reference system assigned to the output. Defaults to EPSG:3857.

Requires GDAL and its Python bindings.


geo-gremlin retile_wms_tiles
geo-gremlin retile-wms-tiles \
    INPUT_DIR \
    OUTPUT_DIR \
    [--tile-width=512] \
    [--tile-height=512] \
    [--tile-overlap=0] \
    [--tile-base-name=tile]

Retile georeferenced PNG tiles into uniformly sized tiles. Empty tiles are removed, and partial edge tiles are padded to the requested dimensions.

geo-gremlin retile-wms-tiles \
    test/esri_19/ \
    test/esri_19_retiled/

Parameters:

  • INPUT_DIR: directory containing PNG tiles and their world files.
  • OUTPUT_DIR: directory where the retiled PNG files will be created.
  • --tile-width: output tile width in pixels. Defaults to 512.
  • --tile-height: output tile height in pixels. Defaults to 512.
  • --tile-overlap: overlap between adjacent tiles in pixels. Defaults to 0.
  • --tile-base-name: base name used for generated tiles. Defaults to tile.

Requires GDAL and its Python bindings.

API

Vector operations

orthogonalize(...)
orthogonalize(
    gdf: gpd.GeoDataFrame,
    *,
    n_workers: int = 6,
    verbose: bool = False,
) -> gpd.GeoDataFrame

Orthogonalize all polygon geometries in a GeoDataFrame. It is a batch wrapper over orthogonalize_poly, with optional multiprocessing.

from geo_gremlin.vector.ortho import orthogonalize

ortho_gdf = orthogonalize(overlap_gdf, n_workers=1, verbose=False)

Parameters:

  • gdf: gpd.GeoDataFrame, input GeoDataFrame with polygon geometries.
  • n_workers: int, number of worker processes (1 runs sequentially).
  • verbose: bool, show progress bars when True.

resolve_overlaps(...)
resolve_overlaps(
    gdf: gpd.GeoDataFrame,
    mode: ResolveMode = "union",
    verbose: bool = False,
    **params,
) -> gpd.GeoDataFrame

Resolve intersecting polygons in a GeoDataFrame by grouping overlaps and merging them using a selected mode.

from geo_gremlin.vector.overlap import resolve_overlaps

overlap_gdf = resolve_overlaps(test_gdf, mode="union", verbose=False)

Parameters:

  • gdf: gpd.GeoDataFrame, input GeoDataFrame with polygon geometries.
  • mode: ResolveMode, merge strategy: "union", "intersection", "largest", or "iou_select".
  • verbose: bool, show progress bars when True.
  • **params: extra params for mode-specific behavior (iou_threshold for "iou_select").

Check results of vector ops? demo-matplot

Check demo_vector.py.

Dev

For dev dependencies check requirements.txt.

Release files for geo-gremlin 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geo-gremlin 0.1.1
File Size Uploaded
geo_gremlin-0.1.1.tar.gz 23.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for geo-gremlin 0.1.1
File Interpreter ABI Platform
geo_gremlin-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 48.9 kB

Release files / geo_gremlin-0.1.1.tar.gz

Download URL geo_gremlin-0.1.1.tar.gz
Size 23.6 kB
Tags Source
SHA-256 checksum
How to use checksums
74ebe9e9eebc65dbf4a6f47e57173317f0f4b0060b3cc6670b1dc41278bcab4c
BLAKE2b-256 checksum
How to use checksums
1499d2a8d5690322ebf909e676198a73bbfa1d0b300b38e5ffd353566a9d96b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / geo_gremlin-0.1.1-py3-none-any.whl

Download URL geo_gremlin-0.1.1-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e75915b23af088e14f5d16e6a94ef8d7ce94e7f15ed93e13b2e28e04e1a389b6
BLAKE2b-256 checksum
How to use checksums
efe58dd0c36f5bfd8254f596eb8caa82db2a7b707eb9a8c1e4397691109d5ee1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page