-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathCreateKml.cs
More file actions
50 lines (41 loc) · 1.43 KB
/
CreateKml.cs
File metadata and controls
50 lines (41 loc) · 1.43 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
using System;
using SharpKml.Base;
using SharpKml.Dom;
namespace Examples
{
/// <summary>
/// Creates a Point and Placemark and prints the resultant KML on to the console.
/// </summary>
public static class CreateKml
{
public static void Run()
{
Console.WriteLine("Creating a point at 37.42052549 latitude and -122.0816695 longitude.\n");
// This will be used for the placemark
var point = new Point
{
Coordinate = new Vector(37.42052549, -122.0816695)
};
var placemark = new Placemark
{
Name = "Cool Statue",
Geometry = point
};
// This is the root element of the file
var kml = new Kml
{
Feature = placemark
};
var serializer = new Serializer();
serializer.Serialize(kml);
Console.WriteLine(serializer.Xml);
Console.WriteLine("\nReading Xml...");
var parser = new Parser();
parser.ParseString(serializer.Xml, true);
kml = (Kml)parser.Root;
placemark = (Placemark)kml.Feature;
point = (Point)placemark.Geometry;
Console.WriteLine("Latitude:{0} Longitude:{1}", point.Coordinate.Latitude, point.Coordinate.Longitude);
}
}
}