.NET Standard 2.0 .NET Framework 3.5
NuGet\Install-Package Spatial4n -Version
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.
dotnet add package Spatial4n --version
<PackageReference Include="Spatial4n" Version="" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Spatial4n --version
#r "nuget: Spatial4n,"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Spatial4n as a Cake Addin
#addin nuget:?package=Spatial4n&version=

// Install Spatial4n as a Cake Tool
#tool nuget:?package=Spatial4n&version=

Spatial4n - A GeoSpatial Library for .NET

Nuget Azure DevOps builds (branch) GitHub GitHub Sponsors

Spatial4n is a general purpose spatial / geospatial library for .NET, a direct port of the spatial4j Java library. Its core capabilities are:

  1. To provide common shapes that can be used in Euclidean and geodesic world models.
  2. To provide distance calculations and other math.
  3. To read and write shapes from formats like WKT.

When working with grid square indexing schemes, you will likely to find something especially useful in Spatial4n.

Shapes and Other Features

The main part of Spatial4n is its collection of shapes. Shapes in Spatial4n have these features:

  • Compute its lat-lon bounding box.
  • Compute an area. For some shapes its more of an estimate.
  • Compute if it contains a provided point.
  • Compute the relationship to a lat-lon rectangle. Relationships are: Contains, Within, Disjoint, Intersects. Note that Spatial4n doesn't have a notion of "touching".

Spatial4n has a variety of shapes that operate in Euclidean-space -- i.e. a flat 2D plane. Most shapes are augmented to support a wrap-around at X -180/+180 for compatibility with latitude & longitudes, which is effectively a cylindrical model. But the real bonus is its circle (i.e. point-radius shape that can operate on a surface-of-a-sphere model. See below for further info. The term "geodetic" or "geodesic" or "geo" is used here as synonymous with that model but technically those words have a more broad meaning.

Shape Euclidean Cylindrical Spherical
Point Y Y Y
Rectangle Y Y Y
Circle Y N Y
LineString Y N N
Buffered L/S Y N N
Polygon Y Y N
ShapeCollection Y Y Y
  • The Rectangle shape exists in the spherical model as a lat-lon rectangle, which basically means it's math is no different than cylindrical.
  • Polygons don't support pole-wrap (sorry, no Antarctica polygon); just dateline-cross. Polygons are supported by wrapping NTS's Geometry, which is to say that most of the fundamental logic for that shape is implemented by NTS.

Other Features

  • Read and write Shapes as WKT. Include the ENVELOPE extension from CQL, plus a Spatial4n custom BUFFER operation. Buffering a point gets you a Circle.
  • 3 great-circle distance calculators: Law of Cosines, Haversine, Vincenty


Currently, the best sources of documentation are the Spatial4j javadocs and the Spatial4j Getting Started section.

Building and Testing

To build the project from source, see the Building and Testing documentation.

Saying Thanks

If you find this library to be useful, please star us on GitHub and consider a financial sponsorship so we can continue bringing you great free tools like this one.

GitHub Sponsors

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Spatial4n:

Package Downloads

Geospatial search for the Lucene.NET full-text search engine library from The Apache Software Foundation. Documentation: This package is part of the Lucene.NET project:


System for benchmarking the Lucene.NET full-text search engine library from The Apache Software Foundation. Documentation: This package is part of the Lucene.NET project:

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Spatial4n:

Repository Stars
ACID Document Database
Apache Lucene.NET
Version Downloads Last updated 71,501 2/11/2022