Criteria SpatialRestrictions.IsWithinDistance NHibernate.Spatial

Ian*_*Ian 95 .net nhibernate spatial geospatial criteria-api

有没有人实现过这个,或者知道是否难以实现这个/有任何指针?

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

来自NHibernate.Spatial.Criterion.SpatialRestrictions

我可以在hql中使用"NHSP.Distance(PROPERTY,:point)".但是想要将此查询与我现有的Criteria查询相结合.

目前我正在创建一个粗糙的多边形,并使用

criteria.Add(SpatialRestrictions.Intersects("PROPERTY", myPolygon));
Run Code Online (Sandbox Code Playgroud)

编辑 通过在SpatialRelationCriterion上重载构造函数来获得原型,添加新的SpatialRelation.Distance

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

为SpatialRelationCriterion添加了一个新字段

private readonly double? distance;

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

编辑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));
                }
Run Code Online (Sandbox Code Playgroud)

重载了ISpatialDialect.GetSpatialRelationString

在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();
        }
Run Code Online (Sandbox Code Playgroud)

不确定为什么没有使用AddParameter?