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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Contour.Core.ContourGenerator.MarchingSquares" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Contour.Core.ContourGenerator.MarchingSquares" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Contour.Core.ContourGenerator.MarchingSquares" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Contour.Core.ContourGenerator.MarchingSquares --version 1.0.6
                    
#r "nuget: Contour.Core.ContourGenerator.MarchingSquares, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Contour.Core.ContourGenerator.MarchingSquares@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Contour.Core.ContourGenerator.MarchingSquares&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Contour.Core.ContourGenerator.MarchingSquares&version=1.0.6
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 85 6/23/2026
1.0.5 128 3/26/2026
1.0.4 105 3/26/2026
1.0.3 99 3/26/2026
1.0.2 100 3/26/2026
1.0.1 98 3/26/2026
1.0.0 112 3/25/2026