Exemplo n.º 1
0
        public IQueryOver <TEntity, TEntity> FilterForBoundingBox(IQueryOver <TEntity, TEntity> queryOver, TReportParameter parameter)
        {
            var filterGeom = GISService.GetGeometryFromBoundingBox(parameter.BoundingBox);

            queryOver.UnderlyingCriteria.Add(SpatialRestrictions.Filter(ExpressionHelper.GetPropertyName <StrassenabschnittGIS, IGeometry>(e => e.Shape), filterGeom));
            return(queryOver);
        }
Exemplo n.º 2
0
        private ICriteria CreateCriteriaWithSpatial(IGeometry filterGeom)
        {
            ICriteria cr = CurrentSession.CreateCriteria <TEntity>();

            cr.Add(SpatialRestrictions.Filter(ExpressionHelper.GetPropertyName <IAbschnittGISBase, IGeometry>(e => e.Shape), filterGeom));
            return(cr);
        }
Exemplo n.º 3
0
        private IList <Address> NHGis(bool useSquare, bool regularSize)
        {
            Random ran      = new Random(DateTime.Now.Second);
            var    session  = SessionFactory.GetSession();
            var    criteria = session.CreateCriteria <Address>();

            criteria.Add(SpatialRestrictions.Within("Coordinates", useSquare ?
                                                    GetRandomSquare(ran, regularSize) : GetRandomIrregularPolygon(ran, regularSize)));
            return(criteria.List <Address>());
        }
Exemplo n.º 4
0
        public void ReadTestGis()
        {
            var session  = SessionFactory.GetSession();
            var criteria = session.CreateCriteria <Address>();
            var ran      = new Random();

            criteria.Add(SpatialRestrictions.Within("Coordinates", GetRandomPolygon(ran)));
            criteria.SetProjection(Projections.RowCount());
            var count = criteria.UniqueResult();
        }
Exemplo n.º 5
0
        private void UpdateMapGrid(VeloObject entity, Envelope envelope, ISession session)
        {
            var q = session.CreateCriteria <MapGrid>("mg")
                    .Add(Restrictions.Eq("mg.Map.ID", entity.FeatureObject.Layer.Map.ID))
                    .Add(SpatialRestrictions.Filter("mg.Bounds", envelope, 4326));
            var mapGridList = q.List <MapGrid>();

            foreach (var mapGrid in mapGridList)
            {
                session.Lock(mapGrid, LockMode.Force);
            }
        }
        public virtual void CountSpatialEmpty()
        {
            IList results = _session.CreateCriteria(typeof(Simple))
                            .Add(SpatialRestrictions.IsEmpty("Geometry"))
                            .List();

            Assert.AreEqual(2, results.Count);
            foreach (Simple item in results)
            {
                Assert.IsTrue(item.Geometry.IsEmpty);
            }
        }
Exemplo n.º 7
0
        private IList <ZustandsabschnittGIS> GetCurrentZustandsAbschnitteBySpatialFilter(IGeometry filter, ErfassungsPeriod erfassungsperiod)

        {
            var cr = transactionScopeProvider.CurrentTransactionScope.Session.CreateCriteria <ZustandsabschnittGIS>();

            cr.CreateAlias(typeof(StrassenabschnittGIS).Name, "strassenabschnittgis", JoinType.InnerJoin);
            cr.Add(SpatialRestrictions.Filter(ExpressionHelper.GetPropertyName <ZustandsabschnittGIS, IGeometry>(za => za.Shape), filter));
            //var test = cr.List();
            cr.Add(Restrictions.Eq("strassenabschnittgis." + ExpressionHelper.GetPropertyName <StrassenabschnittGIS, ErfassungsPeriod>(sa => sa.ErfassungsPeriod), erfassungsperiod));
            //test = cr.List();
            return(cr.List <ZustandsabschnittGIS>().Where(z => z.Shape.Intersects(filter)).ToList());
        }
        public void GeometryContains()
        {
            var point = new Point(1.5, 1.5)
            {
                SRID = 32719
            };

            var county = (County)_session.CreateCriteria(typeof(County))
                         .Add(SpatialRestrictions.Contains("Boundaries", point))
                         .UniqueResult();

            Assert.AreEqual("bbbb", county.Name);
        }
Exemplo n.º 9
0
        public IEnumerable <T> Locate <T>(Point center, double buffer)
            where T : class, IHaveGeoData
        {
            var propName    = ReflectionHelper.GetProperty <T, IGeometry>(x => x.GeoData).Name;
            var coordinates = center.Buffer(buffer).Coordinates.Reverse().ToArray();
            var polygon     = Default.GeometryFactory.CreatePolygon(new LinearRing(coordinates), null);

            var results = _session.CreateCriteria <T>()
                          .Add(SpatialRestrictions.Intersects(propName, polygon))
                          .List <T>();

            return(results);
        }
Exemplo n.º 10
0
        public void LineStringFiltering()
        {
            IList results = Session.CreateCriteria(typeof(LineStringEntity))
                            .Add(SpatialRestrictions.Filter("Geometry", _filter))
                            .List();

            long count;

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

            Assert.AreEqual(count, results.Count);
        }
Exemplo n.º 11
0
        private static void ReadSQlGis(int total)
        {
            Console.WriteLine();
            Random ran = new Random(DateTime.Now.Second);

            for (int i = 0; i < total; i++)
            {
                Console.Write("\r{0:N2}%   ", (i + 1) / Convert.ToDouble(total) * 100);
                var session  = SessionFactory.GetSession();
                var criteria = session.CreateCriteria <Address>();
                criteria.Add(SpatialRestrictions.Within("Coordinates", GetRandomPolygon(ran)));
                criteria.SetProjection(Projections.RowCount());
                var count = criteria.UniqueResult();
            }
            Console.WriteLine();
        }
Exemplo n.º 12
0
        public void PolygonFiltering()
        {
            IList results = session.CreateCriteria(typeof(PolygonEntity))
                            .Add(SpatialRestrictions.Filter("Geometry", this.filter))
                            .List();

            long count;

            using (IDbCommand command = session.Connection.CreateCommand())
            {
                command.CommandText = this.SqlPolygonFilter(FilterString);
                count = (long)command.ExecuteScalar();
            }

            Assert.AreEqual(count, results.Count);
        }
Exemplo n.º 13
0
 public IList <Camp> ListByBufferZone(double longitude, double latitude, float radius, int spatialReference)
 {
     try
     {
         Coordinate coordinate = new Coordinate(longitude, latitude);
         Point      point      = new Point(coordinate);
         point.SRID = spatialReference;
         Geometry buffer = point.Buffer(radius);
         SpatialRelationCriterion spatialCriterion = SpatialRestrictions.Intersects("Location", buffer);
         return(Session.CreateCriteria <Camp>()
                .Add(Restrictions.And(spatialCriterion, Restrictions.Where <Camp>(c => c.IsEnabled)))
                .List <Camp>());
     }
     catch
     {
         throw;
     }
 }
Exemplo n.º 14
0
        public void CountNullOrSpatialEmpty()
        {
            IList results = _session.CreateCriteria(typeof(Simple))
                            .Add(Restrictions.Or(
                                     Restrictions.IsNull("Geometry"),
                                     SpatialRestrictions.IsEmpty("Geometry")
                                     ))
                            .List();

            Assert.AreEqual(3, results.Count);
            foreach (Simple item in results)
            {
                if (item.Geometry != null)
                {
                    Assert.IsTrue(item.Geometry.IsEmpty);
                }
            }
        }
Exemplo n.º 15
0
 public override void Delete(VeloObject entity)
 {
     using (var session = NHibernateSession)
     {
         using (var t = session.BeginTransaction())
         {
             session.Delete(entity);
             var envelope = entity.FeatureObject.Geometry.EnvelopeInternal;
             var q        = session.CreateCriteria <MapGrid>("mg")
                            .Add(Restrictions.Eq("mg.Map.ID", entity.FeatureObject.Layer.Map.ID))
                            .Add(SpatialRestrictions.Filter("mg.Bounds", envelope, 4326));
             var mapGridList = q.List <MapGrid>();
             foreach (var mapGrid in mapGridList)
             {
                 session.Lock(mapGrid, LockMode.Force);
             }
             t.Commit();
         }
     }
 }
Exemplo n.º 16
0
        public void make_sure_the_database_is_querying_geography_correctly()
        {
            // arrange
            var center1  = Default.GeometryFactory.CreatePoint(new Coordinate(35, 32)).As <Point>();
            var country1 = InsertCountryAround(center1, 1);
            var center2  = Default.GeometryFactory.CreatePoint(new Coordinate(36, 32)).As <Point>();
            var country2 = InsertCountryAround(center2);
            var center3  = Default.GeometryFactory.CreatePoint(new Coordinate(36, 33)).As <Point>();

            InsertCountryAround(center3);

            // act
            var propName = ReflectionHelper.GetProperty <Country, IGeometry>(s => s.GeoData).Name;
            var result   = Session.CreateCriteria <Country>()
                           .Add(SpatialRestrictions.Intersects(propName, center2))
                           .List <Country>();

            // assert
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result.Any(e => e.Id == country1.Id));
            Assert.That(result.Any(e => e.Id == country2.Id));
        }
Exemplo n.º 17
0
 /// <summary>
 /// Apply a "relate" constraint to the named property
 /// </summary>
 public AbstractCriterion Relate(object value, string intersectionPatternMatrix)
 {
     return(this.Process(SpatialRestrictions.Relate(this.propertyName, value, intersectionPatternMatrix)));
 }
 /// <summary>
 /// Apply a "filter" constraint to the named property
 /// </summary>
 public TReturn Filter(IGeometry value)
 {
     return(this.Add(SpatialRestrictions.Filter(this.propertyName, value)));
 }
 /// <summary>
 /// Apply a "is Within distance" constraint to the named property
 /// </summary>
 public TReturn IsWithinDistance(object value, double distance)
 {
     return(this.Add(SpatialRestrictions.IsWithinDistance(this.propertyName, value, distance)));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Apply a "crosses" constraint to the named property
 /// </summary>
 public AbstractCriterion Crosses(object value)
 {
     return(this.Process(SpatialRestrictions.Crosses(this.propertyName, value)));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Apply a "disjoint" constraint to the named property
 /// </summary>
 public AbstractCriterion Disjoint(object value)
 {
     return(this.Process(SpatialRestrictions.Disjoint(this.propertyName, value)));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Apply a "filter" constraint to the named property
 /// </summary>
 public AbstractCriterion Filter(IGeometry value)
 {
     return(this.Process(SpatialRestrictions.Filter(this.propertyName, value)));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Apply a "filter" constraint to the named property
 /// </summary>
 public AbstractCriterion Filter(IEnvelope value, int srid)
 {
     return(this.Process(SpatialRestrictions.Filter(this.propertyName, value, srid)));
 }
 /// <summary>
 /// Apply a "disjoint" constraint to the named property
 /// </summary>
 public TReturn Disjoint(object value)
 {
     return(this.Add(SpatialRestrictions.Disjoint(this.propertyName, value)));
 }
 /// <summary>
 /// Apply a "eq" constraint to the named property
 /// </summary>
 public TReturn Eq(object value)
 {
     return(this.Add(SpatialRestrictions.Eq(this.propertyName, value)));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Apply a "eq exact" constraint to the named property
 /// </summary>
 public AbstractCriterion EqExact(object value, double tolerance)
 {
     return(this.Process(SpatialRestrictions.EqExact(this.propertyName, value, tolerance)));
 }
 /// <summary>
 /// Apply a "filter" constraint to the named property
 /// </summary>
 public TReturn Filter(Envelope value, int srid)
 {
     return(this.Add(SpatialRestrictions.Filter(this.propertyName, value, srid)));
 }
 /// <summary>
 /// Apply a "covered by" constraint to the named property
 /// </summary>
 public TReturn CoveredBy(object value)
 {
     return(this.Add(SpatialRestrictions.CoveredBy(this.propertyName, value)));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Apply a "is Within distance" constraint to the named property
 /// </summary>
 public AbstractCriterion IsWithinDistance(object value, double distance)
 {
     return(this.Process(SpatialRestrictions.IsWithinDistance(this.propertyName, value, distance)));
 }
 /// <summary>
 /// Apply a "crosses" constraint to the named property
 /// </summary>
 public TReturn Crosses(object value)
 {
     return(this.Add(SpatialRestrictions.Crosses(this.propertyName, value)));
 }