{ "cells": [ { "cell_type": "markdown", "id": "7505bcf0", "metadata": {}, "source": [ "# ImagesTiles & PictureCollection — Managing images\n", "\n", "- **`ImagesTiles`** — scan a directory of GeoTIFFs and manage them as tiled layers\n", "- **`PictureCollection`** — georeferenced photo management\n", "\n", "Both inherit from `Zones` (which inherits from `Element_To_Draw`)." ] }, { "cell_type": "markdown", "id": "73a2908c", "metadata": {}, "source": [ "## ImagesTiles — tiled raster images\n", "\n", "`ImagesTiles` scans a directory for GeoTIFF files, extracts their spatial extent,\n", "and stores each as a zone/vector with an attached image." ] }, { "cell_type": "code", "execution_count": 1, "id": "a05d88e2", "metadata": {}, "outputs": [], "source": [ "from wolfhece.images_tiles import ImagesTiles\n", "from pathlib import Path" ] }, { "cell_type": "markdown", "id": "2ded0d71", "metadata": {}, "source": [ "### Usage\n", "\n", "```python\n", "tiles = ImagesTiles(idx='ortho_tiles')\n", "\n", "# Scan a directory for .tif files\n", "tiles.scan_dir(Path('path/to/geotiffs/'), extensions=['tif', 'tiff'])\n", "\n", "print(f\"Found {len(tiles.myzones)} tiles\")\n", "\n", "# Each zone contains a vector with:\n", "# - 4 vertices defining the bounding box\n", "# - myprop.attachedimage -> Path to the GeoTIFF\n", "# - myprop.imagevisible -> bool (auto-hidden if >8M pixels)\n", "\n", "for z in tiles.myzones[:3]:\n", " v = z.myvectors[0]\n", " print(f\" {v.myprop.attachedimage.name}: visible={v.myprop.imagevisible}\")\n", "```\n", "\n", "### Adding to WolfMapViewer\n", "\n", "```python\n", "viewer.add_object(which='imagestiles', newobj=tiles)\n", "```" ] }, { "cell_type": "markdown", "id": "77d5331e", "metadata": {}, "source": [ "## PictureCollection — georeferenced photos\n", "\n", "`PictureCollection` manages photos positioned at real-world coordinates.\n", "Useful for field survey documentation, damage mapping, etc." ] }, { "cell_type": "code", "execution_count": 2, "id": "7c2dc6e0", "metadata": {}, "outputs": [], "source": [ "from wolfhece.PyPictures import PictureCollection" ] }, { "cell_type": "markdown", "id": "a2c8d171", "metadata": {}, "source": [ "### Creating a collection\n", "\n", "```python\n", "pics = PictureCollection(idx='field_photos')\n", "\n", "# Add a photo at specific coordinates (Lambert 72)\n", "pics.add_picture(\n", " picture='photos/damage_001.jpg',\n", " x=220150.0,\n", " y=130200.0,\n", " name='damage_001'\n", ")\n", "\n", "# Add to a specific zone (group)\n", "pics.add_picture(\n", " picture='photos/bridge_north.jpg',\n", " x=220300.0,\n", " y=130100.0,\n", " name='bridge_north',\n", " keyzone='bridges'\n", ")\n", "```\n", "\n", "### Visibility control\n", "\n", "```python\n", "pics.hide_all_pictures() # set all imagevisible = False\n", "pics.show_all_pictures() # set all imagevisible = True\n", "```\n", "\n", "### Extracting visible photos\n", "\n", "```python\n", "# Copy all visible photos to a directory\n", "pics.extract_pictures(Path('output/selected_photos/'))\n", "```\n", "\n", "### Saving / loading\n", "\n", "```python\n", "# Save as .vec file (Zones format)\n", "pics.saveas('field_photos.vec')\n", "\n", "# Reload\n", "pics2 = PictureCollection(filename='field_photos.vec')\n", "```" ] }, { "cell_type": "markdown", "id": "fe384b24", "metadata": {}, "source": [ "## Summary\n", "\n", "| Class | Input | Key methods |\n", "|-------|-------|-------------|\n", "| `ImagesTiles` | Directory of GeoTIFFs | `scan_dir()`, `scan_dir_ext()` |\n", "| `PictureCollection` | Individual photos + coordinates | `add_picture()`, `show/hide_all_pictures()`, `extract_pictures()` |\n", "\n", "Both classes can be loaded into `WolfMapViewer` for interactive viewing." ] } ], "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 }