isolines

Contour lines and filled contours (isobands) from grids and scattered points with numpy: marching squares, valid polygons with holes, smoothing, IDW/TIN gridding and GeoJSON output.

Version 0.1.2 · Python >=3.9 · MIT licence
pip install isolines
PyPISourceIssuesChangelogCite (DOI)

isolines

PyPI version Python versions pipeline status License: MIT DOI Downloads

Contour lines and filled contours (isobands) from grids and scattered points, numpy only.

isolines turns a 2-D grid (a DEM, a travel-time surface, a noise raster) or a set of scattered measurements into:

It handles no-data (NaN, masked arrays, a nodata value), georeferences through an affine geotransform, smooths (Chaikin) and simplifies (Douglas-Peucker), interpolates scattered points to a grid (IDW, nearest, linear TIN), and writes GeoJSON. Its only dependency is numpy.

pip install isolines             # numpy only
pip install "isolines[scipy]"    # + linear (Delaunay TIN) interpolation
pip install "isolines[raster]"   # + GeoTIFF and other rasters through rasterio

Requires Python 3.9 or newer.

Typical uses: DEM contours, travel-time isochrones from sampled network times, noise maps from receiver levels, any "contour this surface" job where you don't want a GDAL install.


Quick start (Python)

import math
import numpy as np
import isolines

# A gridded surface with georeferencing (GDAL-style, north-up, 25 m cells)
yy, xx = np.mgrid[0:200, 0:300]
dem = 50 + 40 * np.exp(-((xx - 150) ** 2 + (yy - 100) ** 2) / 2000)
gt = isolines.GeoTransform.north_up(500000.0, 4200000.0, 25.0)

levels = isolines.interval_levels(dem.min(), dem.max(), 5)        # 55, 60, ..., 90
lines = isolines.contour_lines(dem, levels, transform=gt, smooth=2, label_format="{:g} m")
bands = isolines.isobands(dem, [-math.inf, 60, 70, 80, math.inf], transform=gt)

for band in bands:
    print(band.label, round(band.area / 1e4, 1), "ha")

isolines.write_geojson("contours.geojson", lines, precision=2)
isolines.write_geojson("bands.geojson", bands, precision=2)

From scattered points (for example travel times at network nodes):

z, gt = isolines.points_to_grid(x, y, minutes, cell_size=50.0, method="idw", k=8)
isochrones = isolines.isobands(z, [0, 5, 10, 15], transform=gt)

A rasterio dataset can be used directly:

r = isolines.read_raster("dem.tif")          # needs the "raster" extra; NaN for no-data
lines = isolines.contour_lines(r.z, isolines.nice_levels(r.z), transform=r.transform)

See examples/quickstart.py for a DEM, a noise map and an isochrone example.

Quick start (command line)

# contour lines every 10 m from a GeoTIFF (or an Esri ASCII .asc grid)
isolines lines dem.tif --interval 10 --smooth 2 -o contours.geojson

# filled bands with explicit breaks, open-ended below and above
isolines bands noise.asc --breaks 55,60,65,70 --open-ends -o noise.geojson

# bands straight from a point CSV (interpolated to a 50 m grid first)
isolines bands times.csv --value-col minutes --cell-size 50 --method idw \
    --breaks 0,5,10,15 -o isochrones.geojson

# just the interpolation, written as an Esri ASCII grid
isolines grid times.csv --value-col minutes --cell-size 50 -o times.asc

Without --levels/--breaks/--interval, about ten round-numbered levels are chosen. --simplify, --precision, --label-format, --min-length and --min-area are available; isolines <command> --help lists all options.

API overview

Function / class Purpose
contour_lines(z, levels, *, x, y, transform, nodata, pixel_is_area, smooth, simplify, min_length, label_format) List of ContourLine(level, coords, closed, label)
isobands(z, breaks, *, ..., min_area, keep_empty) List of IsoBand(lower, upper, polygons, label), one per interval [lower, upper)
GeoTransform / as_geotransform GDAL 6-coefficient transform; accepts GDAL tuples and rasterio Affine
idw, nearest, linear, points_to_grid, GridSpec Scattered points to grid
interval_levels, nice_interval, nice_levels Level selection
chaikin, douglas_peucker, signed_area, line_length, point_in_ring Geometry helpers
assemble_polygons, orient_polygon, validate_polygon Polygon building and validity checking
read_ascii_grid, write_ascii_grid, read_raster, load_grid, read_points_csv Input
to_geojson, write_geojson, .to_feature() GeoJSON output

Coordinates: with transform, grid value z[row, col] is placed at the pixel centre (pixel_is_area=True, the GDAL/rasterio convention) or the pixel corner (False). With x/y (1-D, strictly monotonic), at (x[col], y[row]). With neither, at (col, row).

GeoJSON properties: lines carry level, label, closed, length; bands carry lower, upper (null for infinite), label, area.

Method and sources

The test suite checks analytic surfaces with known answers: a plane (contour position and band area exact), a cone (contours within the 1/(8r) interpolation error of a circle, annulus area), the saddle z = x*y (contour on the axes, saddle-cell areas computed by hand), nested peak/pit/plateau surfaces (island in a hole), no-data holes and pinches, plus 40 random integer grids whose values sit exactly on the breaks. Every band polygon is validated, and the bands are checked to tile the valid domain; shapely (is_valid, areas) is used as an independent check when installed.

Limitations

Development

python -m pip install -e ".[dev,scipy,raster]"
python -m pytest tests
python -m ruff check . && python -m ruff format --check src tests
python -m mypy src

Academic citation

@software{eminoglu_isolines,
  author  = {Eminoğlu, Yusuf},
  title   = {isolines},
  year    = {2026},
  version = {0.1.2},
  doi     = {10.5281/zenodo.24235578},
  url     = {https://gitlab.com/geophilo1/isolines_sdk}
}

Related Geophilo SDKs

License

MIT License. Copyright (c) 2026 Yusuf Eminoğlu. See LICENSE.

Other Geophilo SDKs