コード例 #1
0
        public void HqlUnion()
        {
            IList results = Session
                            .CreateQuery(
                "select e.Geometry, NHSP.Union(e.Geometry, ?) from PolygonEntity as e where e.Geometry is not null")
                            .SetParameter(0, _filter, SpatialDialect.GeometryTypeOf(Session))
                            .SetMaxResults(100)
                            .List();

            int count = 0;

            foreach (object[] item in results)
            {
                var geom  = (IGeometry)item[0];
                var union = (IGeometry)item[1];

                // some databases give a null object if the difference is the
                // null-set
                if (union == null || union.IsEmpty)
                {
                    continue;
                }

                union.Normalize();
                IGeometry ntsUnion = geom.Union(_filter);
                ntsUnion.Normalize();

                if (ntsUnion.EqualsExact(union, 0.5))
                {
                    count++;
                }
            }
            Assert.Greater(count, 0);
        }
コード例 #2
0
        public void HqlSymDifference()
        {
            IList results = session
                            .CreateQuery("select e.Geometry, NHSP.SymDifference(e.Geometry, ?) from PolygonEntity as e where e.Geometry is not null")
                            .SetParameter(0, this.filter, SpatialDialect.GeometryTypeOf(session))
                            .SetMaxResults(100)
                            .List();

            int count      = 0;
            int countEmpty = 0;

            foreach (object[] item in results)
            {
                IGeometry geom    = (IGeometry)item[0];
                IGeometry symDiff = (IGeometry)item[1];

                // some databases give a null object if the difference is the
                // null-set
                if (symDiff == null || symDiff.IsEmpty)
                {
                    countEmpty++;
                    continue;
                }

                symDiff.Normalize();
                IGeometry ntsSymDiff = geom.SymmetricDifference(this.filter);
                ntsSymDiff.Normalize();

                if (ntsSymDiff.EqualsExact(symDiff, 0.5))
                {
                    count++;
                }
            }
            Assert.Greater(count, 0);
        }
コード例 #3
0
        public void HqlDistanceMin()
        {
            const double minDistance = 40000;

            IList results = Session
                            .CreateQuery(
                @"
					select NHSP.Distance(l.Geometry, :filter), l.Geometry
					from LineStringEntity as l
					where l.Geometry is not null
					and NHSP.Distance(l.Geometry, :filter) > :minDistance
					order by NHSP.Distance(l.Geometry, :filter)"                    )
                            .SetParameter("filter", _filter, SpatialDialect.GeometryTypeOf(Session))
                            .SetParameter("minDistance", minDistance)
                            .SetMaxResults(100)
                            .List();

            Assert.IsNotEmpty(results);
            foreach (object[] item in results)
            {
                var distance = (double)item[0];
                Assert.Greater(distance, minDistance);
                var geom = (IGeometry)item[1];
                Assert.AreEqual(geom.Distance(_filter), distance, 0.003);
            }
        }
コード例 #4
0
        public void HqlOverlapsLineString()
        {
            IList results = Session
                            .CreateQuery(
                "select NHSP.Overlaps(?,l.Geometry) from LineStringEntity as l where l.Geometry is not null")
                            .SetParameter(0, _filter, SpatialDialect.GeometryTypeOf(Session))
                            .List();

            long countOverlapping = 0;

            foreach (bool isOverlapped in results)
            {
                if (isOverlapped)
                {
                    countOverlapping++;
                }
            }

            long count;

            using (var command = Session.Connection.CreateCommand())
            {
                command.CommandText = SqlOvelapsLineString(FilterString);
                count = (long)command.ExecuteScalar();
            }

            Assert.AreEqual(countOverlapping, count);
        }
コード例 #5
0
        public void HqlRelateLineString()
        {
            long count = session
                         .CreateQuery("select count(*) from LineStringEntity l where l.Geometry is not null and NHSP.Relate(l.Geometry, ?, 'TT*******') = true")
                         .SetParameter(0, this.filter, SpatialDialect.GeometryTypeOf(session))
                         .UniqueResult <long>();

            Assert.Greater((int)count, 0);
        }
コード例 #6
0
        public void OrderByDistanceLinq()
        {
            Geometry point = new Point(0.0, 0.0)
            {
                SRID = 4326
            };

            var result = _session.Query <Simple>()
                         .OrderBy(s => s.Geometry.Distance(point.MappedAs(SpatialDialect.GeometryTypeOf(_session))))
                         .ToList();

            Assert.That(result[0].Description, Is.EqualTo("point 2"));
            Assert.That(result[1].Description, Is.EqualTo("point 4"));
            Assert.That(result[2].Description, Is.EqualTo("point 3"));
            Assert.That(result[3].Description, Is.EqualTo("point 1"));
        }
コード例 #7
0
        public void OrderByDistanceHql()
        {
            var point = new Point(0.0, 0.0)
            {
                SRID = 4326
            };

            var result = _session.CreateQuery(
                @"select p from Simple p
                  order by NHSP.Distance(p.Geometry, :point)")
                         .SetParameter("point", point, SpatialDialect.GeometryTypeOf(_session))
                         .List <Simple>();

            Assert.That(result[0].Description, Is.EqualTo("point 2"));
            Assert.That(result[1].Description, Is.EqualTo("point 4"));
            Assert.That(result[2].Description, Is.EqualTo("point 3"));
            Assert.That(result[3].Description, Is.EqualTo("point 1"));
        }
コード例 #8
0
        public void HqlDistance()
        {
            IList results = session
                            .CreateQuery(@"
					select NHSP.Distance(l.Geometry, ?), l.Geometry
					from LineStringEntity as l
					where l.Geometry is not null"                    )
                            .SetParameter(0, this.filter, SpatialDialect.GeometryTypeOf(session))
                            .SetMaxResults(100)
                            .List();

            foreach (object[] item in results)
            {
                double    distance = (double)item[0];
                IGeometry geom     = (IGeometry)item[1];
                Assert.AreEqual(geom.Distance(this.filter), distance, 0.003);
            }
        }
コード例 #9
0
        public void HqlIntersectsLineString()
        {
            IList results = Session
                            .CreateQuery(
                "select NHSP.Intersects(?,l.Geometry) from LineStringEntity as l where l.Geometry is not null")
                            .SetParameter(0, _filter, SpatialDialect.GeometryTypeOf(Session))
                            .List();

            long intersects = 0;

            foreach (bool b in results)
            {
                if (b)
                {
                    intersects++;
                }
            }

            var altIntersects = Session
                                .CreateQuery("select count(*) from LineStringEntity as l where NHSP.Intersects(l.Geometry, ?) = true")
                                .SetParameter(0, _filter, SpatialDialect.GeometryTypeOf(Session))
                                .UniqueResult <long>();

            Assert.AreEqual(intersects, altIntersects);

            long count;

            using (var command = Session.Connection.CreateCommand())
            {
                command.CommandText = SqlIntersectsLineString(FilterString);
                count = (long)command.ExecuteScalar();
            }

            Assert.AreEqual(intersects, count);

            results = Session
                      .CreateQuery("from LineStringEntity as l where NHSP.Intersects(?,l.Geometry) = true")
                      .SetParameter(0, _filter, SpatialDialect.GeometryTypeOf(Session))
                      .List();

            Assert.AreEqual(count, results.Count);
        }
コード例 #10
0
 /// <summary>
 /// Gets the types.
 /// </summary>
 /// <param name="criteria">The criteria.</param>
 /// <param name="criteriaQuery">The criteria query.</param>
 /// <returns></returns>
 public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
 {
     return(new IType[] { SpatialDialect.GeometryTypeOf(criteriaQuery.Factory) });
 }