-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
polygon.txt
55 lines (38 loc) · 1.7 KB
/
polygon.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
========
$polygon
========
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. query:: $polygon
.. versionadded:: 1.9
The :query:`$polygon` operator specifies a polygon for a
:term:`geospatial` :query:`$geoWithin` query on legacy coordinate
pairs. The query returns pairs that are within the bounds of the
polygon. The operator does *not* query for GeoJSON objects.
The :query:`$polygon` operator calculates distances using flat (planar)
geometry.
The ``2d`` geospatial index supports the :query:`$polygon`
operator.
To define the polygon, specify an array of coordinate points. Use the
following syntax:
.. code-block:: javascript
{ <location field> : { $geoWithin : { $polygon : [ [ <x1> , <y1> ] ,
[ <x2> , <y2> ] ,
[ <x3> , <y3> ] ] } } }
.. important:: If you use longitude and latitude, specify **longitude first**.
The last point specified is always implicitly connected to the
first. You can specify as many points, and therefore sides, as you
like.
The following query returns all documents that have coordinates that
exist within the polygon defined by ``[ 0 , 0 ]``, ``[ 3 , 6 ]``, and
``[ 6 , 0 ]``:
.. code-block:: javascript
db.places.find( { loc : { $geoWithin : { $polygon : [ [ 0 , 0 ] ,
[ 3 , 6 ] ,
[ 6 , 0 ] ] } } } )
.. |operator| replace:: :query:`$polygon`
.. include:: /includes/note-geospatial-index-must-exist.rst