我想在MongoDB中找到多边形的交点(图1)。
图1
我使用pymongo,使用的代码是:
intersect = db.samplecol.aggregate([
{"$match": {
"geometry": {
"$geoWithin":
{'$geometry':
{'type': 'Polygon',
'coordinates': [
[
[
-118.125,
50.2893393
],
[
-118.125,
49.3823728
],
[
-84.375,
-27.0591258
],
[
92.8125,
-23.8858377
],
[
93.515625,
52.4827802
],
[
-118.125,
50.2893393
]
]
]
}
}
}
}},
{"$match": {
"geometry": {
"$geoWithin":
{'$geometry':
{'type': 'Polygon',
'coordinates': [
[
[
-118.125,
50.2893393
],
[
-118.125,
49.3823728
],
[
-84.375,
-27.0591258
],
[
92.8125,
-23.8858377
],
[
93.515625,
52.4827802
],
[
-118.125,
50.2893393
]
]
]
}
}
}
}},
{"$group": {"_id": "$properties.vessel_hash",
"total": {"$sum": 1}, "COORDINATES": {
"$push": "$geometry.coordinates"}}},
{"$sort": {"total": 1}}
])
print "object", list(intersect)
for point in intersect:
print "Point", point
在内部查询中,我有两个$match
,以便绘制两个多边形并将其中的点“捕获”。
我有一些GeoJSON格式的文档,格式如下:
{ "_id" : ObjectId("5b06c250f211924446d4f199"), "geometry" : { "type" : "Point", "coordinates" : [ -5.383678, 36.17477 ] }, "type" : "Feature", "properties" : {"timestamp" : "20101-05-23T11:11:56.000Z", "vessel_hash" : "xxxx} }
以上代码不返回任何内容,而由于多边形覆盖了整个世界,因此它将返回所有点。
有人知道我在做什么错吗?也许我试图实现这一目标的方法是错误的。