MongoDb: $geoIntersects for multiple input coordinates
up vote
1
down vote
favorite
I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:
db.polygons.find({
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})
The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.
Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.
mongodb geospatial
add a comment |
up vote
1
down vote
favorite
I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:
db.polygons.find({
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})
The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.
Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.
mongodb geospatial
Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08
@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:
db.polygons.find({
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})
The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.
Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.
mongodb geospatial
I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:
db.polygons.find({
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})
The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.
Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.
mongodb geospatial
mongodb geospatial
asked Nov 10 at 16:39
Yuriy Yunikov
3,1502247
3,1502247
Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08
@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago
add a comment |
Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08
@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago
Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08
Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08
@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago
@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.
1
I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.
1
I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago
add a comment |
up vote
1
down vote
accepted
One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.
1
I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.
One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.
answered 2 days ago
lusitanica
30117
30117
1
I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago
add a comment |
1
I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago
1
1
I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago
I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241083%2fmongodb-geointersects-for-multiple-input-coordinates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08
@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago