- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在寻找移植 dynamo-geo.js 的一部分库到 golang,以便查询到给定点的最近点(存储在 DyanmoDB 中)。
通过 radius 查询是理想的,但如果通过 rectangle 查询是一种更直接的算法,我也很喜欢。
这是我想出的按半径查询的代码,但我似乎无法获得覆盖单元格的非空列表。
我的算法有什么问题?
// Query a circular area constructed by a center point and its radius.
// @see https://github.com/rh389/dynamodb-geo.js/blob/6c388b9070014a096885e00fff6c3fc933d9853f/src/GeoDataManager.ts#L229
func queryRadius(lat float64, lng float64, radiusMeters float64) (error) {
earthRadiusMeters := 6367000.0
// Step1: Get the bounding region (rectangle) from the center and the radius
// @see https://github.com/rh389/dynamodb-geo.js/blob/6c388b9070014a096885e00fff6c3fc933d9853f/src/s2/S2Util.ts#L23
centerLatLng := s2.LatLngFromDegrees(lat, lng)
latReferenceUnit := 1.0
if lat > 0.0 {
latReferenceUnit = -1.0
}
latReferenceLatLng := s2.LatLngFromDegrees(lat+latReferenceUnit, lng)
lngReferenceUnit := 1.0
if lng > 0.0 {
lngReferenceUnit = -1.0
}
lngReferenceLatLng := s2.LatLngFromDegrees(lat, lng+lngReferenceUnit)
latForRadius := radiusMeters / centerLatLng.Distance(latReferenceLatLng).Radians() * earthRadiusMeters
lngForRadius := radiusMeters / centerLatLng.Distance(lngReferenceLatLng).Radians() * earthRadiusMeters
minLatLng := s2.LatLngFromDegrees(lat-latForRadius, lng-lngForRadius)
maxLatLng := s2.LatLngFromDegrees(lat+latForRadius, lng+lngForRadius)
boundingRect := s2.RectFromLatLng(minLatLng)
boundingRect = boundingRect.AddPoint(maxLatLng)
// Step2: Compute the CellIDs for the region we want to cover.
// defaults per https://github.com/vekexasia/nodes2-ts/blob/1952d8c1f6cb4a862731ace2d5f74d472ec22e55/src/S2RegionCoverer.ts#L101
rc := &s2.RegionCoverer{MaxLevel: 30, MaxCells: 8, LevelMod: 1}
r := s2.Region(boundingRect.CapBound())
coveringCells := rc.Covering(r)
for _, c := range coveringCells {
log.WithFields(log.Fields{
"Covering Cell": c,
}).Info("=>")
}
return nil
}
最佳答案
注意:这是对我的特定原始问题的回答,但是我一直无法找到我要解决的问题的完整解决方案(查询最近的点,存储在DyanmoDB,使用 S2 到给定点)。如果/当我得到一个完整的解决方案时,我会更新这个答案。我目前在 this issue 上被屏蔽了.任何帮助表示赞赏。
这是一个完整的围棋程序,它从一个点(以度为单位)和一个半径(以米为单位)计算覆盖单元。
FWIW 从一个点和一个半径确定边界正方形的算法不是很准确。所以到 Martin F用于提供边界框算法。
package main
import (
"fmt"
"math"
"strconv"
"github.com/golang/geo/s2"
)
const earthRadiusM = 6371000 // per https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
const hashLength = 8 // < 1km per https://github.com/rh389/dynamodb-geo.js/blob/master/test/integration/hashKeyLength.ts
func main() {
lowPrefix := uint64(0)
highPrefix := uint64(0)
ctrLat := 52.225730 // Cambridge UK
ctrLng := 0.149593
boundingSq := squareFromCenterAndRadius(ctrLat, ctrLng, 500)
fmt.Printf("\nBounding sq %+v\n", boundingSq)
coveringCells := getCoveringCells(boundingSq)
fmt.Printf("Covering Cells (%d):\n", len(coveringCells))
for idx, cell := range coveringCells {
// cell is the UUID of the center of this cell
fullHash, hashPrefix := genCellIntPrefix(cell)
if 0 == idx {
lowPrefix = hashPrefix
highPrefix = hashPrefix
} else if hashPrefix < lowPrefix {
lowPrefix = hashPrefix
} else if hashPrefix > highPrefix {
highPrefix = hashPrefix
}
fmt.Printf("\tID:%19v uint64: %-19d prefix: %-10d Range: %-19d - %-19d\n", cell, fullHash, hashPrefix, uint64(cell.RangeMin()), uint64(cell.RangeMax()))
}
fmt.Printf("\tPrefix Range from loop: %-10d - %-10d\n", lowPrefix, highPrefix)
// TODO: Assuming covering cells are sorted. Correct assumption?
_, lowPrefix = genCellIntPrefix(coveringCells[0].RangeMin())
_, highPrefix = genCellIntPrefix(coveringCells[len(coveringCells)-1].RangeMax())
fmt.Printf("\tPrefix Range direct: %-10d - %-10d\n", lowPrefix, highPrefix)
}
// Get bounding box square from center point and radius
// Boundnig box is not extremely accurate to the radiusMeters passed in
// @see https://gis.stackexchange.com/questions/80809/calculating-bounding-box-coordinates-based-on-center-and-radius
func squareFromCenterAndRadius(centerLatDegrees float64, centerLngDegrees float64, radiusMeters float32) s2.Rect {
latLng := s2.LatLngFromDegrees(centerLatDegrees, centerLngDegrees)
deltaLng := float64(360 * radiusMeters / earthRadiusM) //Search Radius, difference in lat
deltaLat := deltaLng * math.Cos(latLng.Lng.Radians()) //Search Radius, difference in lng
lowerLeftLatDeg := centerLatDegrees - deltaLat
lowerLeftLngDeg := centerLngDegrees - deltaLng
lowerLeft := s2.LatLngFromDegrees(lowerLeftLatDeg, lowerLeftLngDeg) // AKA s2.Rect.Lo
upperRightLatDeg := centerLatDegrees + deltaLat
upperRightLngDeg := centerLngDegrees + deltaLng
upperRight := s2.LatLngFromDegrees(upperRightLatDeg, upperRightLngDeg) // AKA s2.Rect.Hi
boundingSquare := s2.RectFromLatLng(lowerLeft).AddPoint(upperRight)
return boundingSquare
}
func getCoveringCells(boundingRect s2.Rect) s2.CellUnion {
// defaults per https://github.com/vekexasia/nodes2-ts/blob/1952d8c1f6cb4a862731ace2d5f74d472ec22e55/src/S2RegionCoverer.ts#L101
rc := &s2.RegionCoverer{
MinLevel: 12, // 3km^2 per http://s2geometry.io/resources/s2cell_statistics
MaxLevel: 20, // 46m^2 per http://s2geometry.io/resources/s2cell_statistics
MaxCells: 8,
LevelMod: 1,
}
return rc.Covering(boundingRect)
}
func genCellIntPrefix(cell s2.CellID) (hash uint64, prefix uint64) {
hash = uint64(cell)
geohashString := strconv.FormatUint(hash, 10)
denominator := math.Pow10(len(geohashString) - hashLength)
prefix = hash / uint64(denominator)
return
}
我绝不是 GIS 专家,因此欢迎提出任何改进建议/意见。
关于go - 将 golang S2 几何库与 dynamodb 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57014657/
我正在使用 Boto3 和 Python 开发 Dyanamodb。我发现的问题之一是我们应该何时使用 dynamodb.client、dynamodb.resource 和 dynamodb.Tab
DynamoDB documentation描述了表分区原则上是如何工作的,但它对细节(即数字)非常了解。 DynamoDB 表分区究竟如何以及何时发生? 最佳答案 我找到了这个 presentati
我在 DynamoDB 表中有一个项目。该项目看起来像这样: { data: [ 1, 2, 3, 4, 5, 6 ] more_data: [ 2, 3, 4, 5, 6, 7 ] } 使用
我的 DynamoDB 表中的一个属性是一个名为 REQUEST_IDS 的列表,我想在更新项目之前检查该列表的长度以查看它是否满足条件(小于 10) .如何在 nodejs 的 ConditionE
我正在使用 Amazon Dynamodb,但没有太多经验。我有这样的价格表: 编号 |插入日期 |产品名称 |店名 |价格 相同的商店名称和产品名称可以有不同的值(价格和插入日期可能不同)。例如 i
我对 DynamoDB 上查询/扫描的限制有疑问。 我的表有 1000 条记录,对所有记录的查询返回 50 个值,但是如果我将 Limit 设置为 5,这并不意味着查询将返回前 5 个值,它只是说查询
我需要在 jsp 上显示最大计数为 10 的搜索结果,并且它应该有一个分页来作为分页功能来回遍历。 Dynamodb 有一个 最后评估 key ,但返回上一页无济于事,尽管我可以通过 移动到下一个结果
我是 CouchDB 的忠实粉丝,并且完全爱上了每个文档发出不止一次的 map 函数。我想知道在 DynamoDB 中是否可以通过使用字符串或数字集类型作为散列和范围主键的一部分(作为散列或范围属性)
我目前正在使用 DynamoDB。如果该记录的日期早于新记录日期字段,我想使用条件写入来更新记录。 有没有办法比较条件写入的 DateTime 类型?还是目前仅适用于整数、字符串和流? 谢谢。 最佳答
如何对 dynamoDB 表建模以构建一个标签系统,其中产品可以分配多个标签,并且我们应该能够过滤具有特定标签或标签集合的产品集,并获取分配给给定标签的所有标签产品? 我考虑过有一张 table :
我试图更好地理解在 AWS DynamoDB 中使用邻接列表模式进行多对多 (m:n) 关系设计。 在此处查看 AWS 文档:https://docs.aws.amazon.com/amazondyn
我怀疑 DynamoDB 中的这一说法是否属实或我的理解不正确。它说, ProvisionedThroughputExceededException 消息:您超出了表或一个或多个全局二级索引的最大允许
考虑一个 DynamoDB 表,它由一个主键和两个描述开始日期和结束日期的属性组成。如何在不扫描整个表的情况下查询时间范围是否与表中的时间范围重叠? 例子: 发电机表有两条记录 PK Start
我有一个 DynamoDB 表,其中包含将由许多应用程序读取的键值对。在启动时,每个应用程序将读取整个表并将其缓存在内存中。 我试图解决的问题是,如果 DynamoDB 表中的一个或多个项目已被修改,
我正在有条件地更新 dynamoDB 记录(仅当记录具有其属性之一的特定值时)。无论是否成功更新(条件是否满足),我都想取回记录。 docClient.update(params, function(
我目前正在对 DynamoDB 进行批量加载并将我们的数据项划分为批处理单元: 根据限制文件: https://docs.aws.amazon.com/amazondynamodb/latest/AP
我正在跟踪dynamodb的Python教程,以在端口8000上设置本地dynomodb http://docs.aws.amazon.com/amazondynamodb/latest/gettin
我正在创建一个 DynamoDB 表来保存与单个对象关联的注释。 评论在特定时间发布到对象,我使用发布的时间作为范围,因此评论可以按时间降序排序。我有发布评论的用户的 userId 的全局二级索引,这
我正在运行一个简单的 api,它在每次调用时从 dynamodb 表中获取一个项目,我将自动缩放设置为最小值 25 和最大值 10 000。 但是,如果我使用 wrk 或 hey 之类的工具发送 15
我在模型中有一个字段已声明为字符串,如下所示: App.Student= DS.Model.extend({ name: DS.attr('string'), address1: DS.attr('s
我是一名优秀的程序员,十分优秀!