-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeogragraphicStringFormatter
125 lines (94 loc) · 3.5 KB
/
GeogragraphicStringFormatter
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
[Route("PutZipCode"), HttpPost]
public HttpResponseMessage InsertZipCode(ZipCodePutRequest model)
{
if (!ModelState.IsValid && model != null)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
string input = model.Polygon;
var sequence = new List<GeoCoordinate>();
var endCall = new { };
var Key = new Key();
var multi = false;
var list = input.Split(' ');
var length = list.Length;
var count = 0;
foreach (var set in list)
{
var pair = set.Split(',');
if (pair.Length > 3)
{
var lonOne = pair[0];
var latOne = pair[1];
var bundle = pair[2].Split('<');
var latTwo = pair[3];
var Break = bundle[1].Split('>');
var lonTwo = Break[1];
Key.startCall = @"MULTIPOLYGON(((";
Key.endCall = @")))";
GeoCoordinate coordinate1 = new GeoCoordinate();
GeoCoordinate coordinate2 = new GeoCoordinate();
coordinate2.Longitude = "((" + lonTwo;
coordinate2.Latitude = latTwo;
coordinate1.Longitude = lonOne;
coordinate1.Latitude = latOne + "))";
sequence.Add(coordinate1);
sequence.Add(coordinate2);
multi = true;
}
else
{
GeoCoordinate coordinate = new GeoCoordinate();
var lon = pair[0];
var lat = pair[1];
if (count == 0)
{
var split = lon.Split('\"');
coordinate.Longitude = split[0];
}
else
{
coordinate.Longitude = lon;
}
if (count == (length - 1))
{
var split = lat.Split('\"');
coordinate.Latitude = split[0];
}
else
{
coordinate.Latitude = lat;
}
sequence.Add(coordinate);
}
count++;
}
if (multi == true)
{
}
else
{
Key.startCall = @"POLYGON((";
Key.endCall = @"))";
}
var coordinates = new List<GeoCoordinate>();
var countSecond = 0;
var sb = new StringBuilder();
foreach (var coordinate in sequence)
{
if (countSecond == 0)
{
sb.Append(Key.startCall + coordinate.Longitude + " " + coordinate.Latitude);
}
else
{
sb.Append("," + coordinate.Longitude + " " + coordinate.Latitude);
}
countSecond++;
}
sb.Append(Key.endCall);
model.Polygon = sb.ToString();
_schoolService.PutZipCode(model);
SuccessResponse response = new SuccessResponse();
return Request.CreateResponse(HttpStatusCode.OK, response);
}