-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathPostGis20SpatialQueriesFixture.cs
121 lines (108 loc) · 3.81 KB
/
PostGis20SpatialQueriesFixture.cs
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
117
118
119
120
121
using NHibernate;
using NHibernate.Cfg;
using NUnit.Framework;
using Tests.NHibernate.Spatial.RandomGeometries;
namespace Tests.NHibernate.Spatial
{
[TestFixture]
public class PostGis20SpatialQueriesFixture : SpatialQueriesFixture
{
[Test]
public override void HqlGeometryType()
{
var results = Session
.CreateQuery(
"select NHSP.GeometryType(l.Geometry) from LineStringEntity as l where l.Geometry is not null")
.List();
foreach (object item in results)
{
string gt = (string) item;
Assert.AreEqual("ST_LINESTRING", gt.ToUpper());
}
results = Session
.CreateQuery("select NHSP.GeometryType(p.Geometry) from PolygonEntity as p where p.Geometry is not null")
.List();
foreach (object item in results)
{
string gt = (string) item;
Assert.AreEqual("ST_POLYGON", gt.ToUpper());
}
}
protected override void Configure(Configuration configuration)
{
TestConfiguration.Configure(configuration);
}
protected override string SqlLineStringFilter(string filterString)
{
return $@"
SELECT count(*)
FROM linestringtest
WHERE the_geom && ST_GeomFromText('{filterString}', 4326)
";
}
protected override string SqlPolygonFilter(string filterString)
{
return $@"
SELECT count(*)
FROM polygontest
WHERE the_geom && ST_GeomFromText('{filterString}', 4326)
";
}
protected override string SqlMultiLineStringFilter(string filterString)
{
return $@"
SELECT count(*)
FROM multilinestringtest
WHERE the_geom && ST_GeomFromText('{filterString}', 4326)
";
}
protected override string SqlOvelapsLineString(string filterString)
{
return $@"
SELECT count(*)
FROM linestringtest
WHERE the_geom IS NOT NULL
AND ST_Overlaps(ST_PolygonFromText('{filterString}', 4326), the_geom)
";
}
protected override string SqlIntersectsLineString(string filterString)
{
return $@"
SELECT count(*)
FROM linestringtest
WHERE the_geom IS NOT NULL
AND ST_Intersects(ST_PolygonFromText('{filterString}', 4326), the_geom)
";
}
protected override ISQLQuery SqlIsEmptyLineString(ISession session)
{
return session.CreateSQLQuery(@"
SELECT ST_IsEmpty(the_geom) as result
FROM linestringtest
WHERE oid = ?
AND the_geom IS NOT NULL
")
.AddScalar("result", NHibernateUtil.Boolean);
}
protected override ISQLQuery SqlIsSimpleLineString(ISession session)
{
return session.CreateSQLQuery(@"
SELECT ST_IsSimple(the_geom) as result
FROM linestringtest
WHERE oid = ?
AND the_geom IS NOT NULL
")
.AddScalar("result", NHibernateUtil.Boolean);
}
protected override ISQLQuery SqlAsBinaryLineString(ISession session)
{
return session.CreateSQLQuery(@"
SELECT ST_AsBinary(the_geom) as result
FROM linestringtest
WHERE oid = ?
AND the_geom IS NOT NULL
")
.AddScalar("result", NHibernateUtil.BinaryBlob);
}
}
}