Contour.Core.ContourGenerator.MarchingSquares
1.0.6
dotnet add package Contour.Core.ContourGenerator.MarchingSquares --version 1.0.6
NuGet\Install-Package Contour.Core.ContourGenerator.MarchingSquares -Version 1.0.6
<PackageReference Include="Contour.Core.ContourGenerator.MarchingSquares" Version="1.0.6" />
<PackageVersion Include="Contour.Core.ContourGenerator.MarchingSquares" Version="1.0.6" />
<PackageReference Include="Contour.Core.ContourGenerator.MarchingSquares" />
paket add Contour.Core.ContourGenerator.MarchingSquares --version 1.0.6
#r "nuget: Contour.Core.ContourGenerator.MarchingSquares, 1.0.6"
#:package Contour.Core.ContourGenerator.MarchingSquares@1.0.6
#addin nuget:?package=Contour.Core.ContourGenerator.MarchingSquares&version=1.0.6
#tool nuget:?package=Contour.Core.ContourGenerator.MarchingSquares&version=1.0.6
Contour.Core.ContourGenerator.MarchingSquares
A .NET library for generating contour lines and contour polygons from raster grids using the Marching Squares algorithm. Built on NetTopologySuite geometries and the Contour.Core abstraction layer.
How It Works
Each raster cell (2x2 group of grid nodes) is subdivided into 4 sub-triangles by connecting the corners to a bilinear-interpolated center point. Contour lines and polygons are then traced through this triangle mesh at specified elevation intervals.
TL -------- TR TL -------- TR
| | | \ T / |
| | --> | L + R |
| | | / B \ |
BL -------- BR BL -------- BR
Installation
dotnet add package Contour.Core.ContourGenerator.MarchingSquares
Usage
From an ESRI ASCII Raster file
using AsciiRaster.Parser;
using Contour.Core.ContourGenerator.MarchingSquares;
// Parse the raster file
var raster = EsriAsciiRaster.Read("elevation.asc");
// Build the triangle mesh
var grid = RasterGrid.FromRaster(raster);
// Create the generator
var generator = new ContourGenerator(
new MarchingSquaresContourLines(geometryPrecision),
new MarchingSquaresContourPolygons(geometryPrecision));
generator.SetInput(grid);
// Generate contour lines at 10m intervals
double[] intervals = [10, 20, 30, 40, 50];
Dictionary<double, List<LineString>> contourLines = generator.GenerateContourLines(intervals);
// Generate contour polygons (with optional progress reporting)
Dictionary<double, MultiPolygon> contourPolygons = generator.GenerateContourPolygons(intervals);
From pre-transformed coordinates
When grid coordinates have already been projected or transformed (e.g., to WGS84):
using NetTopologySuite.Geometries;
using Contour.Core.ContourGenerator.MarchingSquares;
// Build a grid from pre-computed nodes [col, row] with M = elevation value
CoordinateM[,] nodes = new CoordinateM[nCols, nRows];
// ... populate nodes ...
var grid = RasterGrid.FromNodes(nodes, noDataValue: -9999);
var generator = new ContourGenerator(
new MarchingSquaresContourLines(geometryPrecision),
new MarchingSquaresContourPolygons(geometryPrecision));
generator.SetInput(grid);
Dictionary<double, List<LineString>> lines = generator.GenerateContourLines(intervals);
Dictionary<double, MultiPolygon> polygons = generator.GenerateContourPolygons(intervals);
Key Features
- Contour lines - traces isolines across the triangle mesh at specified elevation intervals
- Contour polygons - generates filled polygons for areas above each contour level, with parallel processing across intervals
- Dual input paths - accepts ESRI ASCII raster files or pre-transformed coordinate arrays
- NoData handling - cells with missing data are excluded from the mesh
- Progress reporting - polygon generation supports
IProgress<OperationProgress>for tracking long-running operations
Dependencies
| Package | Description |
|---|---|
| Contour.Core | Core interfaces (IContourGenerator, IContourLines, IContourPolygons) |
| AsciiRaster.Parser | ESRI ASCII raster file parsing |
| NetTopologySuite | Geometry types and spatial operations |
License
MIT - Copyright (c) 2026 Acrotron
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- AsciiRaster.Parser (>= 1.0.1)
- Contour.Core (>= 1.0.4)
- NetTopologySuite (>= 2.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.