Contour.Core.ContourGenerator.MarchingSquares 2.0.5

dotnet add package Contour.Core.ContourGenerator.MarchingSquares --version 2.0.5
                    
NuGet\Install-Package Contour.Core.ContourGenerator.MarchingSquares -Version 2.0.5
                    
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="2.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Contour.Core.ContourGenerator.MarchingSquares" Version="2.0.5" />
                    
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 2.0.5
                    
#r "nuget: Contour.Core.ContourGenerator.MarchingSquares, 2.0.5"
                    
#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@2.0.5
                    
#: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=2.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Contour.Core.ContourGenerator.MarchingSquares&version=2.0.5
                    
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 grid nodes

Build the grid from nodes with their coordinates (projected or transformed, e.g. to WGS84) and the data value as M. To contour an ESRI ASCII raster, read it with a raster parser and pass its cells as nodes:

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
  • Grid nodes as input - any regular grid of nodes with coordinates and values; no file format dependency
  • 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)
NetTopologySuite Geometry types and spatial operations

Version 2

Version 2 removes RasterGrid.FromRaster(EsriAsciiRaster) and with it the dependency on AsciiRaster.Parser (and its transitive ProjNET4GeoAPI, LGPL-2.1), so the package depends only on MIT and BSD-licensed code. Build the grid with RasterGrid.FromNodes instead: node [col, row] at x = x0 + col · cellSize and y = y0 + (nRows − 1 − row) · cellSize, with the cell value as M, gives the same triangles.

License

MIT - Copyright (c) 2026 Acrotron

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
2.0.5 162 9/29/2026
2.0.4 113 9/29/2026
2.0.3 103 9/29/2026
2.0.2 100 9/29/2026
2.0.1 1,366 9/29/2026
1.0.7 134 9/29/2026
1.0.6 177 6/23/2026
1.0.5 159 3/26/2026
1.0.4 133 3/26/2026
1.0.3 126 3/26/2026
1.0.2 129 3/26/2026
1.0.1 130 3/26/2026
1.0.0 146 3/25/2026