## Best Fit Plane help

### Rationale

By coupling mapping and remote sensing information with topographic data, it is possible to estimate the orientation of geological planes that best approximate lineaments observed in the field (example in Fig. 1). This is a common task in geological mapping and analysis.
Fig. 1. Example of estimation of a thrust surface orientation in the Mt. Alpi area (Basilicata, Southern Italy).

### User workflow

There are two possible workflows to define the input data: (a) by using 2D geometries (points, lines or polygons) whose topographic elevations are then extracted from a Digital Elevation Model (DEM) (Fig. 2, (a) part) or (b) by using 3D geometries (Fig. 2, (b) part).
After having defined the input data, a list of their spatial properties will be shown (c) and the best-fit-plane can then be calculated (d) (Fig. 2).
Fig. 2. Type of data input via DEM and 2D geometries (a) or via 3D geometries (b). A list of input points is afterwards created (c) and the best-fit-plane may be calculated (d).

#### Data input from 2D features and a topographic DEM

##### DEM definition

When using 2D features as input, first you have to define the input DEM that will be used to extract the elevation information for each feature location (1 in Fig. 3). The user chooses the DEM to be used by selecting one of the rasters loaded in the project.
Note that when the CRS of the source DEM is in polar coordinates (i.e., latitude and longitude) or its vertical distance unit is different from the horizontal one (e.g., meters for the height and decimal degrees for the horizontal location), in order to avoid incorrect results, the user must assign to the project a planar CRS with resulting horizontal and vertical measures expressed in the same distance unit (e.g., meters both for horizontal and vertical distances).

##### Features definition

Afterwards, you may digitize the input points directly in the map canvas (2a in Fig. 3) or, alternatively, load the features from an existing point/line/polygon layer (2b and then 3 in Fig. 3).
In the former case, place the points as a cluster on a structural surface or the trace of a resistant geological unit forming an escarpment.
In the case of loading an existing layer, when there are selected elements only those will be used, otherwise all records will be used. The loaded features will then be listed as points in a window (4 in Fig. 3).
It is possible to reset the points by clicking the Reset all input points button (5 in Fig. 3). When completed with the input features definition, the best-fit-plane can be calculated by pressing the Calculate best-fit plane button (6 in Fig. 3). A pop-up window will display the resulting plane dip direction and dip angle (example in Fig. 1, right-bottom side window).
Fig. 3. Screenshot of the workflow for input from DEM and feature layer.

#### Data input from 3D features

Data can be entered form a single point layer, when there is a "z" field available storing the elevations. The user chooses the input point layer (1 in Fig. 4) and then reads the data via the button to read the input data (2 in Fig. 4). Remember that when there is a selection only selected data will be read. When there is no selection, all layer points will be read. The remaining parts of the processing are the same as when inputting data from DEM and a vector layer: read input data are displayed (3 in Fig. 4), can be reset (4 in Fig. 4) and the best-fit-plane calculated (5 in Fig. 4).
Fig. 4. Screenshot of the workflow for input from point layer storing the elevation information.

#### Defining an Sqlite database to store results

It is possible to save the solution and associated notes in a permanent SQLite database, by using the "Save best-fit-plane value" button (bottom of the stereoplot window in the bottom-right side of Fig. 1).
Before saving, the SQLite database to use has to be defined in the "Saved result database" tab (Fig. 5). It is possible to load an existing database, to which new results will be appended, or create a new database.
Fig. 5. Definition of the internal SQLite database.

#### Processing database records

Saved solutions can be inspected, plotted in a stereo-net, removed or exported in a shapefile from the "Results" tab (Fig. 5). Selected records can be exported in a new or a previous shapefile, both as points or as lines connecting the source points, using the "Export selected records" button (Fig. 6). The output shapefile CRS will always be EPSG:4236.
Fig. 6. Parameters of calculated results stored in a Sqlite database.
The fields added in the exported point/line shapefiles provide information about the point or line features. In particular, fields named 'mpt_lon', 'mpt_lat' and 'mpt_z' provide the x, y and z Cartesian coordinates of the mean point of the inverted points, while 'distance' is the orthogonal distances of the source points from the inferred best-fit-plane passing through the mean point (BFP) (Fig. 7). Points above the plane will have positive distances, while points below the mean BFP will have negative distances (see example in Fig. 8). The fields 'dist_x', 'dist_y' and 'dist_z' are the Cartesian components of the distance between each input point and the corresponding orthogonal projection onto the BFP.
Fig. 7. Example of results for export as points.
Note that when exporting as a point shapefile, the orthogonal distances of the source points from the inferred best-fit-plane (passing through the mean point) will be inserted in the output, as well as the Cartesian components (Fig. 8). Points above the plane will have positive distances, while points below the BFP will have negative distances.
Fig. 8. Example of points along original polygonal source, symbolized by distance from the best-fit-plane: red points are above the best-fit-plane (BFP), blue ones below the BFP and white ones almost near the BFP.

#### Methodology

The algorithm is based on the application of singular value decomposition technique, in order to derive the eigenvectors of a set of measures.
See the discussion in Fit points to a plane algorithms, how to interpret results?.
-----
Doc version 2025-12-30, by Mauro Alberti - alberti.m65@gmail.com