forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeoJSONHelper.cs
More file actions
45 lines (42 loc) · 1.63 KB
/
GeoJSONHelper.cs
File metadata and controls
45 lines (42 loc) · 1.63 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
namespace SharpMap.Converters.GeoJSON
{
using System;
using System.Collections.Generic;
using SharpMap.Data;
/// <summary>
/// GeoJSON helper class
/// </summary>
public static class GeoJSONHelper
{
/// <summary>
/// Method to convert a <see cref="T:SharpMap.Data.FeatureDataSet"/> to a series of <see cref="GeoJSON"/> objects
/// </summary>
/// <param name="data">The feature dataset</param>
/// <returns>A series of <see cref="GeoJSON"/> objects</returns>
public static IEnumerable<GeoJSON> GetData(FeatureDataSet data)
{
if (data == null)
throw new ArgumentNullException("data");
using (data)
{
foreach (FeatureDataTable table in data.Tables)
{
var columns = table.Columns;
var keys = new string[columns.Count];
for (var i = 0; i < columns.Count; i++)
keys[i] = columns[i].ColumnName;
var rows = table.Rows;
for (int i = 0; i < rows.Count; i++)
{
var row = (FeatureDataRow)rows[i];
var geometry = row.Geometry;
var values = new Dictionary<string, object>();
for (var j = 0; j < keys.Length; j++)
values.Add(keys[j], row[j]);
yield return new GeoJSON(geometry, values);
}
}
}
}
}
}