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 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 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 "intersects" constraint to the named property /// </summary> public AbstractCriterion Intersects(object value) { return(this.Process(SpatialRestrictions.Intersects(this.propertyName, value))); }
/// <summary> /// Apply a "intersects" constraint to the named property /// </summary> public TReturn Intersects(object value) { return(this.Add(SpatialRestrictions.Intersects(this.propertyName, value))); }