-
-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathPositionExtensions.cs
More file actions
37 lines (36 loc) · 1.18 KB
/
PositionExtensions.cs
File metadata and controls
37 lines (36 loc) · 1.18 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
using System;
using System.Collections.Generic;
using GeoJSON.Net.Geometry;
namespace GeoJSON.Net
{
internal static class PositionExtensions
{
internal static Position ToPosition(this IEnumerable<double> coordinates)
{
using (var enumerator = coordinates.GetEnumerator())
{
double lat, lng, alt;
if (!enumerator.MoveNext())
{
throw new ArgumentException("Expected 2 or 3 coordinates but got 0");
}
lng = enumerator.Current;
if (!enumerator.MoveNext())
{
throw new ArgumentException("Expected 2 or 3 coordinates but got 1");
}
lat = enumerator.Current;
if (!enumerator.MoveNext())
{
return new Position(lat, lng);
}
alt = enumerator.Current;
if (enumerator.MoveNext())
{
throw new ArgumentException("Expected 2 or 3 coordinates but got >= 4");
}
return new Position(lat, lng, alt);
}
}
}
}