{ "cells": [ { "cell_type": "markdown", "id": "2085e552-3dd8-4a2b-a646-2cc08a818255", "metadata": {}, "source": [ "## Mapping segmentations to filter pipelines" ] }, { "cell_type": "markdown", "id": "e4f5df45", "metadata": {}, "source": [ "When talking about *adaptive* ground point filtering in `adaptivefiltering` we have two types of adaptivity in mind: Parameter adaptivity and spatial adaptivity. This notebook describes the details of how spatial adaptivity is implemented in `adaptivefiltering`. It assumes that you have already created a suitable segmentation of your dataset into spatial features (e.g. in a GIS). We will then see how we can attach filter pipeline information to that segmentation file." ] }, { "cell_type": "code", "execution_count": null, "id": "3a9768c0-91a2-47c6-bdba-2bea91e7e9b8", "metadata": {}, "outputs": [], "source": [ "import adaptivefiltering as af" ] }, { "cell_type": "markdown", "id": "9dd14ed6", "metadata": {}, "source": [ "We again work on our demonstrator dataset:" ] }, { "cell_type": "code", "execution_count": null, "id": "ead2d92e-4be8-4aa6-82fc-7758d3583b6b", "metadata": {}, "outputs": [], "source": [ "ds = af.DataSet(filename=\"500k_NZ20_Westport.laz\")" ] }, { "cell_type": "markdown", "id": "fd0076db-99a2-4657-9390-dde78f6d2d31", "metadata": {}, "source": [ "Next, we import the segmentation the GeoJSON file. It is assumed to contain a `FeatureCollection` in the sense of the GeoJSON standard where each features combines the geometric information of the segment (`Polygon` or `Multipolygon`) and a number of properties. One of these properties should contain your custom classification of the segments into classes." ] }, { "cell_type": "code", "execution_count": null, "id": "76d28da8-e98a-4079-85ca-4459d793faad", "metadata": {}, "outputs": [], "source": [ "segmentation = af.load_segmentation(\n", " \"westportSegmentation.geojson\", spatial_reference=\"EPSG:4326\"\n", ")" ] }, { "cell_type": "markdown", "id": "a8ad7599-9db4-4036-bdac-7400d2b7b1a5", "metadata": {}, "source": [ "As we are trying to map features to filter pipelines, we also need to load some filter pipelines. Here, we are directly opening these using `load_filter`. In practice, these should be selected from available filter libraries using e.g. the tools described in [Working with filter libraries](libraries.ipynb)." ] }, { "cell_type": "code", "execution_count": null, "id": "8b8b0f04", "metadata": {}, "outputs": [], "source": [ "pipelines = [af.load_filter(\"testfilter1.json\"), af.load_filter(\"testfilter2.json\")]" ] }, { "cell_type": "markdown", "id": "234a23de-7abc-4236-8155-a8433fce27d1", "metadata": {}, "source": [ "The core task of assigning filter piplines is done by the `assign_pipeline` function which allows us to interactively set filter pipelines. On the right hand side, we can choose which property of our GeoJSON file contains the classification information. A feature can be highlighted on the map by clicking the button. For each class of segments, a pipeline can be selected from the dropdown menu:" ] }, { "cell_type": "code", "execution_count": null, "id": "cc53b51f-1448-4d0a-94d7-d08e312844b3", "metadata": { "tags": [] }, "outputs": [], "source": [ "assigned_segmentation = af.assign_pipeline(\n", " ds, segmentation=segmentation, pipelines=pipelines\n", ")" ] }, { "cell_type": "markdown", "id": "f17a82d5-eb7e-4300-a22b-db371aa8d6bc", "metadata": {}, "source": [ "Once the pipelines are assigned, the returned segmentation object has a new property called \"pipeline\" that will direct the adaptivefiltering command line interface to the corresponding filter pipeline file. The modified file can be saved to disk by using the `save` method:" ] }, { "cell_type": "code", "execution_count": null, "id": "ffc060ca-78db-46ac-8453-2af6d7c2f1ce", "metadata": {}, "outputs": [], "source": [ "assigned_segmentation.save(\"assigned_segmentation.geojson\")" ] }, { "cell_type": "markdown", "id": "3470c09c-7bfa-484b-979f-64624ce6272e", "metadata": {}, "source": [ "It is worth noting that `adaptivefiltering` does not store the entire filter configuration in the GeoJSON object. This is done to allow further refinement of the used filter pipelines after the segmentation is created. Also, it does not store absolute or relative paths to your filter pipelines, because these could always change when moving to new hardware or when reorganizing your project. Instead it stores the metadata of your filter (in hashed form) and compares it against the metadata of the filter pipelines in your currently loaded filter libraries. If metadata is ambiguous across the given filter libraries, an error will be thrown." ] }, { "cell_type": "code", "execution_count": null, "id": "18f7cd92-6ce7-43f6-ae0f-69a091df4810", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.10" } }, "nbformat": 4, "nbformat_minor": 5 }