2010-03-11 34 views
94

Có ai thực hiện điều này, hoặc biết nếu nó sẽ khó khăn để thực hiện điều này/có bất kỳ con trỏ?Tiêu chí SpatialRestrictions.IsWithinDistance NHibernate.Spatial

public static SpatialRelationCriterion IsWithinDistance(string propertyName, object anotherGeometry, double distance) 
{ 
    // TODO: Implement 
    throw new NotImplementedException(); 
} 

từ NHibernate.Spatial.Criterion.SpatialRestrictions

tôi có thể sử dụng "nơi NHSP.Distance (HỮU,: Điểm)" trong HQL. Nhưng muốn kết hợp truy vấn này với truy vấn Tiêu chí hiện tại của tôi.

cho thời điểm tôi đang tạo ra một đa giác thô, và sử dụng

criteria.Add(SpatialRestrictions.Intersects("PROPERTY", myPolygon)); 

EDIT Got một nguyên mẫu làm việc do quá tải nhà xây dựng trên SpatialRelationCriterion, thêm SpatialRelation.Distance mới

public static SpatialRelationCriterion IsWithinDistance(string propertyName, object anotherGeometry, double distance) 
     { 
      return new SpatialRelationCriterion(propertyName, SpatialRelation.Distance, anotherGeometry, distance); 
     } 

đã thêm trường mới vào SpatialRelationCriterion

private readonly double? distance; 

public SpatialRelationCriterion(string propertyName, SpatialRelation relation, object anotherGeometry, double distance) 
      : this(propertyName, relation, anotherGeometry) 
     { 
      this.distance = distance; 
     } 

Edited ToSqlString

object secondGeometry = Parameter.Placeholder; 
       if (!(this.anotherGeometry is IGeometry)) 
       { 
        secondGeometry = columns2[i]; 
       } 

       if (distance.HasValue) 
       { 
        builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, secondGeometry, distance.Value, true)); 
       } 
       else 
       { 
        builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, secondGeometry, true)); 
       } 

quá tải ISpatialDialect.GetSpatialRelationString

thực hiện quá tải trong MsSql2008SpatialDialect

public SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, double distance, bool criterion) 
     { 
      var x = new SqlStringBuilder(8) 
          .AddObject(geometry) 
          .Add(".ST") 
          .Add(relation.ToString()) 
          .Add("(") 
          .AddObject(anotherGeometry) 
          .Add(")"); 

      if (criterion) 
      { 
       x.Add(" < "); 
       x.AddObject(distance.ToString()); 
      } 

      return x.ToSqlString(); 
     } 

Không chắc chắn tại sao AddParameter không được sử dụng?

+3

Tôi gặp vấn đề tương tự và chưa tìm thấy bất kỳ bản vá/sửa chữa hoàn chỉnh nào cho đến thời điểm này. Bạn đã giải quyết nó, hoặc bạn đã đi với các biến thể HQL? – Liedman

+1

Hãy suy nghĩ đã đi với cách tiếp cận trên, và dll biên dịch lại để làm việc, nhưng vẫn còn mã thử nghiệm. – Ian

+2

@Amesh là bạn không hài lòng với giải pháp đề xuất mà OP đưa ra? – Eranga

Trả lời

1

Có tôi nghĩ rằng Biên dịch lại DLL là giải pháp tốt nhất hiện nay.

0

chúng tôi đang xem xét vấn đề này qua GitHub. Cảm ơn bạn đã cung cấp thông tin chi tiết tuyệt vời và giải pháp khả thi. Đây là liên kết đến vấn đề: https://github.com/nhibernate/NHibernate.Spatial/issues/61

Tôi sẽ xuất bản gói NuGet mới ngay khi sửa lỗi này.

+0

Câu hỏi SO này cũng là về một vấn đề tương tự với một giải pháp khác nhau http://stackoverflow.com/questions/1833879/advanced-search-with-distances-using-nhibernate-and-sql-server-geography –