PageRenderTime 30ms CodeModel.GetById 50ms RepoModel.GetById 9ms app.codeStats 1ms

/src/NHibernate.Spatial/src/Tests.NHibernate.Spatial/OgcSfSql11Compliance/ConformanceItemsFixture.cs

https://bitbucket.org/dabide/nhcontrib
C# | 2801 lines | 1533 code | 357 blank | 911 comment | 92 complexity | 832f0a4499690af1260e69e99000766c MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, Apache-2.0, LGPL-3.0, LGPL-2.1
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using GeoAPI.Geometries;
  5. using NHibernate;
  6. using NHibernate.Criterion;
  7. using NHibernate.Linq;
  8. using NHibernate.Spatial.Linq;
  9. using NHibernate.Spatial.Metadata;
  10. using NUnit.Framework;
  11. using Tests.NHibernate.Spatial.OgcSfSql11Compliance.Model;
  12. namespace Tests.NHibernate.Spatial.OgcSfSql11Compliance
  13. {
  14. /// <summary>
  15. /// Adaptation of OGC SFSQL 1.1 Compliance Test Suite.
  16. ///
  17. /// All conformance items should be specified as HQL queries
  18. /// (server-side processed) and NTS methods (client-side processed).
  19. /// For example, see <c>ConformanceItemT11</c> and <c>ConformanceItemT11Hql</c>.
  20. /// </summary>
  21. public abstract class ConformanceItemsFixture : AbstractFixture
  22. {
  23. protected override Type[] Mappings
  24. {
  25. get
  26. {
  27. return new Type[] {
  28. typeof(Bridge),
  29. typeof(Building),
  30. typeof(DividedRoute),
  31. typeof(Forest),
  32. typeof(Lake),
  33. typeof(MapNeatline),
  34. typeof(NamedPlace),
  35. typeof(Pond),
  36. typeof(RoadSegment),
  37. typeof(Stream),
  38. };
  39. }
  40. }
  41. private ISession session;
  42. protected override bool CheckDatabaseWasCleanedOnTearDown
  43. {
  44. get { return false; }
  45. }
  46. private const string SpatialReferenceSystemWKT =
  47. @"PROJCS[""UTM_ZONE_14N"", GEOGCS[""World Geodetic System 72"",
  48. DATUM[""WGS_72"", SPHEROID[""NWL_10D"", 6378135, 298.26]],
  49. PRIMEM[""Greenwich"", 0], UNIT[""Meter"", 1.0]],
  50. PROJECTION[""Transverse_Mercator""],
  51. PARAMETER[""False_Easting"", 500000.0],
  52. PARAMETER[""False_Northing"", 0.0],
  53. PARAMETER[""Central_Meridian"", -99.0],
  54. PARAMETER[""Scale_Factor"", 0.9996],
  55. PARAMETER[""Latitude_of_origin"", 0.0],
  56. UNIT[""Meter"", 1.0]]";
  57. protected override void OnBeforeCreateSchema()
  58. {
  59. using (ISession session = sessions.OpenSession())
  60. {
  61. if (Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  62. {
  63. session.Save(new SpatialReferenceSystem(101, "POSC", 32214, SpatialReferenceSystemWKT));
  64. session.Flush();
  65. }
  66. }
  67. }
  68. protected override void OnAfterDropSchema()
  69. {
  70. using (ISession session = sessions.OpenSession())
  71. {
  72. if (Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  73. {
  74. session.Delete("from SpatialReferenceSystem where SRID=101");
  75. session.Flush();
  76. }
  77. }
  78. }
  79. protected override void OnTestFixtureSetUp()
  80. {
  81. using (ISession session = sessions.OpenSession())
  82. {
  83. // Lake
  84. session.Save(new Lake(101, "Blue Lake",
  85. Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18),(59 18,67 18,67 13,59 13,59 18))")));
  86. // RoadSegment
  87. session.Save(new RoadSegment(102, "Route 5", null, 2,
  88. Wkt.Read("LINESTRING( 0 18, 10 21, 16 23, 28 26, 44 31 )")));
  89. session.Save(new RoadSegment(103, "Route 5", "Main Street", 4,
  90. Wkt.Read("LINESTRING( 44 31, 56 34, 70 38 )")));
  91. session.Save(new RoadSegment(104, "Route 5", null, 2,
  92. Wkt.Read("LINESTRING( 70 38, 72 48 )")));
  93. session.Save(new RoadSegment(105, "Main Street", null, 4,
  94. Wkt.Read("LINESTRING( 70 38, 84 42 )")));
  95. session.Save(new RoadSegment(106, "Dirt Road by Green Forest", null, 1,
  96. Wkt.Read("LINESTRING( 28 26, 28 0 )")));
  97. // DividedRoute
  98. session.Save(new DividedRoute(119, "Route 75", 4,
  99. Wkt.Read("MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))")));
  100. // Forest
  101. session.Save(new Forest(109, "Green Forest",
  102. Wkt.Read("MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))")));
  103. // Bridge
  104. session.Save(new Bridge(110, "Cam Bridge",
  105. Wkt.Read("POINT( 44 31 )")));
  106. // Stream
  107. session.Save(new Stream(111, "Cam Stream",
  108. Wkt.Read("LINESTRING( 38 48, 44 41, 41 36, 44 31, 52 18 )")));
  109. session.Save(new Stream(112, null,
  110. Wkt.Read("LINESTRING( 76 0, 78 4, 73 9 )")));
  111. // Building
  112. session.Save(new Building(113, "123 Main Street",
  113. Wkt.Read("POINT( 52 30 )"),
  114. Wkt.Read("POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )")));
  115. session.Save(new Building(114, "215 Main Street",
  116. Wkt.Read("POINT( 64 33 )"),
  117. Wkt.Read("POLYGON( ( 66 34, 62 34, 62 32, 66 32, 66 34) )")));
  118. // Pond
  119. session.Save(new Pond(120, null, "Stock Pond",
  120. Wkt.Read("MULTIPOLYGON( ( ( 24 44, 22 42, 24 40, 24 44) ), ( ( 26 44, 26 40, 28 42, 26 44) ) )")));
  121. // NamedPlace
  122. session.Save(new NamedPlace(117, "Ashton",
  123. Wkt.Read("POLYGON( ( 62 48, 84 48, 84 30, 56 30, 56 34, 62 48) )")));
  124. session.Save(new NamedPlace(118, "Goose Island",
  125. Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )")));
  126. // MapNeatline
  127. session.Save(new MapNeatline(115,
  128. Wkt.Read("POLYGON( ( 0 0, 0 48, 84 48, 84 0, 0 0 ) )")));
  129. session.Flush();
  130. }
  131. }
  132. protected override void OnTestFixtureTearDown()
  133. {
  134. using (ISession session = sessions.OpenSession())
  135. {
  136. DeleteMappings(session);
  137. }
  138. }
  139. protected override void OnSetUp()
  140. {
  141. session = sessions.OpenSession();
  142. }
  143. protected override void OnTearDown()
  144. {
  145. session.Clear();
  146. session.Close();
  147. session.Dispose();
  148. }
  149. #region Queries testing functions in section 3.2.10.2 (T1 - T14)
  150. /// <summary>
  151. /// Conformance Item T1
  152. /// GEOMETRY_COLUMNS table/view is created/updated properly
  153. /// For this test we will check to see that all of the feature tables are
  154. /// represented by entries in the GEOMETRY_COLUMNS table/view
  155. ///
  156. /// ANSWER: lakes, road_segments, divided_routes, buildings, forests, bridges,
  157. /// named_places, streams, ponds, map_neatlines
  158. /// *** ADAPTATION ALERT ***
  159. /// Since there are no quotes around the table names in the CREATE TABLEs,
  160. /// they will be converted to upper case in many DBMSs, and therefore, the
  161. /// answer to this query may be:
  162. /// ANSWER: LAKES, ROAD_SEGMENTS, DIVIDED_ROUTES, BUILDINGS, FORESTS, BRIDGES,
  163. /// NAMED_PLACES, STREAMS, PONDS, MAP_NEATLINES
  164. /// *** ADAPTATION ALERT ***
  165. /// If the implementer made the adaptation concerning the buildings table
  166. /// in sqltsch.sql, then the answer here may differ slightly.
  167. ///
  168. /// Original SQL:
  169. /// <code>
  170. /// SELECT f_table_name
  171. /// FROM geometry_columns;
  172. /// </code>
  173. /// </summary>
  174. [Test]
  175. public void ConformanceItemT01Hql()
  176. {
  177. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  178. {
  179. Assert.Ignore("Provider does not support spatial metadata");
  180. }
  181. string[] tables = new string[] {
  182. "lakes",
  183. "road_segments",
  184. "divided_routes",
  185. "buildings",
  186. "forests",
  187. "bridges",
  188. "named_places",
  189. "streams",
  190. "ponds",
  191. "map_neatlines",
  192. };
  193. IList results = session.CreateQuery("select distinct g.TableName from GeometryColumn g").List();
  194. Assert.AreEqual(tables.Length, results.Count);
  195. foreach (string tableName in results)
  196. {
  197. bool found = (Array.IndexOf<string>(tables, tableName) != -1);
  198. Assert.IsTrue(found);
  199. }
  200. }
  201. /// <summary>
  202. /// Conformance Item T2
  203. /// GEOMETRY_COLUMNS table/view is created/updated properly
  204. /// For this test we will check to see that the correct geometry columns for the
  205. /// streams table is represented in the GEOMETRY_COLUMNS table/view
  206. ///
  207. /// ANSWER: centerline
  208. /// *** ADAPTATION ALERT ***
  209. /// Since there are no quotes around the table name, streams, in it's CREATE TABLE,
  210. /// it will be converted to upper case in many DBMSs, and therefore, the WHERE
  211. /// clause may have to be f_table_name = 'STREAMS'.
  212. ///
  213. /// Original SQL:
  214. /// <code>
  215. /// SELECT f_geometry_column
  216. /// FROM geometry_columns
  217. /// WHERE f_table_name = 'streams';
  218. /// </code>
  219. /// </summary>
  220. [Test]
  221. public void ConformanceItemT02Hql()
  222. {
  223. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  224. {
  225. Assert.Ignore("Provider does not support spatial metadata");
  226. }
  227. var query = session.CreateQuery(@"
  228. select g.Name
  229. from GeometryColumn g
  230. where g.TableName = 'streams'
  231. ");
  232. string result = query.UniqueResult<string>();
  233. Assert.AreEqual("centerline", result);
  234. }
  235. [Test]
  236. public void ConformanceItemT02Linq()
  237. {
  238. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  239. {
  240. Assert.Ignore("Provider does not support spatial metadata");
  241. }
  242. var query =
  243. from g in session.Query<GeometryColumn>()
  244. where g.TableName == "streams"
  245. select g.Name;
  246. string result = query.Single();
  247. Assert.AreEqual("centerline", result);
  248. }
  249. /// <summary>
  250. /// Conformance Item T3
  251. /// GEOMETRY_COLUMNS table/view is created/updated properly
  252. /// For this test we will check to see that the correct coordinate dimension
  253. /// for the streams table is represented in the GEOMETRY_COLUMNS table/view
  254. ///
  255. /// ANSWER: 2
  256. /// *** ADAPTATION ALERT ***
  257. /// Since there are no quotes around the table name, streams, in it's CREATE TABLE,
  258. /// it will be converted to upper case in many DBMSs, and therefore, the WHERE
  259. /// clause may have to be f_table_name = 'STREAMS'.
  260. ///
  261. /// Original SQL:
  262. /// <code>
  263. /// SELECT coord_dimension
  264. /// FROM geometry_columns
  265. /// WHERE f_table_name = 'streams';
  266. /// </code>
  267. /// </summary>
  268. [Test]
  269. public void ConformanceItemT03Hql()
  270. {
  271. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  272. {
  273. Assert.Ignore("Provider does not support spatial metadata");
  274. }
  275. var query = session.CreateQuery(@"
  276. select g.Dimension
  277. from GeometryColumn g
  278. where g.TableName = 'streams'
  279. ");
  280. int result = query.UniqueResult<int>();
  281. Assert.AreEqual(2, result);
  282. }
  283. [Test]
  284. public void ConformanceItemT03Linq()
  285. {
  286. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  287. {
  288. Assert.Ignore("Provider does not support spatial metadata");
  289. }
  290. var query =
  291. from g in session.Query<GeometryColumn >()
  292. where g.TableName == "streams"
  293. select g.Dimension;
  294. int result = query.Single();
  295. Assert.AreEqual(2, result);
  296. }
  297. /// <summary>
  298. /// Conformance Item T4
  299. /// GEOMETRY_COLUMNS table/view is created/updated properly
  300. /// For this test we will check to see that the correct value of srid for
  301. /// the streams table is represented in the GEOMETRY_COLUMNS table/view
  302. ///
  303. /// ANSWER: 101
  304. /// *** ADAPTATION ALERT ***
  305. /// Since there are no quotes around the table name, streams, in it's CREATE TABLE,
  306. /// it will be converted to upper case in many DBMSs, and therefore, the WHERE
  307. /// clause may have to be f_table_name = 'STREAMS'.
  308. ///
  309. /// Original SQL:
  310. /// <code>
  311. /// SELECT srid
  312. /// FROM geometry_columns
  313. /// WHERE f_table_name = 'streams';
  314. /// </code>
  315. /// </summary>
  316. [Test]
  317. public void ConformanceItemT04Hql()
  318. {
  319. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  320. {
  321. Assert.Ignore("Provider does not support spatial metadata");
  322. }
  323. var query = session.CreateQuery(@"
  324. select g.SRID
  325. from GeometryColumn g
  326. where g.TableName = 'streams'
  327. ");
  328. int result = query.UniqueResult<int>();
  329. Assert.AreEqual(101, result);
  330. }
  331. [Test]
  332. public void ConformanceItemT04Linq()
  333. {
  334. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  335. {
  336. Assert.Ignore("Provider does not support spatial metadata");
  337. }
  338. var query =
  339. from g in session.Query<GeometryColumn >()
  340. where g.TableName == "streams"
  341. select g.SRID;
  342. int result = query.Single();
  343. Assert.AreEqual(101, result);
  344. }
  345. /// <summary>
  346. /// Conformance Item T5
  347. /// SPATIAL_REF_SYS table/view is created/updated properly
  348. /// For this test we will check to see that the correct value of srtext is
  349. /// represented in the SPATIAL_REF_SYS table/view
  350. ///
  351. /// ANSWER: 'PROJCS["UTM_ZONE_14N", GEOGCS["World Geodetic System 72",
  352. /// DATUM["WGS_72", SPHEROID["NWL_10D", 6378135, 298.26]],
  353. /// PRIMEM["Greenwich", 0], UNIT["Meter", 1.0]],
  354. /// PROJECTION["Traverse_Mercator"], PARAMETER["False_Easting", 500000.0],
  355. /// PARAMETER["False_Northing", 0.0], PARAMETER["Central_Meridian", -99.0],
  356. /// PARAMETER["Scale_Factor", 0.9996], PARAMETER["Latitude_of_origin", 0.0],
  357. /// UNIT["Meter", 1.0]]'
  358. ///
  359. /// Original SQL:
  360. /// <code>
  361. /// SELECT srtext
  362. /// FROM SPATIAL_REF_SYS
  363. /// WHERE SRID = 101;
  364. /// </code>
  365. /// </summary>
  366. [Test]
  367. public void ConformanceItemT05Hql()
  368. {
  369. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  370. {
  371. Assert.Ignore("Provider does not support spatial metadata");
  372. }
  373. SpatialReferenceSystem srs = session.CreateQuery(
  374. "from SpatialReferenceSystem where SRID=101")
  375. .UniqueResult<SpatialReferenceSystem>();
  376. Assert.IsNotNull(srs);
  377. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  378. // Alternative syntax for identifiers:
  379. srs = session.CreateQuery(
  380. "from SpatialReferenceSystem s where s=101")
  381. .UniqueResult<SpatialReferenceSystem>();
  382. Assert.IsNotNull(srs);
  383. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  384. }
  385. [Test]
  386. public void ConformanceItemT05Linq()
  387. {
  388. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  389. {
  390. Assert.Ignore("Provider does not support spatial metadata");
  391. }
  392. var query =
  393. from s in session.Query<SpatialReferenceSystem>()
  394. where s.SRID == 101
  395. select s;
  396. var srs = query.Single();
  397. Assert.IsNotNull(srs);
  398. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  399. }
  400. [Test]
  401. public void ConformanceItemT05Get()
  402. {
  403. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  404. {
  405. Assert.Ignore("Provider does not support spatial metadata");
  406. }
  407. SpatialReferenceSystem srs = session.Get<SpatialReferenceSystem>(101);
  408. Assert.IsNotNull(srs);
  409. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  410. }
  411. [Test]
  412. public void ConformanceItemT05Criteria()
  413. {
  414. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  415. {
  416. Assert.Ignore("Provider does not support spatial metadata");
  417. }
  418. SpatialReferenceSystem srs = session.CreateCriteria(typeof(SpatialReferenceSystem))
  419. .Add(Restrictions.IdEq(101))
  420. .UniqueResult<SpatialReferenceSystem>();
  421. Assert.IsNotNull(srs);
  422. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  423. }
  424. /// <summary>
  425. /// Conformance Item T6
  426. /// Dimension(g Geometry) : Integer
  427. /// For this test we will determine the dimension of Blue Lake.
  428. ///
  429. /// ANSWER: 2
  430. ///
  431. /// Original SQL:
  432. /// <code>
  433. /// SELECT Dimension(shore)
  434. /// FROM lakes
  435. /// WHERE name = 'Blue Lake';
  436. /// </code>
  437. /// </summary>
  438. [Test]
  439. public void ConformanceItemT06()
  440. {
  441. Lake lake = session.CreateCriteria(typeof(Lake))
  442. .Add(Restrictions.Eq("Name", "Blue Lake"))
  443. .UniqueResult<Lake>();
  444. Assert.AreEqual(2, (int)lake.Shore.Dimension);
  445. }
  446. [Test]
  447. public void ConformanceItemT06Hql()
  448. {
  449. string query =
  450. @"select NHSP.Dimension(t.Shore)
  451. from Lake t
  452. where t.Name = 'Blue Lake'
  453. ";
  454. int result = session.CreateQuery(query)
  455. .UniqueResult<int>();
  456. Assert.AreEqual(2, result);
  457. }
  458. [Test]
  459. public void ConformanceItemT06Linq()
  460. {
  461. var query =
  462. from t in session.Query<Lake>()
  463. where t.Name == "Blue Lake"
  464. select t.Shore.GetDimension();
  465. int result = query.Single();
  466. Assert.AreEqual(2, result);
  467. }
  468. /// <summary>
  469. /// Conformance Item T7
  470. /// GeometryType(g Geometry) : String
  471. /// For this test we will determine the type of Route 75.
  472. ///
  473. /// ANSWER: 9 (which corresponds to 'MULTILINESTRING')
  474. ///
  475. /// Original SQL:
  476. /// <code>
  477. /// SELECT GeometryType(centerlines)
  478. /// FROM lakes
  479. /// WHERE name = 'Route 75';
  480. /// </code>
  481. /// </summary>
  482. /// <remarks>
  483. /// Correction:
  484. /// * Table name should be DIVIDED_ROUTES instead of LAKES
  485. /// </remarks>
  486. [Test]
  487. public void ConformanceItemT07()
  488. {
  489. DividedRoute route = session.CreateCriteria(typeof(DividedRoute))
  490. .Add(Restrictions.Eq("Name", "Route 75"))
  491. .UniqueResult<DividedRoute>();
  492. Assert.AreEqual("MULTILINESTRING", route.Centerlines.GeometryType.ToUpper());
  493. }
  494. [Test]
  495. public void ConformanceItemT07Hql()
  496. {
  497. string query =
  498. @"select NHSP.GeometryType(t.Centerlines)
  499. from DividedRoute t
  500. where t.Name = 'Route 75'
  501. ";
  502. string result = session.CreateQuery(query)
  503. .UniqueResult<string>();
  504. Assert.AreEqual("MULTILINESTRING", result.ToUpper());
  505. }
  506. [Test]
  507. public void ConformanceItemT07Linq()
  508. {
  509. var query =
  510. from t in session.Query<DividedRoute>()
  511. where t.Name == "Route 75"
  512. select t.Centerlines.GeometryType;
  513. string result = query.Single();
  514. Assert.AreEqual("MULTILINESTRING", result.ToUpper());
  515. }
  516. /// <summary>
  517. /// Conformance Item T8
  518. /// AsText(g Geometry) : String
  519. /// For this test we will determine the WKT representation of Goose Island.
  520. ///
  521. /// ANSWER: 'POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )'
  522. ///
  523. /// Original SQL:
  524. /// <code>
  525. /// SELECT AsText(boundary)
  526. /// FROM named_places
  527. /// WHERE name = 'Goose Island';
  528. /// </code>
  529. /// </summary>
  530. [Test]
  531. public void ConformanceItemT08()
  532. {
  533. NamedPlace place = session.CreateCriteria(typeof(NamedPlace))
  534. .Add(Restrictions.Eq("Name", "Goose Island"))
  535. .UniqueResult<NamedPlace>();
  536. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  537. Assert.IsTrue(expected.Equals(place.Boundary));
  538. }
  539. [Test]
  540. public void ConformanceItemT08Hql()
  541. {
  542. string query =
  543. @"select t.Boundary
  544. from NamedPlace t
  545. where t.Name = 'Goose Island'
  546. ";
  547. IGeometry result = session.CreateQuery(query)
  548. .UniqueResult<IGeometry>();
  549. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  550. Assert.IsTrue(expected.Equals(result));
  551. }
  552. [Test]
  553. public void ConformanceItemT08Linq()
  554. {
  555. var query =
  556. from t in session.Query<NamedPlace>()
  557. where t.Name == "Goose Island"
  558. select t.Boundary;
  559. IGeometry result = query.Single();
  560. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  561. Assert.IsTrue(expected.Equals(result));
  562. }
  563. /// <summary>
  564. /// Conformance Item T9
  565. /// AsBinary(g Geometry) : Blob
  566. /// For this test we will determine the WKB representation of Goose Island.
  567. /// We will test by applying AsText to the result of PolygonFromText to the
  568. /// result of AsBinary.
  569. ///
  570. /// ANSWER: 'POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )'
  571. ///
  572. /// Original SQL:
  573. /// <code>
  574. /// SELECT AsText(PolygonFromWKB(AsBinary(boundary)))
  575. /// FROM named_places
  576. /// WHERE name = 'Goose Island';
  577. /// </code>
  578. /// </summary>
  579. [Test]
  580. public void ConformanceItemT09Hql()
  581. {
  582. string query =
  583. @"select NHSP.AsText(NHSP.PolyFromWKB(NHSP.AsBinary(t.Boundary), 0))
  584. from NamedPlace t
  585. where t.Name = 'Goose Island'
  586. ";
  587. string result = session.CreateQuery(query)
  588. .UniqueResult<string>();
  589. IGeometry geometry = Wkt.Read(result);
  590. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  591. Assert.IsTrue(expected.Equals(geometry));
  592. }
  593. [Test]
  594. [Ignore("TODO: ToPolygon")]
  595. public void ConformanceItemT09Linq()
  596. {
  597. var query =
  598. from t in session.Query<NamedPlace>()
  599. where t.Name == "Goose Island"
  600. select t.Boundary.AsBinary().ToPolygon(0);
  601. IGeometry geometry = query.Single();
  602. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  603. Assert.IsTrue(expected.Equals(geometry));
  604. }
  605. /// <summary>
  606. /// Conformance Item T10
  607. /// SRID(g Geometry) : Integer
  608. /// For this test we will determine the SRID of Goose Island.
  609. ///
  610. /// ANSWER: 101
  611. ///
  612. /// Original SQL:
  613. /// <code>
  614. /// SELECT SRID(boundary)
  615. /// FROM named_places
  616. /// WHERE name = 'Goose Island';
  617. /// </code>
  618. /// </summary>
  619. [Test]
  620. public void ConformanceItemT10Hql()
  621. {
  622. string query =
  623. @"select NHSP.SRID(t.Boundary)
  624. from NamedPlace t
  625. where t.Name = 'Goose Island'
  626. ";
  627. int result = session.CreateQuery(query)
  628. .UniqueResult<int>();
  629. Assert.AreEqual(101, result);
  630. }
  631. [Test]
  632. public void ConformanceItemT10Linq()
  633. {
  634. var query =
  635. from t in session.Query<NamedPlace>()
  636. where t.Name == "Goose Island"
  637. select t.Boundary.SRID;
  638. int result = query.Single();
  639. Assert.AreEqual(101, result);
  640. }
  641. /// <summary>
  642. /// Conformance Item T11
  643. /// IsEmpty(g Geometry) : Integer
  644. /// For this test we will determine whether the geometry of a
  645. /// segment of Route 5 is empty.
  646. ///
  647. /// ANSWER: 0
  648. /// *** Adaptation Alert ***
  649. /// If the implementer provides IsEmpty as a boolean function, instead of as
  650. /// an INTEGER function, then:
  651. /// ANSWER: FALSE or 'f'
  652. ///
  653. /// Original SQL:
  654. /// <code>
  655. /// SELECT IsEmpty(centerline)
  656. /// FROM road_segments
  657. /// WHERE name = 'Route 5' AND aliases = 'Main Street';
  658. /// </code>
  659. /// </summary>
  660. [Test]
  661. public void ConformanceItemT11()
  662. {
  663. RoadSegment entity = session.CreateCriteria(typeof(RoadSegment))
  664. .Add(Restrictions.Eq("Name", "Route 5"))
  665. .Add(Restrictions.Eq("Aliases", "Main Street"))
  666. .UniqueResult<RoadSegment>();
  667. Assert.IsFalse(entity.Centerline.IsEmpty);
  668. }
  669. [Test]
  670. public void ConformanceItemT11Hql()
  671. {
  672. string query =
  673. @"select NHSP.IsEmpty(t.Centerline)
  674. from RoadSegment t
  675. where t.Name = 'Route 5' and t.Aliases = 'Main Street'
  676. ";
  677. bool result = session.CreateQuery(query)
  678. .UniqueResult<bool>();
  679. Assert.IsFalse(result);
  680. }
  681. [Test]
  682. public void ConformanceItemT11Linq()
  683. {
  684. var query =
  685. from t in session.Query<RoadSegment>()
  686. where t.Name == "Route 5" && t.Aliases == "Main Street"
  687. select t.Centerline.IsEmpty;
  688. bool result = query.Single();
  689. Assert.IsFalse(result);
  690. }
  691. /// <summary>
  692. /// Conformance Item T12
  693. /// IsSimple(g Geometry) : Integer
  694. /// For this test we will determine whether the geometry of a
  695. /// segment of Blue Lake is simple.
  696. ///
  697. /// ANSWER: 1
  698. /// *** Adaptation Alert ***
  699. /// If the implementer provides IsSimple as a boolean function, instead of as
  700. /// an INTEGER function, then:
  701. /// ANSWER: TRUE or 't'
  702. ///
  703. /// Original SQL:
  704. /// <code>
  705. /// SELECT IsSimple(shore)
  706. /// FROM lakes
  707. /// WHERE name = 'Blue Lake';
  708. /// </code>
  709. /// </summary>
  710. [Test]
  711. public void ConformanceItemT12()
  712. {
  713. Lake entity = session.CreateCriteria(typeof(Lake))
  714. .Add(Restrictions.Eq("Name", "Blue Lake"))
  715. .UniqueResult<Lake>();
  716. Assert.IsTrue(entity.Shore.IsSimple);
  717. }
  718. [Test]
  719. public void ConformanceItemT12Hql()
  720. {
  721. string query =
  722. @"select NHSP.IsSimple(t.Shore)
  723. from Lake t
  724. where t.Name = 'Blue Lake'
  725. ";
  726. bool result = session.CreateQuery(query)
  727. .UniqueResult<bool>();
  728. Assert.IsTrue(result);
  729. }
  730. [Test]
  731. public void ConformanceItemT12Linq()
  732. {
  733. var query =
  734. from t in session.Query<Lake>()
  735. where t.Name == "Blue Lake"
  736. select t.Shore.IsSimple;
  737. bool result = query.Single();
  738. Assert.IsTrue(result);
  739. }
  740. /// <summary>
  741. /// Conformance Item T13
  742. /// Boundary(g Geometry) : Geometry
  743. /// For this test we will determine the boundary of Goose Island.
  744. /// NOTE: The boundary result is as defined in 3.12.3.2 of 96-015R1.
  745. ///
  746. /// ANSWER: 'LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )'
  747. ///
  748. /// Original SQL:
  749. /// <code>
  750. /// SELECT AsText(Boundary((boundary))
  751. /// FROM named_places
  752. /// WHERE name = 'Goose Island';
  753. /// </code>
  754. /// </summary>
  755. [Test]
  756. public void ConformanceItemT13()
  757. {
  758. NamedPlace entity = session.CreateCriteria(typeof(NamedPlace))
  759. .Add(Restrictions.Eq("Name", "Goose Island"))
  760. .UniqueResult<NamedPlace>();
  761. IGeometry expected = Wkt.Read("LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )");
  762. Assert.IsTrue(expected.Equals(entity.Boundary.Boundary));
  763. }
  764. [Test]
  765. public void ConformanceItemT13Hql()
  766. {
  767. string query =
  768. @"select NHSP.AsText(NHSP.Boundary(t.Boundary))
  769. from NamedPlace t
  770. where t.Name = 'Goose Island'
  771. ";
  772. string result = session.CreateQuery(query)
  773. .UniqueResult<string>();
  774. IGeometry geometry = Wkt.Read(result);
  775. IGeometry expected = Wkt.Read("LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )");
  776. Assert.IsTrue(expected.Equals(geometry));
  777. }
  778. [Test]
  779. public void ConformanceItemT13Linq()
  780. {
  781. var query =
  782. from t in session.Query<NamedPlace>()
  783. where t.Name == "Goose Island"
  784. select t.Boundary.Boundary;
  785. IGeometry geometry = query.Single();
  786. IGeometry expected = Wkt.Read("LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )");
  787. Assert.IsTrue(expected.Equals(geometry));
  788. }
  789. /// <summary>
  790. /// Conformance Item T14
  791. /// Envelope(g Geometry) : Geometry
  792. /// For this test we will determine the envelope of Goose Island.
  793. ///
  794. /// ANSWER: 'POLYGON( ( 59 13, 59 18, 67 18, 67 13, 59 13) )'
  795. ///
  796. /// Original SQL:
  797. /// <code>
  798. /// SELECT AsText(Envelope((boundary))
  799. /// FROM named_places
  800. /// WHERE name = 'Goose Island';
  801. /// </code>
  802. /// </summary>
  803. [Test]
  804. public void ConformanceItemT14Hql()
  805. {
  806. string query =
  807. @"select NHSP.AsText(NHSP.Envelope(t.Boundary))
  808. from NamedPlace t
  809. where t.Name = 'Goose Island'
  810. ";
  811. string result = session.CreateQuery(query)
  812. .UniqueResult<string>();
  813. IGeometry geometry = Wkt.Read(result);
  814. IGeometry expected = Wkt.Read("POLYGON( ( 59 13, 59 18, 67 18, 67 13, 59 13) )");
  815. Assert.IsTrue(expected.Equals(geometry));
  816. }
  817. [Test]
  818. public void ConformanceItemT14Linq()
  819. {
  820. var query =
  821. from t in session.Query<NamedPlace>()
  822. where t.Name == "Goose Island"
  823. select t.Boundary.Envelope;
  824. IGeometry geometry = query.Single();
  825. IGeometry expected = Wkt.Read("POLYGON( ( 59 13, 59 18, 67 18, 67 13, 59 13) )");
  826. Assert.IsTrue(expected.Equals(geometry));
  827. }
  828. #endregion
  829. #region Queries testing functions in section 3.2.11.2 (T15 - T16)
  830. /// <summary>
  831. /// Conformance Item T15
  832. /// X(p Point) : Double Precision
  833. /// For this test we will determine the X coordinate of Cam Bridge.
  834. ///
  835. /// ANSWER: 44.00
  836. ///
  837. /// Original SQL:
  838. /// <code>
  839. /// SELECT X(position)
  840. /// FROM bridges
  841. /// WHERE name = 'Bridges';
  842. /// </code>
  843. /// </summary>
  844. /// <remarks>
  845. /// Correction:
  846. /// * Bridge name should be 'Cam Bridge'
  847. /// </remarks>
  848. [Test]
  849. public void ConformanceItemT15Hql()
  850. {
  851. string query =
  852. @"select NHSP.X(t.Position)
  853. from Bridge t
  854. where t.Name = 'Cam Bridge'
  855. ";
  856. double result = session.CreateQuery(query)
  857. .UniqueResult<double>();
  858. Assert.AreEqual(44, result);
  859. }
  860. [Test]
  861. public void ConformanceItemT15Linq()
  862. {
  863. var query =
  864. from t in session.Query<Bridge>()
  865. where t.Name == "Cam Bridge"
  866. select ((IPoint)t.Position).X;
  867. double result = query.Single();
  868. Assert.AreEqual(44, result);
  869. }
  870. /// <summary>
  871. /// Conformance Item T16
  872. /// Y(p Point) : Double Precision
  873. /// For this test we will determine the Y coordinate of Cam Bridge.
  874. ///
  875. /// ANSWER: 31.00
  876. ///
  877. /// Original SQL:
  878. /// <code>
  879. /// SELECT Y(position)
  880. /// FROM bridges
  881. /// WHERE name = 'Bridges';
  882. /// </code>
  883. /// </summary>
  884. /// <remarks>
  885. /// Correction:
  886. /// * Bridge name should be 'Cam Bridge'
  887. /// </remarks>
  888. [Test]
  889. public void ConformanceItemT16Hql()
  890. {
  891. string query =
  892. @"select NHSP.Y(t.Position)
  893. from Bridge t
  894. where t.Name = 'Cam Bridge'
  895. ";
  896. double result = session.CreateQuery(query)
  897. .UniqueResult<double>();
  898. Assert.AreEqual(31, result);
  899. }
  900. [Test]
  901. public void ConformanceItemT16Linq()
  902. {
  903. var query =
  904. from t in session.Query<Bridge >()
  905. where t.Name == "Cam Bridge"
  906. select ((IPoint)t.Position).Y;
  907. double result = query.Single();
  908. Assert.AreEqual(31, result);
  909. }
  910. #endregion
  911. #region Queries testing functions in section 3.2.12.2 (T17 - T21)
  912. /// <summary>
  913. /// Conformance Item T17
  914. /// StartPoint(c Curve) : Point
  915. /// For this test we will determine the start point of road segment 102.
  916. ///
  917. /// ANSWER: 'POINT( 0 18 )'
  918. ///
  919. /// Original SQL:
  920. /// <code>
  921. /// SELECT AsText(StartPoint(centerline))
  922. /// FROM road_segments
  923. /// WHERE fid = 102;
  924. /// </code>
  925. /// </summary>
  926. [Test]
  927. public void ConformanceItemT17Hql()
  928. {
  929. string query =
  930. @"select NHSP.AsText(NHSP.StartPoint(t.Centerline))
  931. from RoadSegment t
  932. where t.Fid = 102
  933. ";
  934. string result = session.CreateQuery(query)
  935. .UniqueResult<string>();
  936. IGeometry geometry = Wkt.Read(result);
  937. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  938. Assert.IsTrue(expected.Equals(geometry));
  939. }
  940. [Test]
  941. public void ConformanceItemT17Linq()
  942. {
  943. var query =
  944. from t in session.Query<RoadSegment>()
  945. where t.Fid == 102
  946. select ((ICurve)t.Centerline).StartPoint;
  947. IGeometry geometry = query.Single();
  948. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  949. Assert.IsTrue(expected.Equals(geometry));
  950. }
  951. /// <summary>
  952. /// Conformance Item T18
  953. /// EndPoint(c Curve) : Point
  954. /// For this test we will determine the end point of road segment 102.
  955. ///
  956. /// ANSWER: 'POINT( 44 31 )'
  957. ///
  958. /// Original SQL:
  959. /// <code>
  960. /// SELECT AsText(EndPoint(centerline))
  961. /// FROM road_segments
  962. /// WHERE fid = 102;
  963. /// </code>
  964. /// </summary>
  965. [Test]
  966. public void ConformanceItemT18Hql()
  967. {
  968. string query =
  969. @"select NHSP.AsText(NHSP.EndPoint(t.Centerline))
  970. from RoadSegment t
  971. where t.Fid = 102
  972. ";
  973. string result = session.CreateQuery(query)
  974. .UniqueResult<string>();
  975. IGeometry geometry = Wkt.Read(result);
  976. IGeometry expected = Wkt.Read("POINT( 44 31 )");
  977. Assert.IsTrue(expected.Equals(geometry));
  978. }
  979. [Test]
  980. public void ConformanceItemT18Linq()
  981. {
  982. var query =
  983. from t in session.Query<RoadSegment>()
  984. where t.Fid == 102
  985. select ((ICurve)t.Centerline).EndPoint;
  986. IGeometry geometry = query.Single();
  987. IGeometry expected = Wkt.Read("POINT( 44 31 )");
  988. Assert.IsTrue(expected.Equals(geometry));
  989. }
  990. /// <summary>
  991. /// Conformance Item T19
  992. /// IsClosed(c Curve) : Integer
  993. /// For this test we will determine the boundary of Goose Island.
  994. ///
  995. /// ANSWER: 1
  996. /// *** Adaptation Alert ***
  997. /// If the implementer provides IsClosed as a boolean function, instead of as
  998. /// an INTEGER function, then:
  999. /// ANSWER: TRUE or 't'
  1000. ///
  1001. /// Original SQL:
  1002. /// <code>
  1003. /// SELECT IsClosed(Boundary(boundary))
  1004. /// FROM named_places
  1005. /// WHERE name = 'Goose Island';
  1006. /// </code>
  1007. /// </summary>
  1008. [Test]
  1009. public void ConformanceItemT19Hql()
  1010. {
  1011. string query =
  1012. @"select NHSP.IsClosed(NHSP.Boundary(t.Boundary))
  1013. from NamedPlace t
  1014. where t.Name = 'Goose Island'
  1015. ";
  1016. bool result = session.CreateQuery(query)
  1017. .UniqueResult<bool>();
  1018. Assert.IsTrue(result);
  1019. }
  1020. [Test]
  1021. public void ConformanceItemT19Linq()
  1022. {
  1023. var query =
  1024. from t in session.Query<NamedPlace>()
  1025. where t.Name == "Goose Island"
  1026. select ((ICurve)t.Boundary.Boundary).IsClosed;
  1027. bool result = query.Single();
  1028. Assert.IsTrue(result);
  1029. }
  1030. /// <summary>
  1031. /// Conformance Item T20
  1032. /// IsRing(c Curve) : Integer
  1033. /// For this test we will determine the boundary of Goose Island.
  1034. ///
  1035. /// ANSWER: 1
  1036. /// *** Adaptation Alert ***
  1037. /// If the implementer provides IsRing as a boolean function, instead of as
  1038. /// an INTEGER function, then:
  1039. /// ANSWER: TRUE or 't'
  1040. ///
  1041. /// Original SQL:
  1042. /// <code>
  1043. /// SELECT IsRing(Boundary(boundary))
  1044. /// FROM named_places
  1045. /// WHERE name = 'Goose Island';
  1046. /// </code>
  1047. /// </summary>
  1048. [Test]
  1049. public void ConformanceItemT20Hql()
  1050. {
  1051. string query =
  1052. @"select NHSP.IsRing(NHSP.Boundary(t.Boundary))
  1053. from NamedPlace t
  1054. where t.Name = 'Goose Island'
  1055. ";
  1056. bool result = session.CreateQuery(query)
  1057. .UniqueResult<bool>();
  1058. Assert.IsTrue(result);
  1059. }
  1060. [Test]
  1061. public void ConformanceItemT20Linq()
  1062. {
  1063. var query =
  1064. from t in session.Query<NamedPlace>()
  1065. where t.Name == "Goose Island"
  1066. select ((ICurve)t.Boundary.Boundary).IsRing;
  1067. bool result = query.Single();
  1068. Assert.IsTrue(result);
  1069. }
  1070. /// <summary>
  1071. /// Conformance Item T21
  1072. /// Length(c Curve) : Double Precision
  1073. /// For this test we will determine the length of road segment 106.
  1074. ///
  1075. /// ANSWER: 26.00 (meters)
  1076. ///
  1077. /// Original SQL:
  1078. /// <code>
  1079. /// SELECT Length(centerline)
  1080. /// FROM road_segments
  1081. /// WHERE fid = 106;
  1082. /// </code>
  1083. /// </summary>
  1084. [Test]
  1085. public void ConformanceItemT21Hql()
  1086. {
  1087. string query =
  1088. @"select NHSP.Length(t.Centerline)
  1089. from RoadSegment t
  1090. where t.Fid = 106
  1091. ";
  1092. double result = session.CreateQuery(query)
  1093. .UniqueResult<double>();
  1094. Assert.AreEqual(26, result);
  1095. }
  1096. [Test]
  1097. public void ConformanceItemT21Linq()
  1098. {
  1099. var query =
  1100. from t in session.Query<RoadSegment>()
  1101. where t.Fid == 106
  1102. select t.Centerline.Length;
  1103. double result = query.Single();
  1104. Assert.AreEqual(26, result);
  1105. }
  1106. #endregion
  1107. #region Queries testing functions in section 3.2.13.2 (T22 - T23)
  1108. /// <summary>
  1109. /// Conformance Item T22
  1110. /// NumPoints(l LineString) : Integer
  1111. /// For this test we will determine the number of points in road segment 102.
  1112. ///
  1113. /// ANSWER: 5
  1114. ///
  1115. /// Original SQL:
  1116. /// <code>
  1117. /// SELECT NumPoints(centerline)
  1118. /// FROM road_segments
  1119. /// WHERE fid = 102;
  1120. /// </code>
  1121. /// </summary>
  1122. [Test]
  1123. public void ConformanceItemT22Hql()
  1124. {
  1125. string query =
  1126. @"select NHSP.NumPoints(t.Centerline)
  1127. from RoadSegment t
  1128. where t.Fid = 102
  1129. ";
  1130. int result = session.CreateQuery(query)
  1131. .UniqueResult<int>();
  1132. Assert.AreEqual(5, result);
  1133. }
  1134. [Test]
  1135. public void ConformanceItemT22Linq()
  1136. {
  1137. var query =
  1138. from t in session.Query<RoadSegment>()
  1139. where t.Fid == 102
  1140. select t.Centerline.NumPoints;
  1141. int result = query.Single();
  1142. Assert.AreEqual(5, result);
  1143. }
  1144. /// <summary>
  1145. /// Conformance Item T23
  1146. /// PointN(l LineString, n Integer) : Point
  1147. /// For this test we will determine the 1st point in road segment 102.
  1148. ///
  1149. /// ANSWER: 'POINT( 0 18 )'
  1150. ///
  1151. /// Original SQL:
  1152. /// <code>
  1153. /// SELECT AsText(PointN(centerline, 1))
  1154. /// FROM road_segments
  1155. /// WHERE fid = 102;
  1156. /// </code>
  1157. /// </summary>
  1158. [Test]
  1159. public void ConformanceItemT23Hql()
  1160. {
  1161. string query =
  1162. @"select NHSP.AsText(NHSP.PointN(t.Centerline, 1))
  1163. from RoadSegment t
  1164. where t.Fid = 102
  1165. ";
  1166. string result = session.CreateQuery(query)
  1167. .UniqueResult<string>();
  1168. IGeometry geometry = Wkt.Read(result);
  1169. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  1170. Assert.IsTrue(expected.Equals(geometry));
  1171. }
  1172. [Test]
  1173. public void ConformanceItemT23Linq()
  1174. {
  1175. var query =
  1176. from t in session.Query<RoadSegment>()
  1177. where t.Fid == 102
  1178. select ((ILineString)t.Centerline).GetPointN(0);
  1179. IGeometry geometry = query.Single();
  1180. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  1181. Assert.IsTrue(expected.Equals(geometry));
  1182. }
  1183. #endregion
  1184. #region Queries testing functions in section 3.2.14. (T24 - T26)
  1185. /// <summary>
  1186. /// Conformance Item T24
  1187. /// Centroid(s Surface) : Point
  1188. /// For this test we will determine the centroid of Goose Island.
  1189. ///
  1190. /// ANSWER: 'POINT( 63 15.5 )'
  1191. ///
  1192. /// Original SQL:
  1193. /// <code>
  1194. /// SELECT AsText(Centroid(boundary))
  1195. /// FROM named_places
  1196. /// WHERE name = 'Goose Island';
  1197. /// </code>
  1198. /// </summary>
  1199. [Test]
  1200. public void ConformanceItemT24Hql()
  1201. {
  1202. string query =
  1203. @"select NHSP.AsText(NHSP.Centroid(t.Boundary))
  1204. from NamedPlace t
  1205. where t.Name = 'Goose Island'
  1206. ";
  1207. string result = session.CreateQuery(query)
  1208. .UniqueResult<string>();
  1209. IGeometry geometry = Wkt.Read(result);
  1210. IGeometry expected = Wkt.Read("POINT( 63 15.5 )");
  1211. Assert.IsTrue(expected.Equals(geometry));
  1212. }
  1213. [Test]
  1214. public void ConformanceItemT24Linq()
  1215. {
  1216. var query =
  1217. from t in session.Query<NamedPlace>()
  1218. where t.Name == "Goose Island"
  1219. select t.Boundary.Centroid;
  1220. IGeometry geometry = query.Single();
  1221. IGeometry expected = Wkt.Read("POINT( 63 15.5 )");
  1222. Assert.IsTrue(expected.Equals(geometry));
  1223. }
  1224. /// <summary>
  1225. /// Conformance Item T25
  1226. /// PointOnSurface(s Surface) : Point
  1227. /// For this test we will determine a point on Goose Island.
  1228. /// NOTE: For this test we will have to uses the Contains function
  1229. /// (which we don't test until later).
  1230. ///
  1231. /// ANSWER: 1
  1232. /// *** Adaptation Alert ***
  1233. /// If the implementer provides Contains as a boolean function, instead of as
  1234. /// an INTEGER function, then:
  1235. /// ANSWER: TRUE or 't'
  1236. ///
  1237. /// Original SQL:
  1238. /// <code>
  1239. /// SELECT Contains(boundary, PointOnSurface(boundary))
  1240. /// FROM named_places
  1241. /// WHERE name = 'Goose Island';
  1242. /// </code>
  1243. /// </summary>
  1244. [Test]
  1245. public void ConformanceItemT25()
  1246. {
  1247. NamedPlace entity = session.CreateCriteria(typeof(NamedPlace))
  1248. .Add(Restrictions.Eq("Name", "Goose Island"))
  1249. .UniqueResult<NamedPlace>();
  1250. Assert.IsTrue(entity.Boundary.Contains(entity.Boundary.PointOnSurface));
  1251. }
  1252. [Test]
  1253. public void ConformanceItemT25Hql()
  1254. {
  1255. string query =
  1256. @"select NHSP.Contains(t.Boundary, NHSP.PointOnSurface(t.Boundary))
  1257. from NamedPlace t
  1258. where t.Name = 'Goose Island'
  1259. ";
  1260. bool result = session.CreateQuery(query)
  1261. .UniqueResult<bool>();
  1262. Assert.IsTrue(result);
  1263. }
  1264. [Test]
  1265. public void ConformanceItemT25Linq()
  1266. {
  1267. var query =
  1268. from t in session.Query<NamedPlace>()
  1269. where t.Name == "Goose Island"
  1270. select t.Boundary.Contains(t.Boundary.PointOnSurface);
  1271. bool result = query.Single();
  1272. Assert.IsTrue(result);
  1273. }
  1274. /// <summary>
  1275. /// Conformance Item T26
  1276. /// Area(s Surface) : Double Precision
  1277. /// For this test we will determine the area of Goose Island.
  1278. ///
  1279. /// ANSWER: 40.00 (square meters)
  1280. ///
  1281. /// Original SQL:
  1282. /// <code>
  1283. /// SELECT Area(boundary)
  1284. /// FROM named_places
  1285. /// WHERE name = 'Goose Island';
  1286. /// </code>
  1287. /// </summary>
  1288. [Test]
  1289. public void ConformanceItemT26Hql()
  1290. {
  1291. string query =
  1292. @"select NHSP.Area(t.Boundary)
  1293. from NamedPlace t
  1294. where t.Name = 'Goose Island'
  1295. ";
  1296. double result = session.CreateQuery(query)
  1297. .UniqueResult<double>();
  1298. Assert.AreEqual(40, result);
  1299. }
  1300. [Test]
  1301. public void ConformanceItemT26Linq()
  1302. {
  1303. var query =
  1304. from t in session.Query<NamedPlace>()
  1305. where t.Name == "Goose Island"
  1306. select t.Boundary.Area;
  1307. double result = query.Single();
  1308. Assert.AreEqual(40, result);
  1309. }
  1310. #endregion
  1311. #region Queries testing functions in section 3.2.15.2 (T27 - T29)
  1312. /// <summary>
  1313. /// Conformance Item T27
  1314. /// ExteriorRing(p Polygon) : LineString
  1315. /// For this test we will determine the exteroir ring of Blue Lake.
  1316. ///
  1317. /// ANSWER: 'LINESTRING(52 18, 66 23, 73 9, 48 6, 52 18)'
  1318. ///
  1319. /// Original SQL:
  1320. /// <code>
  1321. /// SELECT AsText(ExteriorRing(shore))
  1322. /// FROM lakes
  1323. /// WHERE name = 'Blue Lake';
  1324. /// </code>
  1325. /// </summary>
  1326. [Test]
  1327. public void ConformanceItemT27Hql()
  1328. {
  1329. string query =
  1330. @"select NHSP.AsText(NHSP.ExteriorRing(t.Shore))
  1331. from Lake t
  1332. where t.Name = 'Blue Lake'
  1333. ";
  1334. string result = session.CreateQuery(query)
  1335. .UniqueResult<string>();
  1336. IGeometry geometry = Wkt.Read(result);
  1337. IGeometry expected = Wkt.Read("LINESTRING(52 18, 66 23, 73 9, 48 6, 52 18)");
  1338. Assert.IsTrue(expected.Equals(geometry));
  1339. }
  1340. [Test]
  1341. public void ConformanceItemT27Linq()
  1342. {
  1343. var query =
  1344. from t in session.Query<Lake>()
  1345. where t.Name == "Blue Lake"
  1346. select ((IPolygon)t.Shore).ExteriorRing;
  1347. IGeometry geometry = query.Single();
  1348. IGeometry expected = Wkt.Read("LINESTRING(52 18, 66 23, 73 9, 48 6, 52 18)");
  1349. Assert.IsTrue(expected.Equals(geometry));
  1350. }
  1351. /// <summary>
  1352. /// Conformance Item T28
  1353. /// NumInteriorRings(p Polygon) : Integer
  1354. /// For this test we will determine the number of interior rings of Blue Lake.
  1355. ///
  1356. /// ANSWER: 1
  1357. ///
  1358. /// Original SQL:
  1359. /// <code>
  1360. /// SELECT NumInteriorRings(shore)
  1361. /// FROM lakes
  1362. /// WHERE name = 'Blue Lake';
  1363. /// </code>
  1364. /// </summary>
  1365. [Test]
  1366. public void ConformanceItemT28Hql()
  1367. {
  1368. string query =
  1369. @"select NHSP.NumInteriorRings(t.Shore)
  1370. from Lake t
  1371. where t.Name = 'Blue Lake'
  1372. ";
  1373. int result = session.CreateQuery(query)
  1374. .UniqueResult<int>();
  1375. Assert.AreEqual(1, result);
  1376. }
  1377. [Test]
  1378. public void ConformanceItemT28Linq()
  1379. {
  1380. var query =
  1381. from t in session.Query<Lake>()
  1382. where t.Name == "Blue Lake"
  1383. select ((IPolygon)t.Shore).NumInteriorRings;
  1384. int result = query.Single();
  1385. Assert.AreEqual(1, result);
  1386. }
  1387. /// <summary>
  1388. /// Conformance Item T29
  1389. /// InteriorRingN(p Polygon, n Integer) : LineString
  1390. /// For this test we will determine the first interior ring of Blue Lake.
  1391. ///
  1392. /// ANSWER: 'LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)'
  1393. ///
  1394. /// Original SQL:
  1395. /// <code>
  1396. /// SELECT AsText(InteriorRingN(shore, 1))
  1397. /// FROM lakes
  1398. /// WHERE name = 'Blue Lake';
  1399. /// </code>
  1400. /// </summary>
  1401. [Test]
  1402. public void ConformanceItemT29()
  1403. {
  1404. Lake entity = session.CreateCriteria(typeof(Lake))
  1405. .Add(Restrictions.Eq("Name", "Blue Lake"))
  1406. .UniqueResult<Lake>();
  1407. IGeometry geometry = (entity.Shore as IPolygon).InteriorRings[0];
  1408. IGeometry expected = Wkt.Read("LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)");
  1409. Assert.IsTrue(expected.Equals(geometry));
  1410. }
  1411. [Test]
  1412. public void ConformanceItemT29Hql()
  1413. {
  1414. string query =
  1415. @"select NHSP.AsText(NHSP.InteriorRingN(t.Shore, 1))
  1416. from Lake t
  1417. where t.Name = 'Blue Lake'
  1418. ";
  1419. string result = session.CreateQuery(query)
  1420. .UniqueResult<string>();
  1421. IGeometry geometry = Wkt.Read(result);
  1422. IGeometry expected = Wkt.Read("LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)");
  1423. Assert.IsTrue(expected.Equals(geometry));
  1424. }
  1425. [Test]
  1426. public void ConformanceItemT29Linq()
  1427. {
  1428. var query =
  1429. from t in session.Query<Lake>()
  1430. where t.Name == "Blue Lake"
  1431. select ((IPolygon)t.Shore).GetInteriorRingN(0);
  1432. IGeometry geometry = query.Single();
  1433. IGeometry expected = Wkt.Read("LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)");
  1434. Assert.IsTrue(expected.Equals(geometry));
  1435. }
  1436. #endregion
  1437. #region Queries testing functions in section 3.2.16.2 (T30 - T31)
  1438. /// <summary>
  1439. /// Conformance Item T30
  1440. /// NumGeometries(g GeometryCollection) : Integer
  1441. /// For this test we will determine the number of geometries in Route 75.
  1442. ///
  1443. /// ANSWER: 2
  1444. ///
  1445. /// Original SQL:
  1446. /// <code>
  1447. /// SELECT NumGeometries(centerlines)
  1448. /// FROM divided_routes
  1449. /// WHERE name = 'Route 75';
  1450. /// </code>
  1451. /// </summary>
  1452. [Test]
  1453. public void ConformanceItemT30Hql()
  1454. {
  1455. string query =
  1456. @"select NHSP.NumGeometries(t.Centerlines)
  1457. from DividedRoute t
  1458. where t.Name = 'Route 75'
  1459. ";
  1460. int result = session.CreateQuery(query)
  1461. .UniqueResult<int>();
  1462. Assert.AreEqual(2, result);
  1463. }
  1464. [Test]
  1465. public void ConformanceItemT30Linq()
  1466. {
  1467. var query =
  1468. from t in session.Query<DividedRoute>()
  1469. where t.Name == "Route 75"
  1470. select t.Centerlines.NumGeometries;
  1471. int result = query.Single();
  1472. Assert.AreEqual(2, result);
  1473. }
  1474. /// <summary>
  1475. /// Conformance Item T31
  1476. /// GeometryN(g GeometryCollection, n Integer) : Geometry
  1477. /// For this test we will determine the second geometry in Route 75.
  1478. ///
  1479. /// ANSWER: 'LINESTRING( 16 0, 16 23, 16 48 )'
  1480. ///
  1481. /// Original SQL:
  1482. /// <code>
  1483. /// SELECT GeometryN(centerlines, 2)
  1484. /// FROM divided_routes
  1485. /// WHERE name = 'Route 75';
  1486. /// </code>
  1487. /// </summary>
  1488. [Test]
  1489. public void ConformanceItemT31()
  1490. {
  1491. DividedRoute entity = session.CreateCriteria(typeof(DividedRoute))
  1492. .Add(Restrictions.Eq("Name", "Route 75"))
  1493. .UniqueResult<DividedRoute>();
  1494. IGeometry geometry = (entity.Centerlines as IMultiLineString).Geometries[1];
  1495. IGeometry expected = Wkt.Read("LINESTRING( 16 0, 16 23, 16 48 )");
  1496. Assert.IsTrue(expected.Equals(geometry));
  1497. }
  1498. [Test]
  1499. public void ConformanceItemT31Hql()
  1500. {
  1501. string query =
  1502. @"select NHSP.AsText(NHSP.GeometryN(t.Centerlines, 2))
  1503. from DividedRoute t
  1504. where t.Name = 'Route 75'
  1505. ";
  1506. string result = session.CreateQuery(query)
  1507. .UniqueResult<string>();
  1508. IGeometry geometry = Wkt.Read(result);
  1509. IGeometry expected = Wkt.Read("LINESTRING( 16 0, 16 23, 16 48 )");
  1510. Assert.IsTrue(expected.Equals(geometry));
  1511. }
  1512. [Test]
  1513. public void ConformanceItemT31Linq()
  1514. {
  1515. var query =
  1516. from t in session.Query<DividedRoute>()
  1517. where t.Name == "Route 75"
  1518. select t.Centerlines.GetGeometryN(1);
  1519. IGeometry geometry = query.Single();
  1520. IGeometry expected = Wkt.Read("LINESTRING( 16 0, 16 23, 16 48 )");
  1521. Assert.IsTrue(expected.Equals(geometry));
  1522. }
  1523. #endregion
  1524. #region Queries testing functions in section 3.2.17.2 (T31 - T33)
  1525. /// <summary>
  1526. /// Conformance Item T32
  1527. /// IsClosed(mc MultiCurve) : Integer
  1528. /// For this test we will determine if the geometry of Route 75 is closed.
  1529. ///
  1530. /// ANSWER: 0
  1531. /// *** Adaptation Alert ***
  1532. /// If the implementer provides IsClosed as a boolean function, instead of as
  1533. /// an INTEGER function, then:
  1534. /// ANSWER: FALSE or 'f'
  1535. ///
  1536. /// Original SQL:
  1537. /// <code>
  1538. /// SELECT IsClosed(centerlines)
  1539. /// FROM divided_routes
  1540. /// WHERE name = 'Route 75';
  1541. /// </code>
  1542. /// </summary>
  1543. [Test]
  1544. public void ConformanceItemT32Hql()
  1545. {
  1546. string query =
  1547. @"select NHSP.IsClosed(t.Centerlines)
  1548. from DividedRoute t
  1549. where t.Name = 'Route 75'
  1550. ";
  1551. bool result = session.CreateQuery(query)
  1552. .UniqueResult<bool>();
  1553. Assert.IsFalse(result);
  1554. }
  1555. [Test]
  1556. public void ConformanceItemT32Linq()
  1557. {
  1558. var query =
  1559. from t in session.Query<DividedRoute>()
  1560. where t.Name == "Route 75"
  1561. select ((ICurve)t.Centerlines).IsClosed;
  1562. bool result = query.Single();
  1563. Assert.IsFalse(result);
  1564. }
  1565. /// <summary>
  1566. /// Conformance Item T33
  1567. /// Length(mc MultiCurve) : Double Precision
  1568. /// For this test we will determine the length of Route 75.
  1569. /// NOTE: This makes no semantic sense in our example...
  1570. ///
  1571. /// ANSWER: 96.00 (meters)
  1572. ///
  1573. /// Original SQL:
  1574. /// <code>
  1575. /// SELECT Length(centerlines)
  1576. /// FROM divided_routes
  1577. /// WHERE name = 'Route 75';
  1578. /// </code>
  1579. /// </summary>
  1580. [Test]
  1581. public void ConformanceItemT33Hql()
  1582. {
  1583. string query =
  1584. @"select NHSP.Length(t.Centerlines)
  1585. from DividedRoute t
  1586. where t.Name = 'Route 75'
  1587. ";
  1588. double result = session.CreateQuery(query)
  1589. .UniqueResult<double>();
  1590. Assert.AreEqual(96, result);
  1591. }
  1592. [Test]
  1593. public void ConformanceItemT33Linq()
  1594. {
  1595. var query =
  1596. from t in session.Query<DividedRoute>()
  1597. where t.Name == "Route 75"
  1598. select t.Centerlines.Length;
  1599. double result = query.Single();
  1600. Assert.AreEqual(96, result);
  1601. }
  1602. #endregion
  1603. #region Queries testing functions in section 3.2.18.2 (T34 - T36)
  1604. /// <summary>
  1605. /// Conformance Item T34
  1606. /// Centroid(ms MultiSurface) : Point
  1607. /// For this test we will determine the centroid of the ponds.
  1608. ///
  1609. /// ANSWER: 'POINT( 25 42 )'
  1610. ///
  1611. /// Original SQL:
  1612. /// <code>
  1613. /// SELECT AsText(Centroid(shores))
  1614. /// FROM ponds
  1615. /// WHERE fid = 120;
  1616. /// </code>
  1617. /// </summary>
  1618. [Test]
  1619. public void ConformanceItemT34Hql()
  1620. {
  1621. string query =
  1622. @"select NHSP.AsText(NHSP.Centroid(t.Shores))
  1623. from Pond t
  1624. where t.Fid = 120
  1625. ";
  1626. string result = session.CreateQuery(query)
  1627. .UniqueResult<string>();
  1628. IGeometry geometry = Wkt.Read(result);
  1629. IGeometry expected = Wkt.Read("POINT( 25 42 )");
  1630. Assert.IsTrue(expected.Equals(geometry));
  1631. }
  1632. [Test]
  1633. public void ConformanceItemT34Linq()
  1634. {
  1635. var query =
  1636. from t in session.Query<Pond>()
  1637. where t.Fid == 120
  1638. select t.Shores.Centroid;
  1639. IGeometry geometry = query.Single();
  1640. IGeometry expected = Wkt.Read("POINT( 25 42 )");
  1641. Assert.IsTrue(expected.Equals(geometry));
  1642. }
  1643. /// <summary>
  1644. /// Conformance Item T35
  1645. /// PointOnSurface(ms MultiSurface) : Point
  1646. /// For this test we will determine a point on the ponds.
  1647. /// NOTE: For this test we will have to uses the Contains function
  1648. /// (which we don't test until later).
  1649. ///
  1650. /// ANSWER: 1
  1651. /// *** Adaptation Alert ***
  1652. /// If the implementer provides Contains as a boolean function, instead of as
  1653. /// an INTEGER function, then:
  1654. /// ANSWER: TRUE or 't'
  1655. ///
  1656. /// Original SQL:
  1657. /// <code>
  1658. /// SELECT Contains(shores, PointOnSurface(shores))
  1659. /// FROM ponds
  1660. /// WHERE fid = 120;
  1661. /// </code>
  1662. /// </summary>
  1663. [Test]
  1664. public void ConformanceItemT35()
  1665. {
  1666. Pond entity = session.CreateCriteria(typeof(Pond))
  1667. .Add(Restrictions.Eq("Fid", (long)120))
  1668. .UniqueResult<Pond>();
  1669. Assert.IsTrue(entity.Shores.Contains(entity.Shores.PointOnSurface));
  1670. }
  1671. [Test]
  1672. public void ConformanceItemT35Hql()
  1673. {
  1674. string query =
  1675. @"select NHSP.Contains(t.Shores, NHSP.PointOnSurface(t.Shores))
  1676. from Pond t
  1677. where t.Fid = 120
  1678. ";
  1679. bool result = session.CreateQuery(query)
  1680. .UniqueResult<bool>();
  1681. Assert.IsTrue(result);
  1682. }
  1683. [Test]
  1684. public void ConformanceItemT35Linq()
  1685. {
  1686. var query =
  1687. from t in session.Query<Pond>()
  1688. where t.Fid == 120
  1689. select t.Shores.Contains(t.Shores.PointOnSurface);
  1690. bool result = query.Single();
  1691. Assert.IsTrue(result);
  1692. }
  1693. /// <summary>
  1694. /// Conformance Item T36
  1695. /// Area(ms MultiSurface) : Double Precision
  1696. /// For this test we will determine the area of the ponds.
  1697. ///
  1698. /// ANSWER: 8.00 (square meters)
  1699. ///
  1700. /// Original SQL:
  1701. /// <code>
  1702. /// SELECT Area(shores)
  1703. /// FROM ponds
  1704. /// WHERE fid = 120;
  1705. /// </code>
  1706. /// </summary>
  1707. [Test]
  1708. public void ConformanceItemT36Hql()
  1709. {
  1710. string query =
  1711. @"select NHSP.Area(t.Shores)
  1712. from Pond t
  1713. where t.Fid = 120
  1714. ";
  1715. double result = session.CreateQuery(query)
  1716. .UniqueResult<double>();
  1717. Assert.AreEqual(8, result);
  1718. }
  1719. [Test]
  1720. public void ConformanceItemT36Linq()
  1721. {
  1722. var query =
  1723. from t in session.Query<Pond>()
  1724. where t.Fid == 120
  1725. select t.Shores.Area;
  1726. double result = query.Single();
  1727. Assert.AreEqual(8, result);
  1728. }
  1729. #endregion
  1730. #region Queries testing functions in section 3.2.19.2 (T37 - T45)
  1731. /// <summary>
  1732. /// Conformance Item T37
  1733. /// Equals(g1 Geometry, g2 Geometry) : Integer
  1734. /// For this test we will determine if the geometry of Goose Island is equal
  1735. /// to the same geometry as consructed from it's WKT representation.
  1736. ///
  1737. /// ANSWER: 1
  1738. /// *** Adaptation Alert ***
  1739. /// If the implementer provides Equals as a boolean function, instead of as
  1740. /// an INTEGER function, then:
  1741. /// ANSWER: TRUE or 't'
  1742. ///
  1743. /// Original SQL:
  1744. /// <code>
  1745. /// SELECT Equals(boundary, PolygonFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',1))
  1746. /// FROM named_places
  1747. /// WHERE name = 'Goose Island';
  1748. /// </code>
  1749. /// </summary>
  1750. /// <remarks>
  1751. /// Correction:
  1752. /// * SRID changed to 101. We require SRIDs are the same for binary operations.
  1753. /// </remarks>
  1754. [Test]
  1755. public void ConformanceItemT37Hql()
  1756. {
  1757. string query =
  1758. @"select NHSP.Equals(t.Boundary, NHSP.PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',101))
  1759. from NamedPlace t
  1760. where t.Name = 'Goose Island'
  1761. ";
  1762. bool result = session.CreateQuery(query)
  1763. .UniqueResult<bool>();
  1764. Assert.IsTrue(result);
  1765. }
  1766. [Test]
  1767. [Ignore("TODO: ToPolygon")]
  1768. public void ConformanceItemT37Linq()
  1769. {
  1770. var query =
  1771. from t in session.Query<NamedPlace>()
  1772. where t.Name == "Goose Island"
  1773. select t.Boundary.Equals("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )".ToPolygon(101));
  1774. bool result = query.Single();
  1775. Assert.IsTrue(result);
  1776. }
  1777. /// <summary>
  1778. /// Conformance Item T38
  1779. /// Disjoint(g1 Geometry, g2 Geometry) : Integer
  1780. /// For this test we will determine if the geometry of Route 75 is disjoint
  1781. /// from the geometry of Ashton.
  1782. ///
  1783. /// ANSWER: 1
  1784. /// *** Adaptation Alert ***
  1785. /// If the implementer provides Disjoint as a boolean function, instead of as
  1786. /// an INTEGER function, then:
  1787. /// ANSWER: TRUE or 't'
  1788. ///
  1789. /// Original SQL:
  1790. /// <code>
  1791. /// SELECT Disjoint(centerlines, boundary)
  1792. /// FROM divided_routes, named_places
  1793. /// WHERE divided_routes.name = 'Route 75' AND named_places.name = 'Ashton';
  1794. /// </code>
  1795. /// </summary>
  1796. [Test]
  1797. public void ConformanceItemT38Hql()
  1798. {
  1799. string query =
  1800. @"select NHSP.Disjoint(dr.Centerlines, np.Boundary)
  1801. from DividedRoute dr, NamedPlace np
  1802. where dr.Name = 'Route 75' and np.Name = 'Ashton'
  1803. ";
  1804. bool result = session.CreateQuery(query)
  1805. .UniqueResult<bool>();
  1806. Assert.IsTrue(result);
  1807. }
  1808. [Test]
  1809. public void ConformanceItemT38Linq()
  1810. {
  1811. var query =
  1812. from dr in session.Query<DividedRoute>()
  1813. from np in session.Query<NamedPlace>()
  1814. where dr.Name == "Route 75" && np.Name == "Ashton"
  1815. select dr.Centerlines.Disjoint(np.Boundary);
  1816. bool result = query.Single();
  1817. Assert.IsTrue(result);
  1818. }
  1819. /// <summary>
  1820. /// Conformance Item T39
  1821. /// Touch(g1 Geometry, g2 Geometry) : Integer
  1822. /// For this test we will determine if the geometry of Cam Stream touches
  1823. /// the geometry of Blue Lake.
  1824. ///
  1825. /// ANSWER: 1
  1826. /// *** Adaptation Alert ***
  1827. /// If the implementer provides Touch as a boolean function, instead of as
  1828. /// an INTEGER function, then:
  1829. /// ANSWER: TRUE or 't'
  1830. ///
  1831. /// Original SQL:
  1832. /// <code>
  1833. /// SELECT Touch(centerline, shore)
  1834. /// FROM streams, lakes
  1835. /// WHERE streams.name = 'Cam Stream' AND lakes.name = 'Blue Lake';
  1836. /// </code>
  1837. /// </summary>
  1838. [Test]
  1839. public void ConformanceItemT39Hql()
  1840. {
  1841. string query =
  1842. @"select NHSP.Touches(s.Centerline, l.Shore)
  1843. from Stream s, Lake l
  1844. where s.Name = 'Cam Stream' and l.Name = 'Blue Lake'
  1845. ";
  1846. bool result = session.CreateQuery(query)
  1847. .UniqueResult<bool>();
  1848. Assert.IsTrue(result);
  1849. }
  1850. [Test]
  1851. public void ConformanceItemT39Linq()
  1852. {
  1853. var query =
  1854. from s in session.Query<Stream>()
  1855. from l in session.Query<Lake>()
  1856. where s.Name == "Cam Stream" && l.Name == "Blue Lake"
  1857. select s.Centerline.Touches(l.Shore);
  1858. bool result = query.Single();
  1859. Assert.IsTrue(result);
  1860. }
  1861. /// <summary>
  1862. /// Conformance Item T40
  1863. /// Within(g1 Geometry, g2 Geometry) : Integer
  1864. /// For this test we will determine if the geometry of the house at 215 Main Street
  1865. /// is within Ashton.
  1866. ///
  1867. /// ANSWER: 1
  1868. /// *** Adaptation Alert ***
  1869. /// If the implementer provides Within as a boolean function, instead of as
  1870. /// an INTEGER function, then:
  1871. /// ANSWER: TRUE or 't'
  1872. ///
  1873. /// Original SQL:
  1874. /// <code>
  1875. /// SELECT Within(boundary, footprint)
  1876. /// FROM named_places, buildings
  1877. /// WHERE named_places.name = 'Ashton' AND buildings.address = '215 Main Street';
  1878. /// </code>
  1879. /// </summary>
  1880. /// <remarks>
  1881. /// Correction:
  1882. /// * Within arguments order changed because is wrong.
  1883. /// The test asks if a footprint ('215 Main Street') is within a boundary ('Ashton'),
  1884. /// so the correct argument order should be Within(footprint, boundary).
  1885. /// </remarks>
  1886. [Test]
  1887. public virtual void ConformanceItemT40Hql()
  1888. {
  1889. string query =
  1890. @"select NHSP.Within(b.Footprint, np.Boundary)
  1891. from NamedPlace np, Building b
  1892. where np.Name = 'Ashton' and b.Address = '215 Main Street'
  1893. ";
  1894. bool result = session.CreateQuery(query)
  1895. .UniqueResult<bool>();
  1896. Assert.IsTrue(result);
  1897. }
  1898. [Test]
  1899. public virtual void ConformanceItemT40Linq()
  1900. {
  1901. var query =
  1902. from np in session.Query<NamedPlace>()
  1903. from b in session.Query<Building>()
  1904. where np.Name == "Ashton" && b.Address == "215 Main Street"
  1905. select b.Footprint.Within(np.Boundary);
  1906. bool result = query.Single();
  1907. Assert.IsTrue(result);
  1908. }
  1909. /// <summary>
  1910. /// Conformance Item T41
  1911. /// Overlap(g1 Geometry, g2 Geometry) : Integer
  1912. /// For this test we will determine if the geometry of Green Forest overlaps
  1913. /// the geometry of Ashton.
  1914. ///
  1915. /// ANSWER: 1
  1916. /// *** Adaptation Alert ***
  1917. /// If the implementer provides Overlap as a boolean function, instead of as
  1918. /// an INTEGER function, then:
  1919. /// ANSWER: TRUE or 't'
  1920. ///
  1921. /// Original SQL:
  1922. /// <code>
  1923. /// SELECT Overlap(forest.boundary, named_places.boundary)
  1924. /// FROM forests, named_places
  1925. /// WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
  1926. /// </code>
  1927. /// </summary>
  1928. [Test]
  1929. public void ConformanceItemT41Hql()
  1930. {
  1931. string query =
  1932. @"select NHSP.Overlaps(f.Boundary, np.Boundary)
  1933. from Forest f, NamedPlace np
  1934. where f.Name = 'Green Forest' and np.Name = 'Ashton'
  1935. ";
  1936. bool result = session.CreateQuery(query)
  1937. .UniqueResult<bool>();
  1938. Assert.IsTrue(result);
  1939. }
  1940. [Test]
  1941. public void ConformanceItemT41Linq()
  1942. {
  1943. var query =
  1944. from f in session.Query<Forest>()
  1945. from np in session.Query<NamedPlace>()
  1946. where f.Name == "Green Forest" && np.Name == "Ashton"
  1947. select f.Boundary.Overlaps(np.Boundary);
  1948. bool result = query.Single();
  1949. Assert.IsTrue(result);
  1950. }
  1951. /// <summary>
  1952. /// Conformance Item T42
  1953. /// Cross(g1 Geometry, g2 Geometry) : Integer
  1954. /// For this test we will determine if the geometry of road segment 102 crosses
  1955. /// the geometry of Route 75.
  1956. ///
  1957. /// ANSWER: 1
  1958. /// *** Adaptation Alert ***
  1959. /// If the implementer provides Cross as a boolean function, instead of as
  1960. /// an INTEGER function, then:
  1961. /// ANSWER: TRUE or 't'
  1962. ///
  1963. /// Original SQL:
  1964. /// <code>
  1965. /// SELECT Cross(road_segment.centerline, divided_routes.centerlines)
  1966. /// FROM road_segment, divided_routes
  1967. /// WHERE road_segment.fid = 102 AND divided_routes.name = 'Route 75';
  1968. /// </code>
  1969. /// </summary>
  1970. [Test]
  1971. public void ConformanceItemT42Hql()
  1972. {
  1973. string query =
  1974. @"select NHSP.Crosses(rs.Centerline, dr.Centerlines)
  1975. from RoadSegment rs, DividedRoute dr
  1976. where rs.Fid = 102 and dr.Name = 'Route 75'
  1977. ";
  1978. bool result = session.CreateQuery(query)
  1979. .UniqueResult<bool>();
  1980. Assert.IsTrue(result);
  1981. }
  1982. [Test]
  1983. public void ConformanceItemT42Linq()
  1984. {
  1985. var query =
  1986. from rs in session.Query<RoadSegment>()
  1987. from dr in session.Query<DividedRoute>()
  1988. where rs.Fid == 102 && dr.Name == "Route 75"
  1989. select rs.Centerline.Crosses(dr.Centerlines);
  1990. bool result = query.Single();
  1991. Assert.IsTrue(result);
  1992. }
  1993. /// <summary>
  1994. /// Conformance Item T43
  1995. /// Intersects(g1 Geometry, g2 Geometry) : Integer
  1996. /// For this test we will determine if the geometry of road segment 102 intersects
  1997. /// the geometry of Route 75.
  1998. ///
  1999. /// ANSWER: 1
  2000. /// *** Adaptation Alert ***
  2001. /// If the implementer provides Intersects as a boolean function, instead of as
  2002. /// an INTEGER function, then:
  2003. /// ANSWER: TRUE or 't'
  2004. ///
  2005. /// Original SQL:
  2006. /// <code>
  2007. /// SELECT Intersects(road_segment.centerline, divided_routes.centerlines)
  2008. /// FROM road_segment, divided_routes
  2009. /// WHERE road_segment.fid = 102 AND divided_routes.name = 'Route 75';
  2010. /// </code>
  2011. /// </summary>
  2012. [Test]
  2013. public void ConformanceItemT43Hql()
  2014. {
  2015. string query =
  2016. @"select NHSP.Intersects(rs.Centerline, dr.Centerlines)
  2017. from RoadSegment rs, DividedRoute dr
  2018. where rs.Fid = 102 and dr.Name = 'Route 75'
  2019. ";
  2020. bool result = session.CreateQuery(query)
  2021. .UniqueResult<bool>();
  2022. Assert.IsTrue(result);
  2023. }
  2024. [Test]
  2025. public void ConformanceItemT43Linq()
  2026. {
  2027. var query =
  2028. from rs in session.Query<RoadSegment>()
  2029. from dr in session.Query<DividedRoute>()
  2030. where rs.Fid == 102 && dr.Name == "Route 75"
  2031. select rs.Centerline.Intersects(dr.Centerlines);
  2032. bool result = query.Single();
  2033. Assert.IsTrue(result);
  2034. }
  2035. /// <summary>
  2036. /// Conformance Item T44
  2037. /// Contains(g1 Geometry, g2 Geometry) : Integer
  2038. /// For this test we will determine if the geometry of Green Forest contains
  2039. /// the geometry of Ashton.
  2040. ///
  2041. /// ANSWER: 0
  2042. /// *** Adaptation Alert ***
  2043. /// If the implementer provides Contains as a boolean function, instead of as
  2044. /// an INTEGER function, then:
  2045. /// ANSWER: FALSE or 'f'
  2046. ///
  2047. /// Original SQL:
  2048. /// <code>
  2049. /// SELECT Contains(forest.boundary, named_places.boundary)
  2050. /// FROM forests, named_places
  2051. /// WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
  2052. /// </code>
  2053. /// </summary>
  2054. [Test]
  2055. public void ConformanceItemT44Hql()
  2056. {
  2057. string query =
  2058. @"select NHSP.Contains(f.Boundary, np.Boundary)
  2059. from Forest f, NamedPlace np
  2060. where f.Name = 'Green Forest' and np.Name = 'Ashton'
  2061. ";
  2062. bool result = session.CreateQuery(query)
  2063. .UniqueResult<bool>();
  2064. Assert.IsFalse(result);
  2065. }
  2066. [Test]
  2067. public void ConformanceItemT44Linq()
  2068. {
  2069. var query =
  2070. from f in session.Query<Forest>()
  2071. from np in session.Query<NamedPlace>()
  2072. where f.Name == "Green Forest" && np.Name == "Ashton"
  2073. select f.Boundary.Contains(np.Boundary);
  2074. bool result = query.Single();
  2075. Assert.IsFalse(result);
  2076. }
  2077. /// <summary>
  2078. /// Conformance Item T45
  2079. /// Relate(g1 Geometry, g2 Geometry, PatternMatrix String) : Integer
  2080. /// For this test we will determine if the geometry of Green Forest relates to
  2081. /// the geometry of Ashton using the pattern "TTTTTTTTT".
  2082. ///
  2083. /// ANSWER: 1
  2084. /// *** Adaptation Alert ***
  2085. /// If the implementer provides Relate as a boolean function, instead of as
  2086. /// an INTEGER function, then:
  2087. /// ANSWER: TRUE or 't'
  2088. ///
  2089. /// Original SQL:
  2090. /// <code>
  2091. /// SELECT Relate(forest.boundary, named_places.boundary, 'TTTTTTTTT')
  2092. /// FROM forests, named_places
  2093. /// WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
  2094. /// </code>
  2095. /// </summary>
  2096. [Test]
  2097. public void ConformanceItemT45Hql()
  2098. {
  2099. string query =
  2100. @"select NHSP.Relate(f.Boundary, np.Boundary, 'TTTTTTTTT')
  2101. from Forest f, NamedPlace np
  2102. where f.Name = 'Green Forest' and np.Name = 'Ashton'
  2103. ";
  2104. bool result = session.CreateQuery(query)
  2105. .UniqueResult<bool>();
  2106. Assert.IsTrue(result);
  2107. }
  2108. [Test]
  2109. public void ConformanceItemT45Linq()
  2110. {
  2111. var query =
  2112. from f in session.Query<Forest>()
  2113. from np in session.Query<NamedPlace>()
  2114. where f.Name == "Green Forest" && np.Name == "Ashton"
  2115. select f.Boundary.Relate(np.Boundary, "TTTTTTTTT");
  2116. bool result = query.Single();
  2117. Assert.IsTrue(result);
  2118. }
  2119. #endregion
  2120. #region Queries testing functions in section 3.2.20.2 (T46)
  2121. /// <summary>
  2122. /// Conformance Item T46
  2123. /// Distance(g1 Geometry, g2 Geometry) : Double Precision
  2124. /// For this test we will determine the distance between Cam Bridge and Ashton.
  2125. ///
  2126. /// ANSWER: 12 (meters)
  2127. ///
  2128. /// Original SQL:
  2129. /// <code>
  2130. /// SELECT Distance(position, boundary)
  2131. /// FROM bridges, named_places
  2132. /// WHERE bridges.name = 'Cam Bridge' AND named_places.name = 'Ashton';
  2133. /// </code>
  2134. /// </summary>
  2135. [Test]
  2136. public void ConformanceItemT46Hql()
  2137. {
  2138. string query =
  2139. @"select NHSP.Distance(b.Position, np.Boundary)
  2140. from Bridge b, NamedPlace np
  2141. where b.Name = 'Cam Bridge' and np.Name = 'Ashton'
  2142. ";
  2143. double result = session.CreateQuery(query)
  2144. .UniqueResult<double>();
  2145. Assert.AreEqual(12, result);
  2146. }
  2147. [Test]
  2148. public void ConformanceItemT46Linq()
  2149. {
  2150. var query =
  2151. from b in session.Query<Bridge>()
  2152. from np in session.Query<NamedPlace>()
  2153. where b.Name == "Cam Bridge" && np.Name == "Ashton"
  2154. select b.Position.Distance(np.Boundary);
  2155. double result = query.Single();
  2156. Assert.AreEqual(12, result);
  2157. }
  2158. #endregion
  2159. #region Queries testing functions in section 3.2.21.2 (T47 - T50)
  2160. /// <summary>
  2161. /// Conformance Item T47
  2162. /// Intersection(g1 Geometry, g2 Geometry) : Geometry
  2163. /// For this test we will determine the intersection between Cam Stream and
  2164. /// Blue Lake.
  2165. ///
  2166. /// ANSWER: 'POINT( 52 18 )'
  2167. ///
  2168. /// Original SQL:
  2169. /// <code>
  2170. /// SELECT Intersection(centerline, shore)
  2171. /// FROM streams, lakes
  2172. /// WHERE streams.name = 'Cam Stream' AND lakes.name = 'Blue Lake';
  2173. /// </code>
  2174. /// </summary>
  2175. [Test]
  2176. public void ConformanceItemT47Hql()
  2177. {
  2178. string query =
  2179. @"select NHSP.AsText(NHSP.Intersection(s.Centerline, l.Shore))
  2180. from Stream s, Lake l
  2181. where s.Name = 'Cam Stream' and l.Name = 'Blue Lake'
  2182. ";
  2183. string result = session.CreateQuery(query)
  2184. .UniqueResult<string>();
  2185. IGeometry geometry = Wkt.Read(result);
  2186. IGeometry expected = Wkt.Read("POINT( 52 18 )");
  2187. Assert.IsTrue(expected.Equals(geometry));
  2188. }
  2189. [Test]
  2190. public void ConformanceItemT47Linq()
  2191. {
  2192. var query =
  2193. from s in session.Query<Stream>()
  2194. from l in session.Query<Lake>()
  2195. where s.Name == "Cam Stream" && l.Name == "Blue Lake"
  2196. select s.Centerline.Intersection(l.Shore);
  2197. IGeometry geometry = query.Single();
  2198. IGeometry expected = Wkt.Read("POINT( 52 18 )");
  2199. Assert.IsTrue(expected.Equals(geometry));
  2200. }
  2201. /// <summary>
  2202. /// Conformance Item T48
  2203. /// Difference(g1 Geometry, g2 Geometry) : Geometry
  2204. /// For this test we will determine the difference between Ashton and
  2205. /// Green Forest.
  2206. ///
  2207. /// ANSWER: 'POLYGON( ( 56 34, 62 48, 84 48, 84 42, 56 34) )'
  2208. /// NOTE: The order of the vertices here is arbitrary.
  2209. ///
  2210. /// Original SQL:
  2211. /// <code>
  2212. /// SELECT Difference(named_places.boundary, forests.boundary)
  2213. /// FROM named_places, forests
  2214. /// WHERE named_places.name = 'Ashton' AND forests.name = 'Green Forest';
  2215. /// </code>
  2216. /// </summary>
  2217. [Test]
  2218. public void ConformanceItemT48Hql()
  2219. {
  2220. string query =
  2221. @"select NHSP.AsText(NHSP.Difference(np.Boundary, f.Boundary))
  2222. from NamedPlace np, Forest f
  2223. where np.Name = 'Ashton' and f.Name = 'Green Forest'
  2224. ";
  2225. string result = session.CreateQuery(query)
  2226. .UniqueResult<string>();
  2227. IGeometry geometry = Wkt.Read(result);
  2228. IGeometry expected = Wkt.Read("POLYGON( ( 56 34, 62 48, 84 48, 84 42, 56 34) )");
  2229. Assert.IsTrue(expected.Equals(geometry));
  2230. }
  2231. [Test]
  2232. public void ConformanceItemT48Linq()
  2233. {
  2234. var query =
  2235. from np in session.Query<NamedPlace>()
  2236. from f in session.Query<Forest>()
  2237. where np.Name == "Ashton" && f.Name == "Green Forest"
  2238. select np.Boundary.Difference(f.Boundary);
  2239. IGeometry geometry = query.Single();
  2240. IGeometry expected = Wkt.Read("POLYGON( ( 56 34, 62 48, 84 48, 84 42, 56 34) )");
  2241. Assert.IsTrue(expected.Equals(geometry));
  2242. }
  2243. /// <summary>
  2244. /// Conformance Item T49
  2245. /// Union(g1 Geometry, g2 Geometry) : Integer
  2246. /// For this test we will determine the union of Blue Lake and Goose Island
  2247. ///
  2248. /// ANSWER: 'POLYGON((52 18,66 23,73 9,48 6,52 18))'
  2249. /// NOTE: The outer ring of BLue Lake is the answer.
  2250. ///
  2251. /// Original SQL:
  2252. /// <code>
  2253. /// SELECT Union(shore, boundary)
  2254. /// FROM lakes, named_places
  2255. /// WHERE lakes.name = 'Blue Lake' AND named_places.name = Ashton';
  2256. /// </code>
  2257. /// </summary>
  2258. /// <remarks>
  2259. /// Correction:
  2260. /// * Place name condition changed from 'Ashton' to 'Goose Island'
  2261. /// in order to conform the test enunciation and correct answer.
  2262. /// </remarks>
  2263. [Test]
  2264. public void ConformanceItemT49Hql()
  2265. {
  2266. string query =
  2267. @"select NHSP.AsText(NHSP.Union(l.Shore, np.Boundary))
  2268. from Lake l, NamedPlace np
  2269. where l.Name = 'Blue Lake' and np.Name = 'Goose Island'
  2270. ";
  2271. string result = session.CreateQuery(query)
  2272. .UniqueResult<string>();
  2273. IGeometry geometry = Wkt.Read(result);
  2274. IGeometry expected = Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18))");
  2275. Assert.IsTrue(expected.Equals(geometry));
  2276. }
  2277. [Test]
  2278. public void ConformanceItemT49Linq()
  2279. {
  2280. var query =
  2281. from l in session.Query<Lake>()
  2282. from np in session.Query<NamedPlace>()
  2283. where l.Name == "Blue Lake" && np.Name == "Goose Island"
  2284. select l.Shore.Union(np.Boundary);
  2285. IGeometry geometry = query.Single();
  2286. IGeometry expected = Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18))");
  2287. Assert.IsTrue(expected.Equals(geometry));
  2288. }
  2289. /// <summary>
  2290. /// Conformance Item T50
  2291. /// SymmetricDifference(g1 Geometry, g2 Geometry) : Integer
  2292. /// For this test we will determine the symmetric difference of Blue Lake
  2293. /// and Goose Island
  2294. ///
  2295. /// ANSWER: 'POLYGON((52 18,66 23,73 9,48 6,52 18))'
  2296. /// NOTE: The outer ring of BLue Lake is the answer.
  2297. ///
  2298. /// Original SQL:
  2299. /// <code>
  2300. /// SELECT SymmetricDifference(shore, boundary)
  2301. /// FROM lakes, named_places
  2302. /// WHERE lakes.name = 'Blue Lake' OR named_places.name = 'Ashton';
  2303. /// </code>
  2304. /// </summary>
  2305. /// <remarks>
  2306. /// Correction:
  2307. /// * Place name condition changed from 'Ashton' to 'Goose Island'
  2308. /// in order to conform the test enunciation and correct answer.
  2309. /// </remarks>
  2310. [Test]
  2311. public void ConformanceItemT50()
  2312. {
  2313. IGeometry shore = session
  2314. .CreateCriteria(typeof(Lake), "l")
  2315. .Add(Restrictions.Eq("l.Name", "Blue Lake"))
  2316. .SetProjection(Projections.Property("l.Shore"))
  2317. .UniqueResult<IGeometry>();
  2318. IGeometry boundary = session
  2319. .CreateCriteria(typeof(NamedPlace))
  2320. .Add(Restrictions.Eq("Name", "Goose Island"))
  2321. .SetProjection(Projections.Property("Boundary"))
  2322. .UniqueResult<IGeometry>();
  2323. IGeometry result = shore.SymmetricDifference(boundary);
  2324. IGeometry expected = Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18))");
  2325. Assert.IsTrue(expected.Equals(result));
  2326. }
  2327. [Test]
  2328. public void ConformanceItemT50Hql()
  2329. {
  2330. string query =
  2331. @"select NHSP.AsText(NHSP.SymDifference(l.Shore, np.Boundary))
  2332. from Lake l, NamedPlace np
  2333. where l.Name = 'Blue Lake' and np.Name = 'Goose Island'
  2334. ";
  2335. string result = session.CreateQuery(query)
  2336. .UniqueResult<string>();
  2337. IGeometry geometry = Wkt.Read(result);
  2338. IGeometry expected = Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18))");
  2339. Assert.IsTrue(expected.Equals(geometry));
  2340. }
  2341. [Test]
  2342. public void ConformanceItemT50Linq()
  2343. {
  2344. var query =
  2345. from l in session.Query<Lake>()
  2346. from np in session.Query<NamedPlace>()
  2347. where l.Name == "Blue Lake" && np.Name == "Goose Island"
  2348. select l.Shore.SymmetricDifference(np.Boundary);
  2349. IGeometry geometry = query.Single();
  2350. IGeometry expected = Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18))");
  2351. Assert.IsTrue(expected.Equals(geometry));
  2352. }
  2353. /// <summary>
  2354. /// Conformance Item T51
  2355. /// Buffer(g Geometry, d Double Precision) : Geometry
  2356. /// For this test we will make a 15 meter buffer about Cam Bridge.
  2357. /// NOTE: This test we count the number of buildings contained in
  2358. /// the buffer that is generated. This test only works because
  2359. /// we have a single bridge record, two building records, and
  2360. /// we selected the buffer size such that only one of the buildings
  2361. /// is contained in the buffer.
  2362. ///
  2363. /// ANSWER: 1
  2364. /// *** Adaptation Alert ***
  2365. /// If the implementer provides Contains as a boolean function, instead of as
  2366. /// an INTEGER function, then the WHERE clause should be:
  2367. /// WHERE Contains(Buffer(bridges.position, 15.0), buildings.footprint) = 'TRUE';
  2368. /// - or -
  2369. /// WHERE Contains(Buffer(bridges.position, 15.0), buildings.footprint) = 't';
  2370. ///
  2371. /// Original SQL:
  2372. /// <code>
  2373. /// SELECT count(*)
  2374. /// FROM buildings, bridges
  2375. /// WHERE Contains(Buffer(bridges.position, 15.0), buildings.footprint) = 1;
  2376. /// </code>
  2377. /// </summary>
  2378. [Test]
  2379. public virtual void ConformanceItemT51Hql()
  2380. {
  2381. string query =
  2382. @"select count(*)
  2383. from Building bl, Bridge br
  2384. where NHSP.Contains(NHSP.Buffer(br.Position, 15.0), bl.Footprint) = true
  2385. ";
  2386. long result = session.CreateQuery(query)
  2387. .UniqueResult<long>();
  2388. Assert.AreEqual(1, result);
  2389. }
  2390. [Test]
  2391. public virtual void ConformanceItemT51Linq()
  2392. {
  2393. var query =
  2394. from bl in session.Query<Building>()
  2395. from br in session.Query<Bridge>()
  2396. where br.Position.Buffer(15.0).Contains(bl.Footprint)
  2397. select bl
  2398. ;
  2399. long result = query.LongCount();
  2400. Assert.AreEqual(1, result);
  2401. }
  2402. /// <summary>
  2403. /// Conformance Item T52
  2404. /// ConvexHull(g Geometry) : Geometry
  2405. /// For this test we will determine the convex hull of Blue Lake
  2406. ///
  2407. /// ANSWER: 'POLYGON((52 18,66 23,73 9,48 6,52 18))'
  2408. /// NOTE: The outer ring of BLue Lake is the answer.
  2409. ///
  2410. /// Original SQL:
  2411. /// <code>
  2412. /// SELECT ConvexHull(shore)
  2413. /// FROM lakes
  2414. /// WHERE lakes.name = 'Blue Lake';
  2415. /// </code>
  2416. /// </summary>
  2417. [Test]
  2418. public void ConformanceItemT52Hql()
  2419. {
  2420. string query =
  2421. @"select NHSP.AsText(NHSP.ConvexHull(l.Shore))
  2422. from Lake l
  2423. where l.Name = 'Blue Lake'
  2424. ";
  2425. string result = session.CreateQuery(query)
  2426. .UniqueResult<string>();
  2427. IGeometry geometry = Wkt.Read(result);
  2428. IGeometry expected = Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18))");
  2429. Assert.IsTrue(expected.Equals(geometry));
  2430. }
  2431. [Test]
  2432. public void ConformanceItemT52Linq()
  2433. {
  2434. var query =
  2435. from l in session.Query<Lake>()
  2436. where l.Name == "Blue Lake"
  2437. select l.Shore.ConvexHull();
  2438. IGeometry geometry = query.Single();
  2439. IGeometry expected = Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18))");
  2440. Assert.IsTrue(expected.Equals(geometry));
  2441. }
  2442. #endregion
  2443. }
  2444. }