-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
3,485 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/NetTopologySuite.IO.GeoJSON4STJ/Converters/GeoJsonConverterFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using NetTopologySuite.Features; | ||
using NetTopologySuite.Geometries; | ||
|
||
namespace NetTopologySuite.IO.Converters | ||
{ | ||
/// <inheritdoc cref="JsonConverterFactory"/>> | ||
public class GeoJsonConverterFactory : JsonConverterFactory | ||
{ | ||
/// <summary> | ||
/// The default name that, when seen on <see cref="IAttributesTable"/> or the "properties" | ||
/// object of a feature, indicates that it should "really" be the feature's "id", not stored | ||
/// in "properties" as-is. | ||
/// </summary> | ||
public static readonly string DefaultIdPropertyName = "_NetTopologySuite_id"; | ||
|
||
private static readonly HashSet<Type> GeometryTypes = new HashSet<Type> | ||
{ | ||
typeof(Geometry), | ||
typeof(Point), | ||
typeof(LineString), | ||
typeof(Polygon), | ||
typeof(MultiPoint), | ||
typeof(MultiLineString), | ||
typeof(MultiPolygon), | ||
typeof(GeometryCollection), | ||
}; | ||
|
||
private readonly GeometryFactory _factory; | ||
|
||
private readonly bool _writeGeometryBBox; | ||
|
||
private readonly string _idPropertyName; | ||
|
||
/// <summary> | ||
/// Creates an instance of this class using the defaults. | ||
/// </summary> | ||
public GeoJsonConverterFactory() | ||
: this(NtsGeometryServices.Instance.CreateGeometryFactory(4326), false) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates an instance of this class using the provided <see cref="GeometryFactory"/> and | ||
/// defaults for other values. | ||
/// </summary> | ||
/// <param name="factory"></param> | ||
public GeoJsonConverterFactory(GeometryFactory factory) | ||
: this(factory, false) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates an instance of this class using the provided <see cref="GeometryFactory"/>, the | ||
/// given value for whether or not we should write out a "bbox" for a plain geometry, and | ||
/// defaults for all other values. | ||
/// </summary> | ||
/// <param name="factory"></param> | ||
/// <param name="writeGeometryBBox"></param> | ||
public GeoJsonConverterFactory(GeometryFactory factory, bool writeGeometryBBox) | ||
: this(factory, writeGeometryBBox, DefaultIdPropertyName) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates an instance of this class using the provided <see cref="GeometryFactory"/>, the | ||
/// given value for whether or not we should write out a "bbox" for a plain geometry, and | ||
/// the given "magic" string to signal when an <see cref="IAttributesTable"/> property is | ||
/// actually filling in for a Feature's "id". | ||
/// </summary> | ||
/// <param name="factory"></param> | ||
/// <param name="writeGeometryBBox"></param> | ||
/// <param name="idPropertyName"></param> | ||
public GeoJsonConverterFactory(GeometryFactory factory, bool writeGeometryBBox, string idPropertyName) | ||
{ | ||
_factory = factory; | ||
_writeGeometryBBox = writeGeometryBBox; | ||
_idPropertyName = idPropertyName ?? DefaultIdPropertyName; | ||
} | ||
|
||
///<inheritdoc cref="JsonConverter.CanConvert(Type)"/> | ||
public override bool CanConvert(Type typeToConvert) | ||
{ | ||
return GeometryTypes.Contains(typeToConvert) | ||
|| typeof(IFeature).IsAssignableFrom(typeToConvert) | ||
|| typeToConvert == typeof(FeatureCollection) | ||
|| typeof(IAttributesTable).IsAssignableFrom(typeToConvert); | ||
} | ||
|
||
///<inheritdoc cref="JsonConverterFactory.CreateConverter(Type, JsonSerializerOptions)"/> | ||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (GeometryTypes.Contains(typeToConvert)) | ||
return new StjGeometryConverter(_factory, _writeGeometryBBox); | ||
if (typeToConvert == typeof(FeatureCollection)) | ||
return new StjFeatureCollectionConverter(); | ||
if (typeof(IFeature).IsAssignableFrom(typeToConvert)) | ||
return new StjFeatureConverter(_idPropertyName); | ||
if (typeof(IAttributesTable).IsAssignableFrom(typeToConvert)) | ||
return new StjAttributesTableConverter(_idPropertyName); | ||
|
||
throw new ArgumentException(nameof(typeToConvert)); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/NetTopologySuite.IO.GeoJSON4STJ/Converters/GeoJsonObjectType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace NetTopologySuite.IO.Converters | ||
{ | ||
/// <summary> | ||
/// Defines the GeoJSON Objects types as defined in the <a href="https://tools.ietf.org/html/rfc7946#section-3.1">RFC7946 of the Internet Engineering Task Force (IETF)</a>. | ||
/// </summary> | ||
internal enum GeoJsonObjectType | ||
{ | ||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.1.2">Point</a> type. | ||
/// </summary> | ||
Point, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.1.3">MultiPoint</a> type. | ||
/// </summary> | ||
MultiPoint, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.1.4">LineString</a> type. | ||
/// </summary> | ||
LineString, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.1.5">MultiLineString</a> type. | ||
/// </summary> | ||
MultiLineString, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.1.6">Polygon</a> type. | ||
/// </summary> | ||
Polygon, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.1.7">MultiPolygon</a> type. | ||
/// </summary> | ||
MultiPolygon, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.1.8">GeometryCollection</a> type. | ||
/// </summary> | ||
GeometryCollection, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.2">Feature</a> type. | ||
/// </summary> | ||
Feature, | ||
|
||
/// <summary> | ||
/// Defines the <a href="https://tools.ietf.org/html/rfc7946#section-3.3">FeatureCollection</a> type. | ||
/// </summary> | ||
FeatureCollection | ||
} | ||
} |
Oops, something went wrong.