Related
I have the following object in my Collection:
{
"_id":"test123",
"footprint":{
"type":"Polygon",
"coordinates":[
[
[10, 30], [20, 45], [38, 38], [43, 38], [45, 30], [10, 30]
]
]
}
}
with index of type "2dsphere" on "footprint" attribute.
Now, I would like to implements the geospatial query "overlaps", as implemented by ST_Overlaps in PostGIS: https://postgis.net/docs/ST_Overlaps.html.
Due to the fact that MongoDB doesn't support "overlap" natively (only within, intersect and near) and according to the above definition, I whould return all overlapping documents not totally within the search area.
Therefore, I'm trying to execute the following filter:
{
"footprint":{
"$geoIntersects":{
"$geometry":{
"type":"Polygon",
"coordinates":[
[
[
41.62109375000001,
38.087716380862716
],
[
41.870727539062514,
37.998201197578084
],
[
41.72393798828124,
38.01268326428104
],
[
41.62109375000001,
38.087716380862716
]
]
]
}
},
"$not":{
"$geoWithin":{
"$geometry":{
"type":"Polygon",
"coordinates":[
[
[
41.62109375000001,
38.087716380862716
],
[
41.870727539062514,
37.998201197578084
],
[
41.72393798828124,
38.01268326428104
],
[
41.62109375000001,
38.087716380862716
]
]
]
}
}
}
}
}
But I get the following error:
can't parse extra field: $not: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [ [ [ 41.62109375000001, 38.08771638086272 ], [ 41.87072753906251, 37.99820119757808 ], [ 41.72393798828124, 38.01268326428104 ], [ 41.62109375000001, 38.08771638086272 ] ] ] } } }
After several tests, it seems I can't execute a second filter on the same attribute.
Am I wrong? Is there any workaround?
Thanks
This is due to the query language and how it parses objects, the object you're trying to use looks like this:
{ key: { query1, query2 }}
Where query1 is $geoIntersects and query2 is $not which is just not a valid structure, what you can do is wrap both of them with an $and query like so:
{
$and: [
{
"footprint": {
"$geoIntersects": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[
[
41.62109375000001,
38.087716380862716
],
[
41.870727539062514,
37.998201197578084
],
[
41.72393798828124,
38.01268326428104
],
[
41.62109375000001,
38.087716380862716
]
]
]
}
}
}
},
{
footprint: {
"$not": {
"$geoWithin": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[
[
41.62109375000001,
38.087716380862716
],
[
41.870727539062514,
37.998201197578084
],
[
41.72393798828124,
38.01268326428104
],
[
41.62109375000001,
38.087716380862716
]
]
]
}
}
}
}
}
]
}
I am attempting to create a query that will return all documents which have a polygon or LineString which contains a point on the longitude,latitude coordinate system. Can anyone help me to pinpoint the issue with my query? I have tried to troubleshoot this for quite a while and my query appears to follow the mongo 2.6.5 documentation.
So far, considering a document which is in the vendor collection may be defined as follows:
{ "VENDOR": "LUIGIS HARDWARE STORE", "AREA_ON_EARTH_THAT_SHOP_SERVICES": { "type": "LineString", "coordinates": [ [ -73.987792968875, 40.728235015886916 ], [ -73.98737335280508, 40.71806335844922 ], [ -73.986816840625, 40.72778488158918 ], [ -73.98597718728516, 40.71747858911133 ], [ -73.98331451418602, 40.726640847241214 ], [ -73.98307800292969, 40.71710968017578 ], [ -73.9828872680664, 40.71734619140625 ], [ -73.98235321044922, 40.718345642089844 ], [ -73.98203751708984, 40.729120025634764 ], [ -73.98183781738281, 40.719478607177734 ], [ -73.9813332421875, 40.720550537109375 ], [ -73.98103095458984, 40.72093963623047 ], [ -73.9805679321289, 40.72159957885742 ], [ -73.98014068603516, 40.72217559814453 ], [ -73.97969055175781, 40.722801208496094 ], [ -73.97838592529297, 40.72460174560547 ], [ -73.97750091552734, 40.72579574584961 ], [ -73.97659301757812, 40.72700500488281 ], [ -73.97615814208984, 40.7276725769043 ], [ -73.97564697265625, 40.72834014892578 ], [ -73.9739761352539, 40.734655670166016 ], [ -73.9738998413086, 40.73478918457031 ], [ -73.97396087646484, 40.7410791015625 ], [ -73.9742660522461, 40.732242584228516 ], [ -73.97443389892578, 40.732810974121094 ], [ -73.97505950927734, 40.735130310058594 ], [ -73.9751205444336, 40.735748291015625 ], [ -73.9751205444336, 40.73612976074219 ], [ -73.97500610351562, 40.73664855957031 ], [ -73.97478485107422, 40.737037658691406 ], [ -73.97380828857422, 40.73845291137695 ], [ -73.97335815429688, 40.73912811279297 ], [ -73.9732437133789, 40.73942947387695 ], [ -73.97313690185547, 40.73974609375 ], [ -73.97337341308594, 40.73988342285156 ], [ -73.97344970703125, 40.7398681640625 ], [ -73.97357940673828, 40.73987579345703 ], [ -73.97401428222656, 40.74009704589844 ], [ -73.97419738769531, 40.740135192871094 ], [ -73.97447967529297, 40.74012756347656 ], [ -73.97579956054688, 40.74070358276367 ], [ -73.98030090332031, 40.742591857910156 ], [ -73.9834213256836, 40.74393081665039 ], [ -73.9886245727539, 40.74612045288086 ], [ -73.9901123046875, 40.74671173095703 ], [ -73.99053955078125, 40.74614334106445 ], [ -73.99099731445312, 40.7454948425293 ], [ -73.99236297607422, 40.7436408996582 ], [ -73.99419403076172, 40.741111755371094 ], [ -73.9954833984375, 40.739356994628906 ], [ -73.99685668945312, 40.73744583129883 ], [ -73.99828338623047, 40.7354850769043 ], [ -74.0000991821289, 40.74301315307617 ], [ -74.0005874633789, 40.74229217529297 ], [ -74.0009994506836, 40.74176956176758 ], [ -74.00108337402344, 40.74163986206055 ], [ -74.00177001953125, 40.7305908203125 ], [ -74.00286865234375, 40.72846984863281 ], [ -74.00321197509766, 40.72770690917969 ], [ -74.00350952148438, 40.72700500488281 ], [ -74.00405883789062, 40.72560119628906 ], [ -74.00466918945312, 40.724159240722656 ], [ -74.0048828125, 40.72370529174805 ], [ -74.00494384765625, 40.723575592041016 ], [ -74.00322723388672, 40.72327423095703 ], [ -74.00308227539062, 40.7332666015625 ], [ -74.00252532958984, 40.72303009033203 ], [ -73.9991455078125, 40.721378326416016 ], [ -73.99333679199219, 40.72102355957031 ], [ -73.99387902832031, 40.721527099609375 ], [ -73.9933373413086, 40.72134780883789 ], [ -73.99390356445312, 40.72053527832031 ], [ -73.99302673339844, 40.71986770629883 ], [ -73.99363110351562, 40.7191276550293 ], [ -73.98379296875, 40.71823501586914 ] ] } }
Given this, I am trying the following query which fails:
db.vendors.find({ AREA_ON_EARTH_THAT_SHOP_SERVICES : { $geoWithin: { $geometry: { type: "Point", coordinates: [ -73.997439,40.730823]
} } } })
Which results in error:
error: {
"$err" : "$within not supported with provided geometry: { $geoWithin: { $geometry: { type: \"Point\", coordinates: [ -73.997439,40.730823 ] } } }",
"code" : 16672
}
The shape operator cannot be "Point". The available shape operators are: $box, $polygon, $center and $centerSphere.
You can use $center in this case:
{
"AREA_ON_EARTH_THAT_SHOP_SERVICES": {
$geoWithin: { $center: [ [ <x>, <y> ] , <radius> ] }
}
}
You query then should be like this, note that 10 is the radius that makes the circle from center cover entirely the polygone:
db.vendors.find({ "AREA_ON_EARTH_THAT_SHOP_SERVICES" :
{ $geoWithin: { $center: [ [ -73.98652, 40.752044 ], 10 ] } }
})
Or you can use $geoIntersects with "Point", if that gives you the expected result:
db.vendors.find({ "AREA_ON_EARTH_THAT_SHOP_SERVICES" : { $geoIntersects:
{ $geometry: { type: "Point", coordinates: [ -73.98652, 40.752044 ]
} } } })
I faced pretty much the same issue, and got a working example by:
db.getCollection('places').insert({
id: 'some square from 0,0 to 10,10',
loc: {
type: "Polygon",
coordinates: [ [ [ 0 , 0 ] , [ 0 , 10 ] , [ 10 , 10 ] , [ 10 , 0 ], [ 0 , 0 ] ] ]
}
})
Then create index by loc field:
db.getCollection('places').createIndex( { loc : "2dsphere" } )
and then using $geoIntersects and $geometry type Point:
db.getCollection('places').find(
{
loc: {
$geoIntersects: {
$geometry: {
type : "Point" ,
coordinates:
[
1, 1
]
}
}
}
}
)
Hi i have an collection which contains this object
{
"_id":"53b0807ca004f2ad5f0c9839",
"id":"3427734",
"version":"4",
"timestamp":"2012-08-04T12:06:46Z",
"changeset":"12608469",
"uid":"604523",
"user":"673a",
"fenced":"yes",
"landuse":"cemetery",
"name":"Friedhof St. Peter (Alter Friedhof)",
"poly":{
"type":"Polygon",
"coordinates":[
[
[
8.6763586,
49.5531628
],
[
8.6765129,
49.553132
],
[
8.6763608,
49.5528116
],
[
8.6767028,
49.5527433
],
[
8.6765809,
49.5524866
],
[
8.6770135,
49.5524431
],
[
8.6784924,
49.5520942
],
[
8.6788149,
49.5521769
],
[
8.6789908,
49.5524369
],
[
8.6793862,
49.5525109
],
[
8.6786997,
49.5530378
],
[
8.6779331,
49.5531445
],
[
8.6769458,
49.5532933
],
[
8.6766567,
49.5533521
],
[
8.6764405,
49.5533353
],
[
8.6763586,
49.5531628
]
]
]
}
}
now i'm makeing a query
{
"poly":{
$geoIntersects:{
$geometry:{
"type":"Polygon",
"coordinates":[
[
[
-180.0,
90.0
],
[
180.0,
90.0
],
[
180.0,
-90.0
],
[
-180.0,
-90.0
],
[
-180.0,
90.0
]
]
]
}
}
}
}
but it does not return the object.. it returns nothing. Any ideas why?
The GeoJson object that you passed is not acceptable. I changed the query parameter a little bit and it now works. As you have already understood now that the GeoJson object should fit within one hemisphere. If you need some demonstration of the $geoIntersect functionality of MongoDB, you can run the following query and see that it gives your polygon in the results:
db.Test.find({
"poly":{
'$geoIntersects':{
'$geometry':{
"type": "Polygon",
"coordinates": [
[
[
8.6763586,
49.5531628
],
[
8.6788149,
49.5521769
],
[
8.6786997,
49.5530378
],
[
8.6763586,
49.5531628
],
[
8.6763586,
49.5531628
]
]
]
}
}
}
});
Seems that my query won't work, i found this in the docs:
http://docs.mongodb.org/manual/reference/operator/query/geoIntersects/
Note
Any geometry specified with GeoJSON to $geoIntersects queries, must fit within a single hemisphere. MongoDB interprets geometries larger than half of the sphere as queries for the smaller of the complementary geometries.
i can only query fopr the right hmisphere
{
"poly":{
$geoIntersects:{
$geometry:{
"type":"Polygon",
"coordinates":[
[
[
1.0,
90.0
],
[
180.0,
90.0
],
[
180.0,
-90.0
],
[
1.0,
-90.0
],
[
1.0,
90.0
]
]
]
}
}
}
}
I am trying to use mongodb $near operator to get some documents from database according to user's position.
So, after i've got user coordinates, i query a collection which has the right geospatial index ensured before :
computed_places.ensureIndex({'geoJson.coordinates' : "2d"}, function(err,ok) {)
with this query:
computed_places.find({'geoJson.coordinates' :
{$near:
{$geometry:
{type : "Point" ,
coordinates:[user.longitude , user.latitude]}},
$maxDistance : 200
}})
})
But after the first test it sounds returning random documents, as i've input
longitude: 11.870853799999999,
latitude: 45.4109512
And documents returned had this values (one pair for each document, which is the content of 'geoJson.coordinates' field):
[7.42149, 9.00046 ]
[ -1.50372, 12.3791 ]
[ 15.30972, -4.41944 ]
[ 15.0444, 12.1047 ]
[ -16.27479, 12.58644 ]
[ -16.47951, 14.69669 ]
[ -16.96598, 14.79575 ]
[ -17.46682, 14.68189 ]
[ -17.45258, 14.69922 ]
[ -17.46331, 14.68731 ]
[ -17.46232, 14.69187 ]
[ -16.42596, 16.06252 ]
[ 29.74278, -2.61611 ]
[ 30.06219, -1.95994 ]
[ 30.21835, 0.67669 ]
[ 30.27613, 0.65909 ]
[ 30.65717, -0.61551 ]
[ -9.54612, 30.40618 ]
[ 32.01435, 0.0026 ]
[ 32.01889, 1.8425 ]
[ 32.31678, 2.78819 ]
[ 32.56815, 0.33572 ]
[ 32.57702, 0.33791 ]
[ 32.58911, 0.41068 ]
[ 32.59748, 0.32096 ]
[ 32.62691, 0.34929 ]
[ 32.6354, 0.26048 ]
[ -8.02018, 31.64532 ]
[ -8.01542, 31.64902 ]
[ -4.97333, 34.06444 ]
[ -6.86187, 33.98307 ]
[ -6.8614, 33.98705 ]
[ -1.89851, 34.65022 ]
[ -6.80016, 34.04182 ]
[ 35.08467, 0.25603 ]
[ 31.053, -17.784 ]
[ 33.99323, -11.422 ]
[ 32.54222, 15.61222 ]
[ -5.89351, 35.73639 ]
[ 33.52946, 14.38584 ]
[ 36.82248, -1.27937 ]
[ -4.47724, 36.71546 ]
[ -6.29799, 36.53392 ]
[ -3.60341, 37.17572 ]
[ -3.6021, 37.17812 ]
[ -3.60446, 37.18048 ]
[ -3.59712, 37.1935 ]
[ -3.59772, 37.20488 ]
[ -5.99051, 37.3808 ]
[ -6.06589, 37.37031 ]
[ -1.17451, 38.02272 ]
[ 28.1617, -25.7322 ]
[ -3.46826, 37.99136 ]
[ -4.80046, 37.86933 ]
[ -4.78746, 37.87324 ]
[ -4.78191, 37.88005 ]
[ -4.7673, 37.8851 ]
[ -0.68716, 38.27538 ]
[ 27.99889, -26.18333 ]
[ -0.51224, 38.38446 ]
[ 18.8647, -33.9301 ]
[ 38.50135, 7.06233 ]
[ -9.19215, 38.6979 ]
[ 38.75917, 9.04667 ]
[ -9.11664, 38.7562 ]
[ -0.06884, 39.99415 ]
[ 27.72312, -29.45066 ]
[ -5.6689, 40.96603 ]
[ 2.16353, 41.38636 ]
[ 2.11051, 41.39367 ]
[ 0.62332, 41.60818 ]
[ 32.5833, -25.9667 ]
[ 32.58496, -25.974 ]
[ 32.59976, -25.95979 ]
[ -0.88738, 41.68331 ]
[ -8.39647, 41.56104 ]
[ -5.5597, 42.61231 ]
[ 29.89667, 31.19626 ]
[ 29.90528, 31.20194 ]
[ 31.20797, 30.02733 ]
[ 29.9989, 31.26448 ]
[ 25.10237, 35.31901 ]
[ 31.22038, 30.0574 ]
[ 31.23613, 30.04574 ]
[ 31.2625, 30.04583 ]
[ 5.44321, 43.23243 ]
[ 5.44209, 43.23268 ]
[ 5.35897, 43.29198 ]
[ 5.40025, 43.28711 ]
[ -5.77641, 43.24242 ]
[ 5.38261, 43.29817 ]
[ 5.37486, 43.29979 ]
[ 5.39214, 43.30123 ]
[ 5.37923, 43.30398 ]
[ -3.79904, 43.47363 ]
[ 5.39339, 43.30592 ]
[ 5.45815, 43.31909 ]
[ 5.41609, 43.33851 ]
[ 31.60639, 30.15028 ]
[ 22.37148, 37.52703 ]
That results seem random compared to my input, but also among themselves. What am i doing wrong? This is the strcture of queried documents:
doc = {
"geoname_id": 6269578
, names: {
en: "Pedagogical University"
}
, country: "VN"
, geoJson: {
type: "Point"
, coordinates: [
106.68259
, 10.76154
]
}
, timezone: "Asia/Ho_Chi_Minh"
, "_id": new ObjectID("530dffbe734e07e50d9b5ef9")
};
Finally found some of my really old scripts I had written for an IRC Bot about 10 years ago. I had no idea what I was doing, and was wondering if anyone knew what this was written in and any information?
on *:sockread:$1:{
var %stattype $1
if ($sockerr) {
.notice [ %nickname [ $+ [ %stattype ] ] ] Error.
halt
}
else {
var %statread
sockread %statread
if (Stat:* * * * iswm %statread) {
.tokenize 32 %statread
.notice [ %nickname [ $+ [ %stattype ] ] ] 1[ Username:7 $upper( [ %username [ $+ [ %stattype ] ] ] ) 1] [ Skill: 7 $upper(%stattype) 1]
.notice [ %nickname [ $+ [ %stattype ] ] ] 1[ Level:7 $3 1 $chr(124) Exp:7 $4 1 $chr(124) Rank:7 $2 1]
.notice [ %nickname [ $+ [ %stattype ] ] ] 1[ Next lvl:7 $calc($3 + 1) 1 $chr(124) Exp to:7 $bytes($calc( [ %lvl [ $+ [ $calc($3 + 1) ] ] ] - $remove($4,$chr(44))),b) 1]
.notice [ %nickname [ $+ [ %stattype ] ] ] 1[ Bandits:7 $bytes($calc($calc( [ %lvl [ $+ [ $calc($3 + 1) ] ] ] - $remove($4,$chr(44)))/(51*1.33)),b) 1 $chr(124) S.Warriors:7 $bytes($calc($calc( [ %lvl [ $+ [ $calc($3 + 1) ] ] ] - $remove($4,$chr(44)))/(67*1.33)),b) 1 $chr(124) Dagg(74):7 $bytes($calc($calc( [ %lvl [ $+ [ $calc($3 + 1) ] ] ] - $remove($4,$chr(44)))/(70*1.33)),b) 1 $chr(124) Ogre(53)/Ice Warrior:7 $bytes($calc($calc( [ %lvl [ $+ [ $calc($3 + 1) ] ] ] - $remove($4,$chr(44)))/(60*1.33)),b) 1]
.sockclose %stattype
}
}
}
on $*:TEXT:$(/#(hp|att|str|ran|mag|pra|def|coo|woo|fir|fle|run|sla|min|smi|cra)/):#: {
var %stattype $left($remove($1,!,#),3)
.tokenize %stattype 32
if ($2 != $null) {
sockopen %stattype rscript.org 80
set [ %username [ $+ [ %stattype ] ] ] $2
set [ %nickname [ $+ [ %stattype ] ] ] $nick
}
elseif ($2 == $null) {
sockopen hp rscript.org 80
set [ %username [ $+ [ %stattype ] ] ] $nick
set [ %nickname [ $+ [ %stattype ] ] ] $nick
}
else {
.notice $nick Error. Sorry.
}
}
This is the mIRC scripting language for the mIRC client.
Oh and it seems to do something with (pff knowledge from when I was 12) training thieving on bandits in the game runescape through the service rscript.org.
MIRC Remote Events.
I'm sure that you wrote your program in the mIRC scripting language (inofficial mSL). You can find more about that on its official website. Currently i try to figure out what are you doing ;) I stay tuned.