-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathGeoJSON.cs
More file actions
81 lines (72 loc) · 2.68 KB
/
GeoJSON.cs
File metadata and controls
81 lines (72 loc) · 2.68 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using GeoAPI;
namespace SharpMap.Converters.GeoJSON
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeoAPI.Geometries;
using Newtonsoft.Json;
//ReSharper disable InconsistentNaming
/// <summary>
/// GeoJSON converter class
/// </summary>
[JsonObject(MemberSerialization = MemberSerialization.OptOut, Description = "featureType")]
public class GeoJSON
{
/// <summary>
/// Get an empty GeoJSON object
/// </summary>
public static GeoJSON Empty
{
get
{
var factory = GeometryServiceProvider.Instance.CreateGeometryFactory();
var geometry = factory.CreateGeometryCollection(new IGeometry[0]);
var dictionary = new Dictionary<string, object>();
return new GeoJSON(geometry, dictionary);
}
}
/// <summary>
/// Gets the <see cref="IGeometry"/> object
/// </summary>
public IGeometry Geometry { get; private set; }
/// <summary>
/// Gets the attributes
/// </summary>
public IDictionary<string, object> Values { get; private set; }
/// <summary>
/// Creates an instance of this class from <paramref name="geometry"/> and <paramref name="values"/>.
/// </summary>
/// <param name="geometry">The geometry</param>
/// <param name="values">The attribute values</param>
public GeoJSON(IGeometry geometry, IDictionary<string, object> values)
{
if (values == null)
throw new ArgumentNullException("values");
Geometry = geometry;
Values = values;
}
/// <summary>
/// Method to set <see cref="Geometry"/> to <paramref name="converted"/>
/// </summary>
/// <param name="converted">The converted geometry</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="converted"/> is <value>null</value></exception>
public void SetGeometry(IGeometry converted)
{
if (converted == null)
throw new ArgumentNullException("converted");
Geometry = converted;
}
/// <inheritdoc/>
public override string ToString()
{
var text = Values.Aggregate(new StringBuilder("|"), (sb, i) =>
{
sb.AppendFormat("'{0}'-'{1}'|", i.Key, i.Value);
return sb;
});
return String.Format("Geometry: {0}, Values: {1}", Geometry, text);
}
}
}