forked from PomeloFoundation/dotNETCore-Extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolyLine.cs
More file actions
57 lines (52 loc) · 1.6 KB
/
Copy pathPolyLine.cs
File metadata and controls
57 lines (52 loc) · 1.6 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace System
{
public class PolyLine : List<Point>
{
public PolyLine()
{
}
public PolyLine(ICollection<Point> pts)
{
this.AddRange(pts);
ConvertPoints();
}
public double Circumference
{
get
{
ConvertPoints();
double c = 0;
for (var i = 0; i < this.Count - 1; i++)
c += this[i].GetDistance(this[i + 1]);
return c;
}
}
private void ConvertPoints()
{
if (this.Count > 0)
{
var first = this.First();
for (var i = 0; i < this.Count; i++)
{
if (this[i].Type != first.Type)
{
if (first.Type == PointType.None)
throw new NotSupportedException($"不支持{this[i].Type}与{first.Type}混合构成折线");
else if (first.Type == PointType.WGS)
this[i] = this[i].ToWgsPoint();
else if (first.Type == PointType.GCJ)
this[i] = this[i].ToGcjPoint();
else
this[i] = this[i].ToBaiduPoint();
}
}
}
}
public Point Begin { get { return this.First(); } }
public Point End { get { return this.Last(); } }
}
}