94

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

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

来自 NHibernate.Spatial.Criterion.SpatialRestrictions

我可以在 hql 中使用“哪里 NHSP.Distance(PROPERTY, :point)”。但是想将此查询与我现有的 Criteria 查询结合起来。

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

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

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

不确定为什么不使用 AddParameter?

4

2 回答 2

1

我们正在 GitHub 上研究这个问题。感谢您提供深刻的见解和可能的解决方案。这是该问题的链接:https ://github.com/nhibernate/NHibernate.Spatial/issues/61

一旦解决此问题,我将发布新的 NuGet 包。

于 2016-05-24T10:23:28.570 回答
0

是的,我认为重新编译 DLL 是目前最好的解决方案。

于 2012-12-04T23:43:09.293 回答