GeoJson Class

Reads and writes GeoJSON (RFC 7946): a FeatureCollection, a Feature or a geometry.

public static class GeoJson

Remarks

The reader keeps the altitudes, ignores the bbox and the foreign members, except the name of a FeatureCollection, which becomes GeoFeatureCollection.Name. The properties are a String, a Double, a Boolean, null, or a JsonElement for an object or an array. A numeric id becomes its JSON text.

The writer writes the identifiers as strings, the numbers as JSON numbers (null when they are not finite), a JsonElement as it is, a dictionary as an object, a collection as an array, and the other values as their text.

Methods

NameDescription
Format(GeoFeatureCollection, GeoJsonWriterOptions?)Writes features as a GeoJSON FeatureCollection.
FormatGeometry(GeoGeometry, GeoJsonWriterOptions?)Writes a geometry as GeoJSON.
Parse(string)Reads the features of a GeoJSON document.
ParseGeometry(string)Reads a GeoJSON geometry, such as {"type":"Point","coordinates":[2.35,48.86]}.
Read(Stream)Reads the features of a GeoJSON document.
Write(GeoFeatureCollection, Stream, GeoJsonWriterOptions?)Writes features as a GeoJSON FeatureCollection, encoded in UTF-8.

Format(GeoFeatureCollection, GeoJsonWriterOptions?)

GeoJson.cs

Writes features as a GeoJSON FeatureCollection.

public static string Format(GeoFeatureCollection features, GeoJsonWriterOptions? options = null)

Parameters

features GeoFeatureCollection
The features.
options GeoJsonWriterOptions?
The options, or null for the defaults.

Returns

string The GeoJSON text.

Exceptions

ArgumentException
A position is not finite.

FormatGeometry(GeoGeometry, GeoJsonWriterOptions?)

GeoJson.cs

Writes a geometry as GeoJSON.

public static string FormatGeometry(GeoGeometry geometry, GeoJsonWriterOptions? options = null)

Parameters

geometry GeoGeometry
The geometry.
options GeoJsonWriterOptions?
The options, or null for the defaults.

Returns

string The GeoJSON text of the geometry.

Exceptions

ArgumentException
A position is not finite.

Parse(string)

GeoJson.cs

Reads the features of a GeoJSON document.

public static GeoFeatureCollection Parse(string json)

Parameters

json string
The GeoJSON text.

Returns

GeoFeatureCollection The features of a FeatureCollection, the feature of a Feature, or a feature without properties for a geometry.

Exceptions

FormatException
The text is not valid JSON or not GeoJSON.

ParseGeometry(string)

GeoJson.cs

Reads a GeoJSON geometry, such as {"type":"Point","coordinates":[2.35,48.86]}.

public static GeoGeometry ParseGeometry(string json)

Parameters

json string
The GeoJSON text of a geometry.

Returns

GeoGeometry The geometry.

Exceptions

FormatException
The text is not valid JSON or not a GeoJSON geometry.

Read(Stream)

GeoJson.cs

Reads the features of a GeoJSON document.

public static GeoFeatureCollection Read(Stream utf8Json)

Parameters

utf8Json Stream
The GeoJSON document, encoded in UTF-8. It is left open.

Returns

GeoFeatureCollection The features of a FeatureCollection, the feature of a Feature, or a feature without properties for a geometry.

Exceptions

FormatException
The document is not valid JSON or not GeoJSON.

Write(GeoFeatureCollection, Stream, GeoJsonWriterOptions?)

GeoJson.cs

Writes features as a GeoJSON FeatureCollection, encoded in UTF-8.

public static void Write(GeoFeatureCollection features, Stream utf8Json, GeoJsonWriterOptions? options = null)

Parameters

features GeoFeatureCollection
The features.
utf8Json Stream
The stream to write to. It is left open.
options GeoJsonWriterOptions?
The options, or null for the defaults.

Exceptions

ArgumentException
A position is not finite.