带有错误的有效GEOJSON多边形文档的2dsphere索引失败:无法从对象,格式错误的几何体中提取地理位置键?

时间:2014-12-19 18:52:14

标签: mongodb geospatial geojson

当我插入带有有效GeoJSON对象(称为GEOJSONPOlYGON)的文档然后尝试在GEOJSONPOlYGON上的文档上创建2dsphere索引时,索引无法创建错误:“无法从对象中提取地理键,格式不正确几何?” 我遵循mongo文档和geoJSON文档无济于事。任何人都可以帮我解决这个问题吗? Polygon在http://geojsonlint.com/

中正确呈现

以下是重现的步骤。

重现步骤:

1)

mongodbshell> db.vendors.insert({ "NAME": "LUIGIS HARDWARE SUPPLY", "GEOJSONPOlYGON": { "type": "Polygon", "coordinates": [ [ [ -74.01087951660156, 40.73202133178711 ], [ -74.00675964355469, 40.73277282714844 ], [ -74.00328063964844, 40.73329162597656 ], [ -74.002685546875, 40.7330322265625 ], [ -74.0023322241211, 40.73254394533125 ], [ -74.00152587890625, 40.73143768310547 ], [ -74.00079345703125, 40.73137283325195 ], [ -73.99939771118164, 40.73091888427734 ], [ -73.99551391601562, 40.7287712097168 ], [ -73.99191284179688, 40.72701644897461 ], [ -73.98985290527344, 40.72616958618164 ], [ -73.989325018310547, 40.725384533691406 ], [ -73.98374496459961, 40.723512817382812 ], [ -73.983689270019531, 40.72489929199219 ], [ -73.973826385498047, 40.72125625610352 ], [ -73.97440338134766, 40.72047805786133 ], [ -73.97418975830078, 40.72200775146484 ], [ -73.97337341308594, 40.72340393066406 ], [ -73.97174072265625, 40.7264289855957 ], [ -73.97148132324219, 40.72916030883789 ], [ -73.97332763671875, 40.73130798339844 ], [ -73.97461700439453, 40.73602294921875 ], [ -73.97294616699219, 40.73894882202148 ], [ -73.97113800048828, 40.74395751953125 ], [ -73.986835327148438, 40.74704742431641 ], [ -73.96345520019531, 40.75289916992188 ], [ -73.95843505859375, 40.75819778442383 ], [ -73.95530700683594, 40.76128387451172 ], [ -73.925002746582031, 40.7671012878418 ], [ -73.94731903076172, 40.77009201049805 ], [ -73.94818115234375, 40.77070999145508 ], [ -73.95002746582031, 40.77149200439453 ], [ -73.95221710205078, 40.77239990234375 ], [ -73.954365850830078, 40.773434131469727 ], [ -73.96379852294922, 40.77727508544922 ], [ -73.967134782714844, 40.772823333374023 ], [ -73.96997833251953, 40.76898956298828 ], [ -73.97084045410156, 40.76788330078125 ], [ -73.97268676757812, 40.76525115966797 ], [ -73.97315979003906, 40.76463317871094 ], [ -73.9812240600586, 40.76814270019531 ], [ -73.9791259765625, 40.77149200439453 ], [ -73.97667694091797, 40.77509689331055 ], [ -73.981236983642578, 40.76817370324707 ], [ -73.97581481933594, 40.77584457397461 ], [ -73.97178649902344, 40.78150177001953 ], [ -73.9755630493164, 40.78232151184082 ], [ -73.97380044555664, 40.783332138061523 ], [ -73.9795913696289, 40.78400039672852 ], [ -73.983414611816406, 40.78582000732422 ], [ -73.98564910888672, 40.78387069702148 ], [ -73.98676300048828, 40.78227996826172 ], [ -73.98895263671875, 40.77964782714844 ], [ -73.99212646484375, 40.77529144287109 ], [ -73.99491882324219, 40.77155685424805 ], [ -73.9953842163086, 40.76996231079102 ], [ -73.9964599609375, 40.76814270019531 ], [ -73.99791717529297, 40.76615905761719 ], [ -73.999830926513672, 40.764034571533203 ], [ -74.00409698486328, 40.76323318481445 ], [ -74.00015258789062, 40.76408004760742 ], [ -74.002351007080078, 40.760395962524414 ], [ -74.00543212890625, 40.75748062133789 ], [ -74.00800323486328, 40.75331878662109 ], [ -74.00839233398438, 40.75172805786133 ], [ -74.00890350341797, 40.75088119506836 ], [ -74.009033203125, 40.74997329711914 ], [ -74.00826263427734, 40.74867248535156 ], [ -74.00873565673828, 40.74733734130859 ], [ -74.00886535644531, 40.7459716796875 ], [ -74.00899505615234, 40.74541854858398 ], [ -74.00924682617188, 40.74324035644531 ], [ -74.009731984863281, 40.740377224731445 ], [ -74.010340649414062, 40.738623457275391 ], [ -74.01087951660156, 40.73202133178711 ] ] ] }}) WriteResult({ "nInserted" : 1 })

2)看到索引的创建因上述错误而失败。

mongodbshell> db.vendors.ensureIndex({GEOJSONPOlYGON : "2dsphere"}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "ok" : 0, "errmsg" : "Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('549471aa68cfa2950001cd6e'), NAME: \"LUIGIS HARDWARE SUPPLY\", GEOJSONPOlYGON: { type: \"Polygon\", coordinates: [ [ [ -74.01087951660156, 40.73202133178711 ], [ -74.00675964355469, 40.73277282714844 ], [ -74.00328063964844, 40.73329162597656 ], [ -74.002685546875, 40.7330322265625 ], [ -74.0023322241211, 40.73254394533125 ], [ -74.00152587890625, 40.73143768310547 ], [ -74.00079345703125, 40.73137283325195 ], [ -73.99939771118164, 40.73091888427734 ], [ -73.99551391601562, 40.7287712097168 ], [ -73.99191284179688, 40.72701644897461 ], [ -73.98985290527344, 40.72616958618164 ], [ -73.98932501831055, 40.7253845336914 ], [ -73.98374496459961, 40.72351281738281 ], [ -73.98368927001952, 40.72489929199219 ], [ -73.97382638549804, 40.72125625610352 ], [ -73.97440338134766, 40.72047805786133 ], [ -73.97418975830078, 40.72200775146484 ], [ -73.97337341308594, 40.72340393066406 ], [ -73.97174072265625, 40.7264289855957 ], [ -73.97148132324219, 40.72916030883789 ], [ -73.97332763671875, 40.73130798339844 ], [ -73.97461700439453, 40.73602294921875 ], [ -73.97294616699219, 40.73894882202148 ], [ -73.97113800048828, 40.74395751953125 ], [ -73.98683532714844, 40.74704742431641 ], [ -73.96345520019531, 40.75289916992188 ], [ -73.95843505859375, 40.75819778442383 ], [ -73.95530700683594, 40.76128387451172 ], [ -73.92500274658204, 40.7671012878418 ], [ -73.94731903076172, 40.77009201049805 ], [ -73.94818115234375, 40.77070999145508 ], [ -73.95002746582031, 40.77149200439453 ], [ -73.95221710205078, 40.77239990234375 ], [ -73.95436585083007, 40.77343413146973 ], [ -73.96379852294922, 40.77727508544922 ], [ -73.96713478271485, 40.77282333337402 ], [ -73.96997833251953, 40.76898956298828 ], [ -73.97084045410156, 40.76788330078125 ], [ -73.97268676757812, 40.76525115966797 ], [ -73.97315979003906, 40.76463317871094 ], [ -73.98122406005859, 40.76814270019531 ], [ -73.9791259765625, 40.77149200439453 ], [ -73.97667694091797, 40.77509689331055 ], [ -73.98123698364257, 40.76817370324707 ], [ -73.97581481933594, 40.77584457397461 ], [ -73.97178649902344, 40.78150177001953 ], [ -73.97556304931641, 40.78232151184082 ], [ -73.97380044555663, 40.78333213806152 ], [ -73.97959136962891, 40.78400039672852 ], [ -73.9834146118164, 40.78582000732422 ], [ -73.98564910888672, 40.78387069702148 ], [ -73.98676300048828, 40.78227996826172 ], [ -73.98895263671875, 40.77964782714844 ], [ -73.99212646484375, 40.77529144287109 ], [ -73.99491882324219, 40.77155685424805 ], [ -73.99538421630859, 40.76996231079102 ], [ -73.9964599609375, 40.76814270019531 ], [ -73.99791717529297, 40.76615905761719 ], [ -73.99983092651367, 40.7640345715332 ], [ -74.00409698486328, 40.76323318481445 ], [ -74.00015258789062, 40.76408004760742 ], [ -74.00235100708008, 40.76039596252441 ], [ -74.00543212890625, 40.75748062133789 ], [ -74.00800323486328, 40.75331878662109 ], [ -74.00839233398438, 40.75172805786133 ], [ -74.00890350341797, 40.75088119506836 ], [ -74.009033203125, 40.74997329711914 ], [ -74.00826263427734, 40.74867248535156 ], [ -74.00873565673828, 40.74733734130859 ], [ -74.00886535644531, 40.7459716796875 ], [ -74.00899505615234, 40.74541854858398 ], [ -74.00924682617188, 40.74324035644531 ], [ -74.00973198486328, 40.74037722473145 ], [ -74.01034064941406, 40.73862345727539 ], [ -74.01087951660156, 40.73202133178711 ] ] ] } }", "code" : 16755 } mongodbshell> `

1 个答案:

答案 0 :(得分:2)

如果您在GeoJsonLint上可视化多边形并查看第50街附近的西侧,您将看到多边形的边界与自身交叉。请注意两点:

[-73.999830926513672,40.764034571533203],[ - 74.00409698486328,40.76323318481445]

导致多边形自身重叠,而不是正确形成的多边形。

修正了奇数点导致2dsphere索引构建成功。

MapShaper等工具可用于修复和简化损坏的Pologons / Multipolygons