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); }
private ICriteria CreateCriteriaWithSpatial(IGeometry filterGeom) { ICriteria cr = CurrentSession.CreateCriteria <TEntity>(); cr.Add(SpatialRestrictions.Filter(ExpressionHelper.GetPropertyName <IAbschnittGISBase, IGeometry>(e => e.Shape), filterGeom)); return(cr); }
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>()); }
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(); }
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); } }
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); }
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); }
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); }
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(); }
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); }
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; } }
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); } } }
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(); } } }
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)); }
/// <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))); }
/// <summary> /// Apply a "crosses" constraint to the named property /// </summary> public AbstractCriterion Crosses(object value) { return(this.Process(SpatialRestrictions.Crosses(this.propertyName, value))); }
/// <summary> /// Apply a "disjoint" constraint to the named property /// </summary> public AbstractCriterion Disjoint(object value) { return(this.Process(SpatialRestrictions.Disjoint(this.propertyName, value))); }
/// <summary> /// Apply a "filter" constraint to the named property /// </summary> public AbstractCriterion Filter(IGeometry value) { return(this.Process(SpatialRestrictions.Filter(this.propertyName, value))); }
/// <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))); }
/// <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))); }
/// <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))); }