GeoJson Class
Reads and writes GeoJSON (RFC 7946): a FeatureCollection, a Feature or a geometry.
public static class GeoJsonRemarks
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
| Name | Description |
|---|---|
| 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.csWrites features as a GeoJSON FeatureCollection.
public static string Format(GeoFeatureCollection features, GeoJsonWriterOptions? options = null)Parameters
featuresGeoFeatureCollection- The features.
optionsGeoJsonWriterOptions?- The options, or
nullfor the defaults.
Returns
string The GeoJSON text.
Exceptions
ArgumentException- A position is not finite.
FormatGeometry(GeoGeometry, GeoJsonWriterOptions?)
GeoJson.csWrites a geometry as GeoJSON.
public static string FormatGeometry(GeoGeometry geometry, GeoJsonWriterOptions? options = null)Parameters
geometryGeoGeometry- The geometry.
optionsGeoJsonWriterOptions?- The options, or
nullfor the defaults.
Returns
string The GeoJSON text of the geometry.
Exceptions
ArgumentException- A position is not finite.
Parse(string)
GeoJson.csReads the features of a GeoJSON document.
public static GeoFeatureCollection Parse(string json)Parameters
jsonstring- 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.csReads a GeoJSON geometry, such as {"type":"Point","coordinates":[2.35,48.86]}.
public static GeoGeometry ParseGeometry(string json)Parameters
jsonstring- 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.csReads the features of a GeoJSON document.
public static GeoFeatureCollection Read(Stream utf8Json)Parameters
utf8JsonStream- 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.csWrites features as a GeoJSON FeatureCollection, encoded in UTF-8.
public static void Write(GeoFeatureCollection features, Stream utf8Json, GeoJsonWriterOptions? options = null)Parameters
featuresGeoFeatureCollection- The features.
utf8JsonStream- The stream to write to. It is left open.
optionsGeoJsonWriterOptions?- The options, or
nullfor the defaults.
Exceptions
ArgumentException- A position is not finite.