Tell us what works and what could be better. We read every submission.
@alpha-beta-soup·23 public vizzes
This example shows polygon geometries subdivided into smaller triangles until each triangle’s area falls below a specified threshold. The code triangulates input polygons using Shapely’s `constrained_delaunay_triangles`, then recursively splits oversized triangles along the midpoint of their longest edge via a deque-based queue. It handles invalid or non-planar geometries with `make_valid`, `force_2d`, and `buffer(0)`, and processes test polygons defined in WKT format. The output is a generator of Shapely `Polygon` objects.
This example demonstrates a stratified random sampling workflow for preparing GeoPackage (GPKG) vector data for MapAccuracy validation, using `geopandas` to read and explode geometries, then applying per-class sample sizing with finite population correction, optional area-based weighting with fractional power transforms, and optional grouping into numbered sample groups. It uses `pandas` for data manipulation and NumPy for statistical calculations, with the final output written as a GPKG containing mapped, truth, checked, and comment fields.
This example converts GitHub issue data into a formatted HTML document and then into a Word file. It shows each issue as a section with its title, labels, body text, and all associated comments, styled with CSS. The code uses the GitHub CLI to export issue JSON, the Showdown library to convert Markdown to HTML, and Pandoc to transform the HTML into a DOCX. The rendering approach is a static document layout rather than an interactive visualization.
This example generates 500 discrete and 500 continuous random raster landscapes as ASCII grid files for performance benchmarking. It uses the `nlmpy.mpd` function to create midpoint displacement neutral landscape models, then classifies the discrete layers with `nlmpy.classifyArray` and random integer thresholds. Each raster is exported with `nlmpy.exportASCIIGrid`, including randomized georeferencing metadata via a lambda function that jitters the corner coordinates. The code relies on NumPy’s seeded random number generator and Python’s `random` module to ensure reproducible but varied outputs across the 100×100 cell grids.
This example demonstrates how to adjust commit timestamps in a Kart archive so that the repository history reflects the publication dates of three QEII National Trust geospatial datasets, rather than the import times. It shows the process of initializing a Kart repository, importing shapefile data converted to GeoPackage via `ogr2ogr`, and using `kart import` with `--primary-key` and `--replace-existing` flags to manage schema changes across versions. The `GIT_COMMITTER_DATE` environment variable amends each commit’s timestamp to match the original data release, as manually extracted from HTTP response headers. The visualization highlights the workflow’s ability to align versioned geodata with its true temporal provenance.
This example shows a geometry simplification workflow for geospatial vector data, reducing coordinate precision while preserving topology and repairing invalid geometries. It processes an input GeoPackage file, simplifies geometries using a quantisation tolerance, and writes the result back as a GPKG. The script uses geopandas for reading and writing, pygeos for `make_valid` and `simplify` operations, and Snakemake to manage input/output parameters and logging. It also filters out empty or missing geometries before saving the final dataset.
This example demonstrates Uber’s H3 hexagonal hierarchical geospatial indexing system (DGGS) in Python, using a Jupyter notebook to explore cell resolution and coordinate precision. It converts a point for “The Chalet” into an H3 cell ID via `h3.geo_to_h3`, then reverses it with `h3.h3_to_geo` to show information loss, and visualizes the cell boundary as a polygon using `h3.h3_to_geo_boundary`, `shapely.Polygon`, and `geopandas` with an interactive `gdf.explore()` map. It also traces a building footprint from OpenStreetMap to illustrate polygon-to-H3 conversion, emphasizing the explicit precision control that resolution offers.
This example demonstrates utility functions that convert row and column indices from a raster window into geographic coordinates or H3 hexagonal indices. It shows how raster data read with rasterio can be efficiently mapped to H3 cells for spatial analysis. The code defines two lambda functions: one that uses the window's affine transformation and a pyproj.Transformer to convert cell positions to longitude and latitude, and another that calls the h3.api.basic_int library's geo_to_h3 function to derive the corresponding H3 index at a specified resolution. The approach relies on rasterio's window transform and pyproj’s coordinate transformation APIs.
A cron job refreshes the GNOME desktop wallpaper every 15 minutes with the latest full-disk true-color image from the Himawari 8 satellite, as provided by the Colorado State University RAMMB feed. The script downloads the JPEG via `wget` and applies it using `gsettings` to set both the `picture-uri` and `picture-options` (scaled) properties. It relies solely on standard shell utilities and the GNOME settings API, with no rendering or visualization library involved.
This example defines a custom Cartopy coordinate reference system for the NZTM2000 projection, implementing the TransverseMercator class with parameters from EPSG:2193. It sets the globe’s ellipsoid axes, central meridian at 173°E, scale factor, and false easting/northing, then overrides the boundary and x/y limits to match New Zealand’s extent. The code uses cartopy.crs.TransverseMercator and shapely.geometry.LineString to specify the projection’s rectangular bounds, providing a reusable CRS for plotting geospatial data in this local projection.
This example demonstrates a custom GeoJSON serializer that keeps deeply nested coordinate arrays on a single line, avoiding the visual explosion caused by standard pretty-printing. It shows a MultiPolygon feature from RFC7946, with its `geometry.coordinates` array compactly formatted while other properties retain normal indentation. The code uses `JSON.stringify` with a custom `replacer` function that stringifies coordinate arrays, followed by a `replacerWrapper` that removes surrounding quotes. The output is identical to standard formatting except for the coordinates, making GeoJSON files more readable without sacrificing structure.
This visualization maps the FOAF social network of Richard Law, showing his personal connections to family and friends, each positioned by geographic location where known. It uses D3.js’s `d3.forceSimulation` to arrange nodes and links, with geographic coordinates from the FOAF file’s `geo` vocabulary determining initial placements. The graph renders as a force-directed network, displaying node labels and relationship types from the RDF data. The code employs D3’s simulation and SVG rendering to visualize the semantic relationships encoded in the Turtle file.
This example demonstrates how GNU Make and GDAL’s `gdalwarp` command-line tool can replace `gdal_merge.py` for mosaicking multiple GeoTIFF files without loading all data into memory. It shows a Makefile recipe that first runs `gdalwarp` with `-overwrite` on the initial input to create the output, then appends each remaining file via a `$(foreach)` loop. The code uses GDAL’s GTiff creation options (e.g., `TILED=YES`, `COMPRESS=LZW`) and multi-threading flags (`-multi`, `-wo NUM_THREADS=ALL_CPUS`), while the makefile relies on `.ONESHELL` to chain commands. The data source is a set of five local GeoTIFF files (`a.tif` through `e.tif`).
This example demonstrates how to run QGIS 3 processing algorithms directly from a standalone Python script on a typical Ubuntu Linux installation, using the `QgsApplication`, `QgsProcessingFeedback`, and `QgsRasterLayer` classes from the `qgis.core` module. It computes raster statistics—specifically a requested stat like `SUM`—via the `processing.run` call with the `"qgis:rasterlayerstatistics"` algorithm. The script initializes QGIS with `app.initQgis()`, registers native algorithms through `QgsNativeAlgorithms`, and prints the selected statistic from a raster file provided as a command-line argument.
This experiment uses D3 v4 to render New Zealand’s census ward boundaries as a static SVG map. The geographic data is sourced from Stats NZ, converted from the NZTM projection (EPSG:2193) into a quantized TopoJSON format via a Makefile-driven pipeline, then displayed with a null projection so coordinates are used as-is. The map uses a light grey fill for land areas and omits internal boundaries, showing only the outer ward outlines. The code includes a commented-out geoTransform for potential scaling/zooming and a commented-out boundary mesh, suggesting the visualization focuses on the raw spatial layout of New Zealand's wards.
This example demonstrates a unit-validation function that checks whether a string represents a valid Pint unit. It defines `is_str_valid_pint_unit` to attempt parsing the input with the Pint `UnitRegistry` and returns `False` when an `UndefinedUnitError` occurs. The code prints `True` for the sample unit `'degC'`, showing how the registry recognizes common units. The example uses the Pint library’s `ureg()` call to perform the validation.
This example shows a reusable Python function that converts lists of numeric values between different units of measurement using the Pint library. It defines `convert`, which takes an array, a source unit, and a target unit, then applies Pint’s `Quantity` constructor and `.to()` method to return a list of converted quantities. The code relies on `pint.UnitRegistry` to access unit definitions, as demonstrated in the docstring where inches are converted to meters. The function is designed for interactive use, such as in IPython, to avoid repeating unit conversion logic.
This example shows QGIS automatically centering its map canvas on the viewer’s current geographic location. The map extent is set to a fixed 0.01-degree square around the coordinates obtained from the IP geolocation service ipinfo.io. The code uses the Python `pycurl` library to fetch the JSON response, `json` to parse the latitude and longitude, and the QGIS Python API (`qgis.utils.iface.mapCanvas()` with `setExtent` and `QgsRectangle`) to update the view. No additional mapping libraries are used beyond QGIS’s native canvas.
This script prints the geographic bounding-box corners of a raster layer to the QGIS console in the project’s projection system, converting them from pixel coordinates via the GDAL GeoTransform and reprojecting them using the OSR `CoordinateTransformation`. It reads the active layer’s source path with `gdal.Open`, extracts the raster dimensions and geotransform, and transforms each corner from the layer’s spatial reference to its geographic counterpart. The output provides the top-left and bottom-right coordinates needed for a Leaflet `imageOverlay`.
This visualization presents a mapping of New Zealand street type abbreviations to their full names, sourced from a space-separated CSV derived from NZ Post’s address standards PDF. It shows the complete list of 128 paired entries, such as “St” to “Street” and “Ave” to “Avenue,” rendered as a searchable table. Built with Vue, the interface uses a computed filter to instantly narrow rows as users type, highlighting matching abbreviations or full names. The data is loaded directly from the embedded CSV file, and the layout employs simple HTML tables with Vue’s reactive binding for sorting and display.
This example demonstrates how to calculate the interpolated median of a list of values, a statistic that preserves the median’s resistance to outliers while better reflecting the distribution’s skew. It uses the `numpy.median` function to find the traditional median, then applies a correction formula based on the counts of values below, equal to, and above that median, returning a continuous value. The code also offers an alternative formula that incorporates an explicit interval parameter. Three sample lists with identical traditional medians but different distributions are tested, printing both medians to show how the interpolated version distinguishes them.
This example demonstrates a NumPy-based Python function that converts a week’s timetable of transit vehicle arrival times into headways—the seconds until the next vehicle arrives—while correctly handling gaps across midnight and entire days without service. The function `headway_array` takes a 2D array where rows represent sequential trips and columns represent days of the week, with `None` placeholders for trips that do not run on certain days. It returns an array of the same shape with headway values, using a custom formula to account for elapsed midnights and clamping results to a maximum of `maxseconds` times `daysinweek`. The code includes docstring examples showing the transformation on sample data.
This example demonstrates how to perform a repeated-measures ANOVA with sphericity correction using a custom Python function. It shows the statistical results, including F-values, p-values, and corrected degrees of freedom, for each main effect and interaction term in a factorial within-subject design. The implementation relies on NumPy for matrix operations, SciPy for statistical distributions and detrending, and constructs effect codings through binary patterns. The code defines a `repanova` function that returns a list of named tuples containing the effect name, corrected degrees of freedom, F-value, and p-value, with optional Greenhouse-Geisser correction.