Docs › Guides › Smoothing

Smoothing

-smooth generalizes polygon and polyline geometry by replacing the original vertices with smooth curves. Unlike -simplify, which thins existing vertices, -smooth recomputes the line's shape. It also filters out small intricate details and preserves sharp corners, such as surveyed borders.

mapshaper coastline.shp -smooth 5km -o smoothed.shp

The <distance> parameter sets the smoothing resolution: detail finer than this scale is removed.

Usage tip

For best geographical fidelity, apply -smooth to unsimplified linework. Smoothing can also be applied to simplified paths, but low-resolution inputs give the smoother less information to work with.

Smoothed low-resolution contour lines:

image

Prefiltering intricate detail

When line smoothing is applied to small, intricate features — jetties, narrow inlets, docks, spikes — the output can include kinks or self-intersections. To prevent this, -smooth first removes detail below the smoothing scale.

Use no-prefilter to skip prefiltering and smooth the input as-is.

Fig. 1: with the prefilter, the small basin, dock outline, and other fine detail are dropped before smoothing.

image

Fig. 2: without the prefilter, the same details pull the smoothed line into unwanted bends and loops.

image

Corner preservation

By default, -smooth protects long straight sections from being reshaped by smoothing.

Here, the straight lines are preserved and the riverine section is smoothed:

image

Use corner-bias= to adjust the sensitivity of corner detection, or no-corners to smooth the entire line uniformly.

# Round off corners instead of preserving them.
mapshaper borders.shp -smooth 5km no-corners -o smoothed.shp

Adaptive vertex density

Output vertices are placed adaptively: more on tight bends, fewer on straight or gently curving runs.

The dots below mark output vertices along a smoothed line.

image

The max-bend-angle= option (default 8 degrees) controls output density. A larger value uses fewer vertices; a smaller value uses more.

Technical notes

  • The -smooth command uses a Gaussian smoothing kernel.
  • Curve compensation reduces the shrinkage that smoothing causes around bends. The gain= option controls the strength of this correction.
  • Lat-long data is smoothed on a sphere: coordinates are converted to 3D geocentric coordinates, distances are measured along great circles, and the result is converted back to longitude and latitude.

See the -smooth reference for the full set of options.