-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathNpgsqlGeoJSONExtensions.cs
More file actions
66 lines (61 loc) · 3.51 KB
/
NpgsqlGeoJSONExtensions.cs
File metadata and controls
66 lines (61 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Npgsql.GeoJSON;
using Npgsql.GeoJSON.Internal;
using Npgsql.TypeMapping;
// ReSharper disable once CheckNamespace
namespace Npgsql;
/// <summary>
/// Extension allowing adding the GeoJSON plugin to an Npgsql type mapper.
/// </summary>
public static class NpgsqlGeoJSONExtensions
{
// Note: defined for binary compatibility and NpgsqlConnection.GlobalTypeMapper.
/// <summary>
/// Sets up GeoJSON mappings for the PostGIS types.
/// </summary>
/// <param name="mapper">The type mapper to set up (global or connection-specific)</param>
/// <param name="options">Options to use when constructing objects.</param>
/// <param name="geographyAsDefault">Specifies that the geography type is used for mapping by default.</param>
public static INpgsqlTypeMapper UseGeoJson(this INpgsqlTypeMapper mapper, GeoJSONOptions options = GeoJSONOptions.None, bool geographyAsDefault = false)
{
mapper.AddTypeInfoResolverFactory(new GeoJSONTypeInfoResolverFactory(options, geographyAsDefault, crsMap: null));
return mapper;
}
// Note: defined for binary compatibility and NpgsqlConnection.GlobalTypeMapper.
/// <summary>
/// Sets up GeoJSON mappings for the PostGIS types.
/// </summary>
/// <param name="mapper">The type mapper to set up (global or connection-specific)</param>
/// <param name="crsMap">A custom crs map that might contain more or less entries than the default well-known crs map.</param>
/// <param name="options">Options to use when constructing objects.</param>
/// <param name="geographyAsDefault">Specifies that the geography type is used for mapping by default.</param>
public static INpgsqlTypeMapper UseGeoJson(this INpgsqlTypeMapper mapper, CrsMap crsMap, GeoJSONOptions options = GeoJSONOptions.None, bool geographyAsDefault = false)
{
mapper.AddTypeInfoResolverFactory(new GeoJSONTypeInfoResolverFactory(options, geographyAsDefault, crsMap));
return mapper;
}
/// <summary>
/// Sets up GeoJSON mappings for the PostGIS types.
/// </summary>
/// <param name="mapper">The type mapper to set up (global or connection-specific)</param>
/// <param name="options">Options to use when constructing objects.</param>
/// <param name="geographyAsDefault">Specifies that the geography type is used for mapping by default.</param>
public static TMapper UseGeoJson<TMapper>(this TMapper mapper, GeoJSONOptions options = GeoJSONOptions.None, bool geographyAsDefault = false)
where TMapper : INpgsqlTypeMapper
{
mapper.AddTypeInfoResolverFactory(new GeoJSONTypeInfoResolverFactory(options, geographyAsDefault, crsMap: null));
return mapper;
}
/// <summary>
/// Sets up GeoJSON mappings for the PostGIS types.
/// </summary>
/// <param name="mapper">The type mapper to set up (global or connection-specific)</param>
/// <param name="crsMap">A custom crs map that might contain more or less entries than the default well-known crs map.</param>
/// <param name="options">Options to use when constructing objects.</param>
/// <param name="geographyAsDefault">Specifies that the geography type is used for mapping by default.</param>
public static TMapper UseGeoJson<TMapper>(this TMapper mapper, CrsMap crsMap, GeoJSONOptions options = GeoJSONOptions.None, bool geographyAsDefault = false)
where TMapper : INpgsqlTypeMapper
{
mapper.AddTypeInfoResolverFactory(new GeoJSONTypeInfoResolverFactory(options, geographyAsDefault, crsMap));
return mapper;
}
}