-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathCrsMap.cs
More file actions
59 lines (49 loc) · 1.45 KB
/
CrsMap.cs
File metadata and controls
59 lines (49 loc) · 1.45 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
namespace Npgsql.GeoJSON;
/// <summary>
/// A map of entries that map the authority to the inclusive range of SRID.
/// </summary>
public partial class CrsMap
{
readonly CrsMapEntry[]? _overridden;
internal CrsMap(CrsMapEntry[]? overridden)
=> _overridden = overridden;
internal string? GetAuthority(int srid)
=> GetAuthority(_overridden, srid) ?? GetAuthority(WellKnown, srid);
static string? GetAuthority(CrsMapEntry[]? entries, int srid)
{
if (entries == null)
return null;
var left = 0;
var right = entries.Length;
while (left <= right)
{
var middle = left + (right - left) / 2;
var entry = entries[middle];
if (srid < entry.MinSrid)
right = middle - 1;
else
if (srid > entry.MaxSrid)
left = middle + 1;
else
return entry.Authority;
}
return null;
}
}
/// <summary>
/// An entry which maps the authority to the inclusive range of SRID.
/// </summary>
readonly struct CrsMapEntry
{
internal readonly int MinSrid;
internal readonly int MaxSrid;
internal readonly string? Authority;
internal CrsMapEntry(int minSrid, int maxSrid, string? authority)
{
MinSrid = minSrid;
MaxSrid = maxSrid;
Authority = authority != null
? string.IsInterned(authority) ?? authority
: null;
}
}