Class GeoJson
- Namespace
- SpatialNET.IO
- Assembly
- SpatialNET.IO.dll
Reading and writing GeoJSON (RFC 7946, ADR 0009) via System.Text.Json. Reading goes through the
geometry factory; properties and a crs member are ignored, M values are dropped.
Writing uses the leanest type, with shells counter-clockwise and holes clockwise.
public static class GeoJsonInheritance
Inherited Members
Methods
Read(string, IGeometryFactory?)
Reads a geometry from a Geometry or Feature object.
public static IGeometry2D Read(string json, IGeometryFactory? factory = null)Parameters
jsonstring-
The GeoJSON text.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
Exceptions
- ArgumentNullException
-
jsonisnull. - FormatException
-
Not valid GeoJSON; the message names the JSON path.
- NotSupportedException
-
FeatureCollection or GeometryCollection (use SpatialNET.IO.GeoJson.ReadAll(System.String,SpatialNET.IGeometryFactory) instead).
Read<T>(string, IGeometryFactory?)
Reads a geometry of an expected kind.
public static T Read<T>(string json, IGeometryFactory? factory = null) where T : IGeometry2DParameters
jsonstring-
The GeoJSON text.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
- T
Type Parameters
T-
The expected geometry kind.
Exceptions
- FormatException
-
Not valid GeoJSON or not a geometry of kind
T.
Read(ReadOnlySpan<byte>, IGeometryFactory?)
Reads a geometry from UTF-8 bytes.
public static IGeometry2D Read(ReadOnlySpan<byte> utf8, IGeometryFactory? factory = null)Parameters
utf8ReadOnlySpan<byte>-
The UTF-8 bytes.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
Read(Stream, IGeometryFactory?)
Reads a geometry from a stream (UTF-8).
public static IGeometry2D Read(Stream stream, IGeometryFactory? factory = null)Parameters
streamStream-
The stream.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
ReadAll(string, IGeometryFactory?)
Reads all geometries (Geometry, Feature, FeatureCollection; GeometryCollections are flattened).
public static IReadOnlyList<IGeometry2D> ReadAll(string json, IGeometryFactory? factory = null)Parameters
jsonstring-
The GeoJSON text.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
ReadAll(ReadOnlySpan<byte>, IGeometryFactory?)
Reads all geometries from UTF-8 bytes.
public static IReadOnlyList<IGeometry2D> ReadAll(ReadOnlySpan<byte> utf8, IGeometryFactory? factory = null)Parameters
utf8ReadOnlySpan<byte>-
The UTF-8 bytes.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
ReadAll(Stream, IGeometryFactory?)
Reads all geometries from a stream (UTF-8).
public static IReadOnlyList<IGeometry2D> ReadAll(Stream stream, IGeometryFactory? factory = null)Parameters
streamStream-
The stream.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
ToFeatureCollection(IEnumerable<IGeometry2D>, GeoJsonOptions?)
Writes geometries as a FeatureCollection with empty properties.
public static string ToFeatureCollection(IEnumerable<IGeometry2D> geometries, GeoJsonOptions? options = null)Parameters
geometriesIEnumerable<IGeometry2D>-
The geometries.
optionsGeoJsonOptions?-
The options;
null= SpatialNET.IO.GeoJsonOptions.Default.
Returns
ToGeoJson(IGeometry2D, GeoJsonOptions?)
Writes the geometry as a GeoJSON Geometry object.
public static string ToGeoJson(this IGeometry2D geometry, GeoJsonOptions? options = null)Parameters
geometryIGeometry2D-
The geometry.
optionsGeoJsonOptions?-
The options;
null= SpatialNET.IO.GeoJsonOptions.Default.
Returns
Exceptions
- ArgumentNullException
-
geometryisnull. - NotSupportedException
-
Coordinates are
NaN/infinite (not representable in JSON) or the geometry kind is unknown.
WriteTo(IGeometry2D, Utf8JsonWriter, GeoJsonOptions?)
Writes the geometry as a GeoJSON Geometry object to a System.Text.Json.Utf8JsonWriter.
public static void WriteTo(this IGeometry2D geometry, Utf8JsonWriter writer, GeoJsonOptions? options = null)Parameters
geometryIGeometry2D-
The geometry.
writerUtf8JsonWriter-
The writer.
optionsGeoJsonOptions?-
The options;
null= SpatialNET.IO.GeoJsonOptions.Default.