Criteria SpatialRestrictions.IsWithinDistance NHibernate.Spatial [英] Criteria SpatialRestrictions.IsWithinDistance NHibernate.Spatial

查看:146
本文介绍了Criteria SpatialRestrictions.IsWithinDistance NHibernate.Spatial的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人执行过此操作,还是知道执行此操作是否困难/有任何指针?

Has anyone implemented this, or know if it would be difficult to implement this/have any pointers?

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

来自NHibernate.Spatial.Criterion.SpatialRestrictions

from NHibernate.Spatial.Criterion.SpatialRestrictions

我可以在hql中使用"where NHSP.Distance(PROPERTY,:point)".但是想将此查询与我现有的条件查询结合起来.

I can use "where NHSP.Distance(PROPERTY, :point)" in hql. But want to combine this query with my existing Criteria query.

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

for the moment I'm creating a rough polygon, and using

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

EDIT 通过在SpatialRelationCriterion上重载构造函数,并添加新的SpatialRelation.Distance

EDIT Got a prototype working by overloading constructor on SpatialRelationCriterion, adding new SpatialRelation.Distance

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

为SpatialRelationCriterion添加了一个新字段

added a new field to SpatialRelationCriterion

private readonly double? distance;

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

编辑的ToSqlString

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

重载了ISpatialDialect.GetSpatialRelationString

overloaded ISpatialDialect.GetSpatialRelationString

在MsSql2008SpatialDialect中实现的重载

implemented overload in 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吗?

Not sure why AddParameter not being used?

推荐答案

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

we are looking into this issue over at GitHub. Thanks for providing great insight and a possible solution. Here's a link to the issue: https://github.com/nhibernate/NHibernate.Spatial/issues/61

在修复后,我将发布新的NuGet软件包.

I will publish new NuGet packages as soon as this is fixed.

这篇关于Criteria SpatialRestrictions.IsWithinDistance NHibernate.Spatial的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆