{ "cells": [ { "cell_type": "markdown", "id": "8695cc25", "metadata": {}, "source": [ "# Coordinates_operations — CRS transformations\n", "\n", "This module provides coordinate transformation utilities between Belgian CRS:\n", "\n", "- **Lambert 72** (`EPSG:31370`) — legacy Belgian grid\n", "- **Lambert 2008** (`EPSG:3812`) — current Belgian grid\n", "- **WGS 84** (`EPSG:4326`) — lat/lon\n", "\n", "It also supports raster reprojection via GDAL." ] }, { "cell_type": "code", "execution_count": 1, "id": "7ac629e9", "metadata": {}, "outputs": [], "source": [ "from wolfhece.Coordinates_operations import transform_coordinates\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "7893f9ac", "metadata": {}, "source": [ "## Transforming point coordinates\n", "\n", "`transform_coordinates` converts an `(n, 2)` numpy array from one EPSG to another.\n", "Large arrays are processed in chunks with multiprocessing." ] }, { "cell_type": "code", "execution_count": 2, "id": "959f7849", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Lambert 2008 -> Lambert 72:\n", " (710000.0, 600000.0) -> (209992.5, 99991.9)\n", " (650000.0, 650000.0) -> (149997.9, 149999.4)\n" ] } ], "source": [ "# Points in Lambert 2008 (EPSG:3812)\n", "pts_3812 = np.array([\n", " [710000.0, 600000.0], # approximate Liège area\n", " [650000.0, 650000.0], # approximate Brussels area\n", "])\n", "\n", "# Convert to Lambert 72 (EPSG:31370)\n", "pts_31370 = transform_coordinates(\n", " pts_3812,\n", " inputEPSG='EPSG:3812',\n", " outputEPSG='EPSG:31370'\n", ")\n", "\n", "print(\"Lambert 2008 -> Lambert 72:\")\n", "for a, b in zip(pts_3812, pts_31370):\n", " print(f\" ({a[0]:.1f}, {a[1]:.1f}) -> ({b[0]:.1f}, {b[1]:.1f})\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "83055b63", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Lambert 2008 -> WGS 84 (lon, lat):\n", " (710000.0, 600000.0) -> (5.209195, 50.207972)\n", " (650000.0, 650000.0) -> (4.368720, 50.660611)\n" ] } ], "source": [ "# Convert to WGS 84 (lat/lon)\n", "pts_wgs84 = transform_coordinates(\n", " pts_3812,\n", " inputEPSG='EPSG:3812',\n", " outputEPSG='EPSG:4326'\n", ")\n", "\n", "print(\"Lambert 2008 -> WGS 84 (lon, lat):\")\n", "for a, b in zip(pts_3812, pts_wgs84):\n", " print(f\" ({a[0]:.1f}, {a[1]:.1f}) -> ({b[0]:.6f}, {b[1]:.6f})\")" ] }, { "cell_type": "markdown", "id": "e8793c47", "metadata": {}, "source": [ "## Raster reprojection\n", "\n", "`reproject_and_resample_raster` reprojects a GeoTIFF between CRS using GDAL.\n", "\n", "```python\n", "from wolfhece.Coordinates_operations import reproject_and_resample_raster\n", "from osgeo import gdal\n", "\n", "reproject_and_resample_raster(\n", " input_raster_path='input_L2008.tif',\n", " output_raster_path='output_L72.tif',\n", " input_srs='EPSG:3812',\n", " output_srs='EPSG:31370',\n", " resampling_method=gdal.GRA_Bilinear,\n", " xRes=1.0, yRes=1.0\n", ")\n", "```" ] }, { "cell_type": "markdown", "id": "6fe6ea00", "metadata": {}, "source": [ "## Summary\n", "\n", "| Function | Use case |\n", "|----------|----------|\n", "| `transform_coordinates(pts, inputEPSG, outputEPSG)` | Convert point arrays between CRS |\n", "| `reproject_and_resample_raster(...)` | Reproject GeoTIFF rasters via GDAL |\n", "\n", "Common Belgian EPSG codes:\n", "\n", "| EPSG | Name |\n", "|------|------|\n", "| 31370 | Belgian Lambert 72 |\n", "| 3812 | Belgian Lambert 2008 |\n", "| 4326 | WGS 84 (lat/lon) |" ] } ], "metadata": { "kernelspec": { "display_name": "python311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }