Skip to content

Commit ad05dea

Browse files
committed
updated samples
1 parent 7852986 commit ad05dea

2 files changed

Lines changed: 80 additions & 70 deletions

File tree

  • samples

samples/PolylineAlgorithm.NetTopologySuite.Sample/Program.cs

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,41 @@
66
using NetTopologySuite.Geometries;
77
using PolylineAlgorithm.NetTopologySuite.Sample;
88

9-
// Sample route: Seattle → Bellevue → Redmond
10-
var points = new Point[]
11-
{
12-
new(x: -122.3503, y: 47.6219), // Seattle (x = longitude, y = latitude)
13-
new(x: -122.2015, y: 47.6101), // Bellevue
14-
new(x: -122.1215, y: 47.6740), // Redmond
15-
};
16-
17-
var encoder = new NetTopologyPolylineEncoder();
18-
var decoder = new NetTopologyPolylineDecoder();
19-
20-
// Encode
21-
string encoded = encoder.Encode(points);
22-
23-
Console.WriteLine("=== NetTopologySuite Polyline Sample ===");
24-
Console.WriteLine();
25-
Console.WriteLine("Input points (longitude, latitude):");
26-
foreach (Point p in points)
27-
{
28-
Console.WriteLine($" ({p.X}, {p.Y})");
29-
}
30-
Console.WriteLine();
31-
Console.WriteLine($"Encoded polyline: {encoded}");
32-
Console.WriteLine();
33-
34-
// Decode
35-
IEnumerable<Point> decoded = decoder.Decode(encoded);
36-
37-
Console.WriteLine("Decoded points (longitude, latitude):");
38-
foreach (Point p in decoded)
39-
{
40-
Console.WriteLine($" ({p.X}, {p.Y})");
41-
}
9+
public class Program {
10+
public static void Main(string[] args) {
11+
// Sample route: Seattle → Bellevue → Redmond
12+
var points = new Point[]
13+
{
14+
new(x: -122.3503, y: 47.6219), // Seattle (x = longitude, y = latitude)
15+
new(x: -122.2015, y: 47.6101), // Bellevue
16+
new(x: -122.1215, y: 47.6740), // Redmond
17+
};
18+
19+
var encoder = new NetTopologyPolylineEncoder();
20+
var decoder = new NetTopologyPolylineDecoder();
21+
22+
// Encode
23+
string encoded = encoder.Encode(points);
24+
25+
Console.WriteLine("=== NetTopologySuite Polyline Sample ===");
26+
Console.WriteLine();
27+
Console.WriteLine("Input points (longitude, latitude):");
28+
29+
foreach (Point p in points) {
30+
Console.WriteLine($" ({p.X}, {p.Y})");
31+
}
32+
33+
Console.WriteLine();
34+
Console.WriteLine($"Encoded polyline: {encoded}");
35+
Console.WriteLine();
36+
37+
// Decode
38+
IEnumerable<Point> decoded = decoder.Decode(encoded);
39+
40+
Console.WriteLine("Decoded points (longitude, latitude):");
41+
42+
foreach (Point p in decoded) {
43+
Console.WriteLine($" ({p.X}, {p.Y})");
44+
}
45+
}
46+
}

samples/PolylineAlgorithm.SensorData.Sample/Program.cs

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,45 @@
55

66
using PolylineAlgorithm.SensorData.Sample;
77

8-
// Sample temperature readings from a sensor over six seconds
9-
var readings = new SensorReading[]
10-
{
11-
new(DateTimeOffset.UtcNow, 23.5),
12-
new(DateTimeOffset.UtcNow.AddSeconds(1), 23.7),
13-
new(DateTimeOffset.UtcNow.AddSeconds(2), 24.1),
14-
new(DateTimeOffset.UtcNow.AddSeconds(3), 25.0),
15-
new(DateTimeOffset.UtcNow.AddSeconds(4), 24.8),
16-
new(DateTimeOffset.UtcNow.AddSeconds(5), 24.8),
17-
new(DateTimeOffset.UtcNow.AddSeconds(6), 22.3),
18-
};
19-
20-
var encoder = new SensorDataEncoder();
21-
var decoder = new SensorDataDecoder();
22-
23-
// Encode
24-
string encoded = encoder.Encode(readings);
25-
26-
Console.WriteLine("=== Sensor Data Polyline Sample ===");
27-
Console.WriteLine();
28-
Console.WriteLine("Input readings:");
29-
foreach (SensorReading r in readings)
30-
{
31-
Console.WriteLine($" [{r.Timestamp:HH:mm:ss}] {r.Temperature:F1} °C");
32-
}
33-
Console.WriteLine();
34-
Console.WriteLine($"Encoded polyline: {encoded}");
35-
Console.WriteLine();
36-
37-
// Decode (timestamps and temperatures are both recovered)
38-
IEnumerable<SensorReading> decoded = decoder.Decode(encoded);
39-
40-
Console.WriteLine("Decoded readings:");
41-
foreach (SensorReading r in decoded)
42-
{
43-
Console.WriteLine($" [{r.Timestamp:HH:mm:ss}] {r.Temperature:F1} °C");
44-
}
8+
public static class Program {
9+
public static void Main(string[] args) {
10+
// Sample temperature readings from a sensor over six seconds
11+
var readings = new SensorReading[]
12+
{
13+
new(DateTimeOffset.UtcNow, 23.5),
14+
new(DateTimeOffset.UtcNow.AddSeconds(1), 23.7),
15+
new(DateTimeOffset.UtcNow.AddSeconds(2), 24.1),
16+
new(DateTimeOffset.UtcNow.AddSeconds(3), 25.0),
17+
new(DateTimeOffset.UtcNow.AddSeconds(4), 24.8),
18+
new(DateTimeOffset.UtcNow.AddSeconds(5), 24.8),
19+
new(DateTimeOffset.UtcNow.AddSeconds(6), 22.3),
20+
};
21+
22+
var encoder = new SensorDataEncoder();
23+
var decoder = new SensorDataDecoder();
24+
25+
// Encode
26+
string encoded = encoder.Encode(readings);
27+
28+
Console.WriteLine("=== Sensor Data Polyline Sample ===");
29+
Console.WriteLine();
30+
Console.WriteLine("Input readings:");
31+
32+
foreach (SensorReading r in readings) {
33+
Console.WriteLine($" [{r.Timestamp:HH:mm:ss}] {r.Temperature:F1} °C");
34+
}
35+
36+
Console.WriteLine();
37+
Console.WriteLine($"Encoded polyline: {encoded}");
38+
Console.WriteLine();
39+
40+
// Decode (timestamps and temperatures are both recovered)
41+
IEnumerable<SensorReading> decoded = decoder.Decode(encoded);
42+
43+
Console.WriteLine("Decoded readings:");
44+
45+
foreach (SensorReading r in decoded) {
46+
Console.WriteLine($" [{r.Timestamp:HH:mm:ss}] {r.Temperature:F1} °C");
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)