2010-03-11 12 views
94

Quelqu'un a-t-il implémenté ceci, ou sait-il s'il serait difficile d'implémenter ceci/avoir des pointeurs?Critères SpatialRestrictions.IsWithinDistance NHibernate.Spatial

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

de NHibernate.Spatial.Criterion.SpatialRestrictions

je peux utiliser "où NHSP.Distance (PROPRIÉTÉ,: Point)" dans hql. Mais je veux combiner cette requête avec ma requête Criteria existante.

pour le moment je crée un polygone rugueux, et en utilisant

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

EDIT Vous avez un prototype par le constructeur sur la surcharge SpatialRelationCriterion, l'ajout de nouveaux SpatialRelation.Distance

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

a ajouté un nouveau champ à SpatialRelationCriterion

private readonly double? distance; 

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

Edité 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)); 
       } 

surcharge ISpatialDialect.GetSpatialRelationString

mis en œuvre surcharge 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(); 
     } 

Je ne sais pas pourquoi AddParameter pas utilisé?

+3

J'ai le même problème, et je n'ai trouvé aucun patch/correctif/quoi que ce soit jusqu'à présent. L'avez-vous résolu, ou êtes-vous allé avec la variante HQL? – Liedman

+1

Pensez allé avec l'approche ci-dessus, et a dll recompilled au travail, mais était encore le code expérimental. – Ian

+2

@Amresh n'êtes-vous pas satisfait de la solution proposée par OP? – Eranga

Répondre

1

Oui Je pense que Recompiler la DLL est la meilleure solution pour l'instant.

0

Nous étudions ce problème à GitHub. Merci d'avoir fourni un bon aperçu et une solution possible. Voici un lien vers le problème: https://github.com/nhibernate/NHibernate.Spatial/issues/61

Je publierai de nouveaux paquets NuGet dès qu'ils seront corrigés.

+0

cette question SO est aussi sur un problème similaire avec une solution différente http://stackoverflow.com/questions/1833879/advanced-search-with-distances-using-nhibernate-and-sql-server-geography –