有没有人实现这个,或者知道实现这个困难/是否有任何指针?
public static SpatialRelationCriterion IsWithinDistance(string propertyName, object anotherGeometry, double distance)
{
// TODO: Implement
throw new NotImplementedException();
}
来自NHibernate.Spatial.Criterion.SpatialRestrictions
我可以在hql中使用“ where NHSP.Distance(PROPERTY,:point)”。但是要将此查询与我现有的条件查询结合在一起。
目前,我正在创建一个粗糙的多边形,并使用
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吗?