-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFeatureTests.cs
More file actions
116 lines (105 loc) · 4.32 KB
/
Copy pathFeatureTests.cs
File metadata and controls
116 lines (105 loc) · 4.32 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
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
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace NETMapnik.Test
{
[TestClass]
public class FeatureTests
{
[TestMethod]
public void Featureset_Creation()
{
Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
Dictionary<string, object> options = new Dictionary<string, object>()
{
{ "type","shape"},
{ "file", @".\data\world_merc.shp" }
};
Datasource d = new Datasource(options);
Featureset fs = d.Featureset();
Feature feature = fs.Next();
Dictionary<string, object> attr = new Dictionary<string, object>(feature.Attributes());
Dictionary<string, object> expectedAttr = new Dictionary<string, object>()
{
{"AREA", 44L},
{"FIPS", "AC"},
{"ISO2", "AG"},
{"ISO3", "ATG"},
{"LAT", 17.078},
{"LON", -61.783},
{"NAME", "Antigua and Barbuda"},
{"POP2005", 83039L},
{"REGION", 19L},
{"SUBREGION", 29L},
{"UN", 28L}
};
CollectionAssert.AreEquivalent(attr, expectedAttr);
int count = 1;
while (fs.Next() != null)
{
count++;
}
Assert.AreEqual(count, 245);
}
[TestMethod]
public void Feature_ToJSON()
{
string input = @"{
type: ""Feature"",
properties: {},
geometry: {
type: ""Polygon"",
coordinates: [[[1,1],[1,2],[2,2],[2,1],[1,1]]]
}
}";
JObject expected = JObject.Parse(input);
Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "csv.input"));
Dictionary<string, object> options = new Dictionary<string, object>()
{
{ "type","csv"},
{ "inline", "geojson\n'" + expected["geometry"].ToString(Formatting.None) + "'" }
};
Datasource ds = new Datasource(options);
Feature f = ds.Featureset().Next();
JObject feature = JObject.Parse(f.ToJSON());
Assert.AreEqual(expected["type"], feature["type"]);
Assert.AreEqual(((JObject)expected["properties"]).Count, ((JObject)feature["properties"]).Count);
Assert.AreEqual(expected["geometry"]["type"], feature["geometry"]["type"]);
JArray coords = (JArray)expected["geometry"]["coordinates"][0];
for (int i = 0; i < coords.Count; i++)
{
JArray coord1 = (JArray)expected["geometry"]["coordinates"][0][i];
JArray coord2 = (JArray)feature["geometry"]["coordinates"][0][i];
CollectionAssert.AreEquivalent(coord1.ToObject<List<double>>(), coord2.ToObject<List<double>>());
}
}
[TestMethod]
public void Feature_FromJSON()
{
string input = @"{
type: ""Feature"",
properties: {},
geometry: {
type: ""Polygon"",
coordinates: [[[1,1],[1,2],[2,2],[2,1],[1,1]]]
}
}";
JObject expected = JObject.Parse(input);
Feature f = Feature.FromJSON(expected.ToString(Formatting.None));
JObject feature = JObject.Parse(f.ToJSON());
Assert.AreEqual(expected["type"], feature["type"]);
Assert.AreEqual(((JObject)expected["properties"]).Count, ((JObject)feature["properties"]).Count);
Assert.AreEqual(expected["geometry"]["type"], feature["geometry"]["type"]);
JArray coords = (JArray)expected["geometry"]["coordinates"][0];
for (int i = 0; i < coords.Count; i++)
{
JArray coord1 = (JArray)expected["geometry"]["coordinates"][0][i];
JArray coord2 = (JArray)feature["geometry"]["coordinates"][0][i];
CollectionAssert.AreEquivalent(coord1.ToObject<List<double>>(), coord2.ToObject<List<double>>());
}
}
}
}