MongoDB错误代码16755 - 无法提取地理密钥&重复的顶点 [英] MongoDB Error Code 16755 - Can't extract geo keys & duplicate vertices
问题描述
当我尝试在几何体 db.polygons.createIndex({geometry:2dsphere})
上创建一个索引时,它停止在一个具有错误代码16755.它表示它无法提取地理键
和重复顶点:18和20
。
所以经过进一步的检查,看起来好像是这样的情况发生时,多边形中的2个节点靠得很近,甚至是重复的。
然后在QGIS中手动删除这个节点,然后重新尝试这个过程,只是发现另一个面相同的多边形。
我怎样才能解决这个问题,而没有不得不重复整个多边形>上传到MongoDB>创建索引的整个过程?有没有办法可以找出有多少个多边形有这个问题?
我碰到类似的问题。我只需要在我的数据集中找到有效的记录(我丢弃了具有重复顶点的记录)。
我重命名了集合 -
db.myCollection.renameCollection 'myCollectionBk')
然后我将原始集合中的单个记录添加到新集合中,并添加了地理空间索引到集合
db.myCollection.insert(db.myCollectionBk.findOne())//重新创建集合
db.myCollection.createIndex({geometry:2dsphere})//创建索引(假设记录上的几何体是有效的)
db.myCollection.remove({})//删除记录
然后我将有效记录添加到新集合中。
db.myCollectionBk.find()。forEach(function(x){
db.myCollection.insert(x);
})
无效的记录会被忽略。
您可能需要获取 WriteResult =nofollow noreferrer >插入,然后查看是否成功。类似于
var errors = []
db.myCollectionBk.find()。forEach(function(x){
var result = db.myCollection.insert(x);
if(result.writeError){
errors.push({x._id:result.writeError.errmsg}); $ b作为另一种选择,请查看这个问题(我无法得到这个工作)
When I try to create an index on geometry db.polygons.createIndex({"geometry":"2dsphere"})
, it stops at a certain polygon with the error code 16755. It says it Can't extract geo keys
and Duplicate vertices: 18 and 20
.
So upon further inspection, it seems like this happens when 2 nodes in a polygon are close together, or even duplicates.
I then go manually remove this node in QGIS and re-try the process, only to find there's another polygon with the same issue.
How can I fix this issue without having to repeat the entire process of fixing polygon > uploading to MongoDB > creating index? Is there a way I can find out how many polygons have this issue?
解决方案 I hit a similar problem. I just needed to find the valid records in my dataset (I discarded the records with Duplicate Vertices).
I renamed the collection -
db.myCollection.renameCollection('myCollectionBk')
Then I added a single record from the original collection into a new collection and added a geospatial index to the collection
db.myCollection.insert(db.myCollectionBk.findOne()) // recreate the collection
db.myCollection.createIndex({geometry:"2dsphere"}) // create the index (assumes the geometry on the record is valid)
db.myCollection.remove({}) // remove the record
Then I added the valid records into the new collection.
db.myCollectionBk.find().forEach(function(x){
db.myCollection.insert(x);
})
Invalid records are simply ignored.
In your case you probably want to get the WriteResult from your insert, and look to see if it was successful. Something like
var errors = []
db.myCollectionBk.find().forEach(function(x){
var result = db.myCollection.insert(x);
if (result.writeError) {
errors.push({x._id:result.writeError.errmsg});
}
})
As another alternative, check out this question (I couldn't get this to work)
这篇关于MongoDB错误代码16755 - 无法提取地理密钥&重复的顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!