2010-03-11 8 views
94

क्या किसी ने इसे कार्यान्वित किया है, या पता है कि इसे लागू करना मुश्किल होगा या कोई पॉइंटर्स होगा? HQL में:मानदंड स्पैटलियल रेस्त्रां.इस्विथिनडिस्टेंस एनएचबीर्नेट। सैटियल

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

NHibernate.Spatial.Criterion.SpatialRestrictions

से मैं "जहां NHSP.Distance (बिंदु संपत्ति,)" का उपयोग कर सकते हैं। लेकिन इस क्वेरी को मेरी मौजूदा मानदंड क्वेरी के साथ जोड़ना चाहते हैं।

पल मैं एक किसी न किसी बहुभुज बना रहा हूं, और का उपयोग कर

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

संपादित SpatialRelationCriterion पर निर्माता ओवरलोडिंग से काम कर रहे एक प्रोटोटाइप समझे के लिए

, नई SpatialRelation.Distance जोड़ने

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

ने SpatialRelationCriterion

पर एक नया फ़ील्ड जोड़ा
private readonly double? distance; 

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

संपादित 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)); 
       } 

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(); 
     } 

सुनिश्चित नहीं हैं कि में ISpatialDialect.GetSpatialRelationString

कार्यान्वित अधिभार अतिभारित क्यों AddParameter नहीं किया जा रहा?

+3

मुझे एक ही समस्या है, और अब तक कोई भी पूर्ण पैच/फिक्स/जो भी नहीं मिला है। क्या आपने इसे हल किया था, या आप एचक्यूएल संस्करण के साथ गए थे? – Liedman

+1

सोचें उपर्युक्त दृष्टिकोण के साथ चला गया, और काम करने के लिए डीएलएल recompilled, लेकिन अभी भी प्रयोगात्मक कोड था। – Ian

+2

@Amresh क्या आप प्रस्तावित समाधान ओपी से संतुष्ट नहीं हैं? – Eranga

उत्तर

1

हाँ मुझे लगता है कि डीएलएल का पुनर्मूल्यांकन अब के लिए सबसे अच्छा समाधान है।

0

हम इस मुद्दे को गिटहब में देख रहे हैं। महान अंतर्दृष्टि और एक संभावित समाधान प्रदान करने के लिए धन्यवाद। यहां समस्या का एक लिंक दिया गया है: https://github.com/nhibernate/NHibernate.Spatial/issues/61

जैसे ही यह तय हो गया है, मैं नए NuGet संकुल प्रकाशित करूंगा।

+0

यह SO प्रश्न भी एक अलग समाधान के साथ एक समान समस्या के बारे में है http://stackoverflow.com/questions/1833879/advanced-search-with-distances-using-nhibernate-and-sql-server-geography –

संबंधित मुद्दे