- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在从 MongoDb 迁移到 RavenDb,但遇到了一个问题。
我们有一个简单的模型(C# DotNet)
using System.Globalization;
public class Location
{
#region Properties
public double Latitude { get; set; }
public double Longitude { get; set; }
#endregion Properties
#region Methods
public override string ToString()
{
var numberFormatInfo = new NumberFormatInfo { NumberDecimalSeparator = "." };
return $"{Longitude.ToString(numberFormatInfo)} {Latitude.ToString(numberFormatInfo)}";
}
#endregion Methods
}
public class Place
{
public Location[] Area {get;set;} // Please note the array
}
客户可以选择一个地点作为一对,或者他们可以在交互式 map 上绘制一个多边形,代表该地点,该多边形将存储在上面的 Area 属性中。
var locationQuery = new FilterDefinitionBuilder<Place>()
.GeoWithinBox(
field: x => x.Area,
lowerLeftX: query.Criteria.LongitudeBottomLeft,
lowerLeftY: query.Criteria.LatitudeBottomLeft,
upperRightX: query.Criteria.LongitudeTopRight,
upperRightY: query.Criteria.LatitudeTopRight);
上面的查询类,代表了 map 上当前可见的区域,客户正在查看。
using System.Linq;
using Raven.Client.Documents.Indexes;
public class PlaceAreaIndex : AbstractIndexCreationTask<Place>
{
public PlaceAreaIndex()
{
Map = places => from place in places
select new
{
Area = place.Area.Select(location => CreateSpatialField(location.Latitude, location.Longitude))
};
}
}
在使用查询之前,您需要在服务器上注册您的索引。
new PlaceAreaIndex().Execute(store);
我添加了一些辅助类来帮助我测试这一点,我在此处添加它们以便示例让您尽可能接近正在运行的代码
public class Box
{
#region Constructor
public Box(Location topRight, Location bottomLeft)
{
TopRight = topRight;
BottomLeft = bottomLeft;
TopLeft = new Location { Latitude = topRight.Latitude, Longitude = bottomLeft.Longitude };
BottomRight = new Location { Latitude = bottomLeft.Latitude, Longitude = topRight.Longitude };
}
#endregion Constructor
#region Properties
public Location TopRight { get;}
public Location TopLeft { get; }
public Location BottomLeft { get; }
public Location BottomRight { get; }
#endregion Properties
#region Methods
public override string ToString()
{
return $"POLYGON (({TopRight}, {TopLeft}, {BottomLeft}, {BottomRight}, {TopRight}))";
}
#endregion Methods
}
然后使用助手
var topRight = Location.New(latitude: -22.674847351188916, longitude: 31.25061035156253);
var bottomLeft = Location.New(latitude: -28.9600886880069, longitude: 25.1422119140623);
var box = new Box(topRight: topRight, bottomLeft: bottomLeft);
之后你可以这样查询
var places = await session
.Query<Place, PlaceAreaIndex>()
.Spatial(
factory => factory.Area,
criteria => criteria.RelatesToShape(
shapeWkt: box.ToString(),
relation: SpatialRelation.Within))
.ToArrayAsync();
希望对你有帮助。
最佳答案
IIUC,问题是您可能有特定位置或多边形,对吗?
在 RavenDB 中表示多边形时,您需要为此使用 WKT。
例如,下面是这个样子:
POLYGON((14.316406249999982 37.541615344157876,32.68554687499998 37.541615344157876,32.68554687499998 25.439901234431595,14.316406249999982 25.439901234431595,14.316406249999982 37.541615344157876))
然后可以由 RavenDB 内部的空间引擎使用它,并允许您使用
spatial.Contains
进行查询。 .
Places
如果在矩形内有一个 Location ,那么将其作为一系列位置进行威胁会更容易。
$wkt = "POLYGON((-1.0800308814195025 51.942980464942416,0.5789046654554975 51.942980464942416,0.5789046654554975 51.01935531918276,-1.0800308814195025 51.01935531918276,-1.0800308814195025 51.942980464942416))"
from Employees
where spatial.within( spatial.point(Address.Location.Latitude , Address .Location.Longitude),
spatial.wkt($wkt))
然后您可以看到新的空间选项卡,它将显示结果:
"Locations": [
{
"Latitude": 51.52384070000001,
"Longitude": -0.0944233
},
{
"Latitude": 51.48145355123356,
"Longitude": -0.17475717569860105
}
],
但是,需要一个显式索引来处理,你可以这样写:
from e in docs.Employees
select new
{
Locations = e.Locations.Select(l => CreateSpatialField(l.Latitude, l.Longitude))
}
此索引员工的所有个人位置。
$wkt = "POLYGON((-1.0800308814195025 51.942980464942416,0.5789046654554975 51.942980464942416,0.5789046654554975 51.01935531918276,-1.0800308814195025 51.01935531918276,-1.0800308814195025 51.942980464942416))"
from index 'Employees/ByLocations'
where spatial.within( Locations, spatial.wkt($wkt))
然而,另一种选择是当您需要将位置列表转换为 ploygon 时。
POLYGON((-0.09345874990495329 51.7543103056377,-0.6823256691840518 51.56348306507395,-0.2252946874049533 51.30046869394702,0.09990102742639895 51.42120466591834,-0.09345874990495329 51.7543103056377))
这代表这个多边形:
contains
查询现在需要包括整个多边形。您可以使用 intersect
同样,但是您可能会更好地使用单点选项。 关于c# - RavenDb 空间查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67149032/
我正在玩Raven DB几天,我想将其用作Web聊天应用程序的存储。我有包含一些用户数据和聊天记录的文档-这是大集合的聊天消息。 每次加载用户文档时,聊天记录也会加载,即使我只需要几个字段,例如:用户
我的实体是: class Resource { string Name; string EmployeeId; } 如何查询多名员工的资源?我尝试了这个: Resource[] Fin
我知道这篇文章的标题会让一些人感到畏缩。我自 2011 年 12 月以来一直在使用 RavenDB,并且逐渐意识到我以不适合使用文档数据库的方式对数据进行建模。首先,我完全明白这一点。其次,考虑到我目
考虑 2 个查询: var test1 = store.OpenSession().Query().Where(x => x.Id == 1).ToList(); var test2 =
我正在运行 RavenDB.Client 2.0.2173-Unstable。我正在创建一个 Multi-Tenancy 系统,作为我注册过程的一部分,我想创建一个新的 Raven 数据库。 我有三行
我正在使用在 Visual Studio 2010 中通过 NuGet 安装的嵌入式 RavenDB => RavenDB-Embedded.1.0.499 包。它正在我阅读完这篇优秀文章后开始的当前
我们在 AWS 上有一个带有集群 RavenDB 服务器 (5.23) 的 DotNet Core API (C#)。创建文档时,Id 具有不同的格式,具体取决于客户端。如果使用 Swagger/Po
我想知道取回搜索记录总数的最佳方法是什么,同时取回第 N 个 128 记录块数据段,这似乎是 RavenDb 运行时强加的上限。 例如给定这个查询,我还需要知道记录的总数。 var bookmarks
我使用的是 RavenDB 2.0.3.0 版。连接调试器后,涉及 RavenDB 的所有内容都运行得非常缓慢。每个查询需要几秒钟才能完成。 如果我在调试器坐在那里时按下暂停键,我总是看到它挂断了以下
我使用以下代码从 RavenDB 中删除文档。在 Raven UI 的底部,我可以看到文档数量从 3,000,000 减少到 2,000,000。但是“数据”文件的大小不会缩小。它总是大约100G。
我想在我的 Raven DB 中轮询新文档。推荐的方法是什么?我可以使用 IndexTimestamp 还是可以依赖文档的顺序? 我想我想分两步完成: 1.检查是否有新的东西,如果有: 1.1。获取最
我已经更改了我的数据模型,并且需要将所有对象的属性更改为 null,因为在我的模型更改后反序列化它们会引发异常。 我猜我可以为每个文档发布一个补丁,但我找不到任何方法来做到这一点,修补某种类型的每个文
有没有办法在进行空间搜索时从 RavenDB 获取距离计算值。我尝试转换建议的 _ = SpatialIndex.Generate(r.Latitude, r.Longitude) 至 距离 = Sp
是否有一种明智的方法来 stub /模拟调用 IDocumentSession.Query() 的结果? ? 我有一个命令,我想验证在对象上调用了方法(即正在测试的“单元”是命令,而不是命令编排的对象
我想在存储在 RavenDB 文档数据库中的两个实体之间有一个引用。由于这不是关系数据库,我知道我应该使用 RavenDBs 文档中描述的非规范化引用技术。虽然起初这看起来不错,但一旦我开始创建一个真
是否可以使用返回单个文档但不是关键的属性从数据存储加载(而不是查询)文档? 在我的场景中,我有用户和品牌。品牌是用户,但用户不一定是品牌。每个品牌都有一个 UserId 属性及其 Id。有没有办法通过
通过官方 RavenDB 阅读一个简单的问题 documentation ,我知道您可以使用客户端 API 函数执行这些操作,但不能使用 RQL,或者无论如何都可以使用 RQL 执行。 最佳答案 您正
我正尝试在 RavenDB 中检索我按 int 列表排序的文档。 Queryable = Queryable.OrderBy(dto => SearchIds.IndexOf(dto.Property
我刚刚让 RavenDB 开始工作。 我意识到我必须启动 RavenDB\packages\RavenDB.1.0.573\server.exe 才能通过以下方式在我的应用程序中访问它: Do
RavenDB 是否有众所周知的做法来检查 RavenDb 的可用性或检查它在任何给定时间的过载程度?我研究了一些 ravendb API 服务。好像没找到关于健康监测的。有没有像官方的 ravend
我是一名优秀的程序员,十分优秀!