Footprint Plots and Subplots — Algorithm Notes
Related user page: Footprint Plots and Subplots
Purpose
Split line footprints into plots and subplots along their centerlines, labelled by side, plot and subplot. Ported from SegLine (src/fixed_area and src/fixed_length) by Irina Terentieva.
Inputs and outputs
- Inputs: footprint polygons, centerlines,
mode(fixed_areadefault orfixed_length), plot/subplot sizes,remove_overlap(defaultfalse) - Outputs: plot layer (one feature per plot side) and subplot layer, with the SegLine columns
UniqueID,side,plot_id,subplot_id,area,length,perimeter,plot_area,subplot_area, plusest_width
Method summary
- Check the sizes: subplot size
> 0; in fixed area, plot area>= 2 xsubplot area; in fixed length, plot length>=subplot length. Footprints and centerlines must share a CRS. - Keep an existing unique
UniqueIDcolumn, otherwise generate random 6-character IDs. - Match each footprint to the centerline with the longest overlap inside it (spatial index query, then intersection length).
- With
remove_overlap, decide who keeps each overlap and trim lines that end in one (see Overlap removal). - In a worker per footprint:
- Prepare the centerline (
prepare_centerline): merge parts and trim it to the stretch that overlaps the footprint. - Estimate the width as footprint area / centerline length (
estimate_width). - Get the plot and subplot lengths along the line (
area_mode_lengthsor the fixed lengths). - Split the footprint (
split_footprint), then cut out overlaps it gives up at crossings. - Snap the pieces to a
1e-6m grid and drop zero-width spikes and crumbs of0.001m² or less. - Number plots and subplots across the output, add the measure columns and write both layers.
The core logic is in beratools/modules/mapping/algo_footprint_plots.py; matching and overlap decisions are in beratools/modules/mapping/footprint_plots.py.
Plot and subplot lengths
- Fixed area: a subplot covers one side, so its area is
length x width / 2. - Subplot length =
2 x subplot_area / width - Subplots per side =
round(plot_area / (2 x subplot_area)), at least 1 - Plot length = subplots per side
xsubplot length - Fixed length:
plot_lengthandsubplot_lengthare used directly.
Because the width is the footprint's average, the mean subplot area matches the target; locally wider or narrower parts give larger or smaller subplots.
Stations
subplot_stations places subplot starts along the centerline:
- Plots start every plot length; subplots restart at each plot start, so a plot length that isn't a multiple of the subplot length leaves a shorter last subplot in each plot.
- A piece shorter than half a subplot length (
MIN_TAIL_FRACTION) joins the previous subplot.
Splitting by labelled faces
split_footprint cuts by geometry, not by split order:
- Extend the centerline straight along its end tangents, so it crosses the whole footprint.
- Draw a cross cut perpendicular to the line at every station after the first. Cuts reach the footprint's Hausdorff distance from the centerline plus its width plus 1 m.
- Polygonize the footprint boundary, the extended centerline and the cuts into faces.
- For each face inside the footprint, project its representative point onto the centerline:
- the station interval it falls in gives the subplot;
- the sign of the cross product with the local tangent gives the side (
0left,1right of the line direction). - Dissolve faces with the same side and station into one subplot, and the subplots of a plot side into one plot.
Labelling faces by position keeps sides consistent along the line and gives exactly one geometry per plot side and subplot, even where cross cuts at bends cross each other. Plots and subplots cover the footprint without gaps or overlaps.
Overlap removal
Each overlap between two matched footprints (polygon parts larger than 0.001 m²) is decided on its own:
- A line that ends in the overlap loses it to one that passes through. A line ends in it if a centerline end is within half the footprint width (at least
0.5m) of the overlap. - Otherwise a cardinal line keeps it over a non-cardinal one. A line is cardinal if its main direction is within
15°of north-south or east-west. The main direction is the length-weighted mean of the segment directions, averaged as axes (angles doubled), so a line and its reverse agree and short bends count little. - Then the longer centerline (inside its footprint) keeps it, then the lower input index.
The loser gives up the overlap in one of two ways:
- Ends in the overlap (
trim_line_ends, before splitting): the overlap is cut off the footprint and the centerline keeps its longest stretch outside it, in its original direction. Footprint pieces touching the overlap but not crossed by that stretch (bits beyond the other footprint) are dropped; other parts of a multipart footprint are kept. A footprint with nothing left is skipped. - Passes through (
remove_overlap, after splitting): the overlap is cut out of the subplots, which keep their stations andlength. A subplot split in two keeps both pieces; a subplot entirely inside the overlap is dropped. Plots are rebuilt as the union of their subplots.
Numbering
As in SegLine, plot_id and subplot_id are unique across the output. Subplots are sorted by footprint, plot, side and position along the line, so IDs increase along each line. length is measured along the centerline; area, perimeter and plot_area are measured on the final geometry, after any overlap removal.
Assumptions
- Footprints and centerlines use the same projected CRS (metres).
- Each footprint has one main centerline running along it.
Edge cases
- Footprints with no overlapping centerline, or whose centerline has no length inside the footprint, are skipped.
- A start trimmed off a line in overlap removal shifts every plot along that line by the trimmed amount; trimming the far end doesn't move plots.
- Plots and subplots the crossing runs through can end up as two pieces, one on each side of the other line.