forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeoPackageTest.cs
More file actions
115 lines (92 loc) · 4.31 KB
/
GeoPackageTest.cs
File metadata and controls
115 lines (92 loc) · 4.31 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
using System;
using System.Collections.ObjectModel;
using System.IO;
using GeoAPI.Geometries;
using NetTopologySuite;
using NUnit.Framework;
using SharpMap.Data;
using SharpMap.Data.Providers;
using SharpMap.Layers;
namespace UnitTests.Data.Providers
{
public class GeoPackageTest
{
[OneTimeSetUp]
public void OneTimeSetUp()
{
GeoAPI.GeometryServiceProvider.Instance = new NtsGeometryServices();
}
[TestCase(@"geonames_belgium.gpkg")]
[TestCase(@"gdal_sample.gpkg")]
[TestCase(@"haiti-vectors-split.gpkg")]
[TestCase(@"simple_sewer_features.gpkg")]
public void TestGeoPackage(string filePath)
{
if (!Path.IsPathRooted(filePath))
filePath = TestUtility.GetPathToTestFile(filePath);
if (!File.Exists(filePath))
throw new IgnoreException(string.Format("Test data not present: '{0}'!", filePath));
GeoPackage gpkg = null;
Assert.DoesNotThrow(() => gpkg = GeoPackage.Open(filePath), "Opened did not prove to be a valid geo package");
Assert.Greater(gpkg.Features.Count + gpkg.Tiles.Count, 0);
foreach (var feature in gpkg.Features)
{
IProvider p = null;
Assert.DoesNotThrow(() => p = gpkg.GetFeatureProvider(feature));
TestProvider(p, feature);
ILayer l = null;
Assert.DoesNotThrow(() => l = gpkg.GetFeatureLayer(feature));
}
}
private static void TestProvider(IProvider provider, GpkgContent content)
{
int numFeatures = 0;
Assert.DoesNotThrow(() => numFeatures = provider.GetFeatureCount(),
"GetFeatureCount threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
var extent = provider.GetExtents();
Collection<uint> oids = null;
Assert.DoesNotThrow(() => oids = provider.GetObjectIDsInView(extent),
"GetObjectIDsInView threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
if (numFeatures > 0)
Assert.IsTrue(oids.Count > 0);
var tmpFeatures = 0;
foreach (var oid in oids)
{
if (tmpFeatures > 50) break;
IGeometry geom = null;
Assert.DoesNotThrow(() => geom = provider.GetGeometryByID(oid),
"GetGeometryByID threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
FeatureDataRow feat = null;
Assert.DoesNotThrow(() => feat = provider.GetFeature(oid),
"GetFeature threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
if (geom != null)
Assert.IsTrue(geom.EqualsExact(feat.Geometry));
tmpFeatures++;
}
Collection<IGeometry> geoms = null;
Assert.DoesNotThrow(() => geoms = provider.GetGeometriesInView(extent),
"GetGeometriesInView threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
if (numFeatures > 0)
{
Assert.IsTrue(geoms.Count > 0,
"GetGeometriesInView with full extent did not return 90% of the geometries:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
}
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => provider.ExecuteIntersectionQuery(extent, fds),
"ExecuteIntersectionQuery threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
if (numFeatures > 0)
{
Assert.IsTrue(fds.Tables[0].Rows.Count > 0,
"ExecuteIntersectionQuery with full extent did not return 90% of the features:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
}
}
}
}