Skip to content

Commit 29c9ba2

Browse files
committed
mm feedback
1 parent 3bd548b commit 29c9ba2

File tree

2 files changed

+96
-88
lines changed

2 files changed

+96
-88
lines changed

source/geo.txt

Lines changed: 94 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ Geospatial Data Formats
3939
All geospatial data in MongoDB is stored in one of the following formats:
4040

4141
- GeoJSON, a format that represents geospatial data on an earth-like
42-
sphere.
42+
sphere
4343

4444
- Legacy coordinate pairs, a format that represents geospatial data
45-
on a Euclidean plane.
45+
on a Euclidean plane
4646

4747
GeoJSON
4848
~~~~~~~
@@ -88,8 +88,8 @@ Here are some common GeoJSON types and how you can specify them with positions:
8888
.. code-block:: python
8989

9090
{
91-
"type": "Point",
92-
"coordinates": [-73.856077, 40.848447]
91+
"type": "Point",
92+
"coordinates": [-73.856077, 40.848447]
9393
}
9494

9595
- ``LineString``: an array of two or more positions that forms a series of line
@@ -100,12 +100,12 @@ Here are some common GeoJSON types and how you can specify them with positions:
100100
.. code-block:: python
101101

102102
{
103-
"type": "LineString",
104-
"coordinates":
105-
[[116.572, 40.430],
106-
[116.570, 40.434],
107-
[116.567, 40.436],
108-
[116.566, 40.441]]
103+
"type": "LineString",
104+
"coordinates":
105+
[[116.572, 40.430],
106+
[116.570, 40.434],
107+
[116.567, 40.436],
108+
[116.566, 40.441]]
109109
}
110110

111111
- ``Polygon``: an array of positions in which the first and last
@@ -115,13 +115,13 @@ Here are some common GeoJSON types and how you can specify them with positions:
115115
.. code-block:: python
116116

117117
{
118-
"type": "Polygon",
119-
"coordinates":
120-
[[[12.446086, 41.901977],
121-
[12.457952, 41.901559],
122-
[12.455375, 41.907351],
123-
[12.449863, 41.905186],
124-
[12.446086, 41.901977]]]
118+
"type": "Polygon",
119+
"coordinates":
120+
[[[12.446086, 41.901977],
121+
[12.457952, 41.901559],
122+
[12.455375, 41.907351],
123+
[12.449863, 41.905186],
124+
[12.446086, 41.901977]]]
125125
}
126126

127127
To learn more about the GeoJSON types you can use in MongoDB, see the
@@ -136,7 +136,7 @@ Legacy Coordinate Pairs
136136
Use legacy coordinate pairs to store data that represents geospatial information
137137
on a two-dimensional plane.
138138

139-
Legacy coordinate pairs are represented by an array of two values, in which the first
139+
Legacy coordinate pairs are represented by an array of two values, in which the first value
140140
represents the ``x`` axis value and the second represents the ``y`` axis value.
141141

142142
For more information on legacy coordinate pairs, see the
@@ -200,88 +200,94 @@ The following example queries for documents with a ``location.geo`` field value
200200
within 1000 meters of the MongoDB Headquarters in New York City, NY. It returns documents
201201
from nearest to farthest.
202202

203-
.. code-block:: python
204-
205-
# set query with point at MongoDB headquarters and a maxDistance of 1000 meters
206-
query = {
207-
"location.geo": {
208-
"$near": {
209-
"$geometry": {
210-
"type": "Point",
211-
"coordinates": [-73.986805, 40.7620853] # Search around this location
212-
},
213-
"$maxDistance": 1000 # Distance in meters (1 km)
214-
}
215-
}
216-
}
217-
218-
# fetches the _id and theaterId fields
219-
projection = { "theaterId": 1 }
203+
.. io-code-block::
204+
:copyable: true
205+
206+
.. input::
207+
:language: python
208+
209+
# set query with point at MongoDB headquarters and a maxDistance of 1000 meters
210+
query = {
211+
"location.geo": {
212+
"$near": {
213+
"$geometry": {
214+
"type": "Point",
215+
"coordinates": [-73.986805, 40.7620853] # Search around this location
216+
},
217+
"$maxDistance": 1000 # Distance in meters (1 km)
218+
}
219+
}
220+
}
220221

221-
nearby_places = location.find(query, projection)
222+
# fetches the _id and theaterId fields
223+
projection = { "theaterId": 1 }
222224

223-
for i in nearby_places:
224-
print(i)
225+
nearby_places = location.find(query, projection)
225226

226-
The results of the preceding example contain the following documents:
227+
for i in nearby_places:
228+
print(i)
227229

228-
.. code-block:: json
229-
:copyable: False
230+
.. output::
231+
:language: json
232+
:visible: false
230233

231-
{ "_id" : ObjectId("59a47287cfa9a3a73e51e8e2"), "theaterId" : 1908 }
232-
{ "_id" : ObjectId("59a47286cfa9a3a73e51e838"), "theaterId" : 1448 }
234+
{ "_id" : ObjectId("59a47287cfa9a3a73e51e8e2"), "theaterId" : 1908 }
235+
{ "_id" : ObjectId("59a47286cfa9a3a73e51e838"), "theaterId" : 1448 }
233236

234237
Query by Polygon
235238
~~~~~~~~~~~~~~~~
236239

237240
The following example queries for documents with a ``location.geo`` field value that exists
238241
within the boundaries of Manhattan.
239242

240-
.. code-block:: python
241-
242-
# Polygon representation of Manhattan
243-
query = {
244-
"location.geo": {
245-
"$geoWithin": {
246-
"$geometry": {
247-
# Search around this location
248-
"type": "Polygon",
249-
"coordinates":
250-
[[[-73.925492, 40.877410],
251-
[-73.910372, 40.872366],
252-
[-73.935127, 40.834020],
253-
[-73.929049, 40.798569],
254-
[-73.976485, 40.711432],
255-
[-74.015747, 40.701229],
256-
[-74.018859, 40.708367],
257-
[-74.008007, 40.754307],
258-
[-73.925492, 40.877410]]]
259-
}
260-
}
261-
}
262-
}
263-
264-
# fetches the _id and theaterId fields
265-
projection = { "theaterId": 1 }
266-
267-
nearby_places = location.find(query, projection)
268-
269-
for i in nearby_places:
270-
print(i)
271-
272-
The results of the preceding example contain the following documents:
273-
274-
.. code-block:: json
275-
:copyable: False
276-
277-
{ "_id" : ObjectId("59a47287cfa9a3a73e51e8e2"), "theaterId" : 1908 }
278-
{ "_id" : ObjectId("59a47287cfa9a3a73e51eccb"), "theaterId" : 835 }
279-
{ "_id" : ObjectId("59a47286cfa9a3a73e51e838"), "theaterId" : 1448 }
280-
{ "_id" : ObjectId("59a47286cfa9a3a73e51e744"), "theaterId" : 1028 }
281-
{ "_id" : ObjectId("59a47287cfa9a3a73e51ebe1"), "theaterId" : 609 }
282-
{ "_id" : ObjectId("59a47287cfa9a3a73e51e8ed"), "theaterId" : 1906 }
283-
{ "_id" : ObjectId("59a47287cfa9a3a73e51e87d"), "theaterId" : 1531 }
284-
{ "_id" : ObjectId("59a47287cfa9a3a73e51eb63"), "theaterId" : 482 }
243+
.. io-code-block::
244+
:copyable: true
245+
246+
.. input::
247+
:language: python
248+
249+
# Polygon representation of Manhattan
250+
query = {
251+
"location.geo": {
252+
"$geoWithin": {
253+
"$geometry": {
254+
# Search around this location
255+
"type": "Polygon",
256+
"coordinates":
257+
[[[-73.925492, 40.877410],
258+
[-73.910372, 40.872366],
259+
[-73.935127, 40.834020],
260+
[-73.929049, 40.798569],
261+
[-73.976485, 40.711432],
262+
[-74.015747, 40.701229],
263+
[-74.018859, 40.708367],
264+
[-74.008007, 40.754307],
265+
[-73.925492, 40.877410]]]
266+
}
267+
}
268+
}
269+
}
270+
271+
# fetches the _id and theaterId fields
272+
projection = { "theaterId": 1 }
273+
274+
nearby_places = location.find(query, projection)
275+
276+
for i in nearby_places:
277+
print(i)
278+
279+
.. output::
280+
:language: json
281+
:visible: false
282+
283+
{ "_id" : ObjectId("59a47287cfa9a3a73e51e8e2"), "theaterId" : 1908 }
284+
{ "_id" : ObjectId("59a47287cfa9a3a73e51eccb"), "theaterId" : 835 }
285+
{ "_id" : ObjectId("59a47286cfa9a3a73e51e838"), "theaterId" : 1448 }
286+
{ "_id" : ObjectId("59a47286cfa9a3a73e51e744"), "theaterId" : 1028 }
287+
{ "_id" : ObjectId("59a47287cfa9a3a73e51ebe1"), "theaterId" : 609 }
288+
{ "_id" : ObjectId("59a47287cfa9a3a73e51e8ed"), "theaterId" : 1906 }
289+
{ "_id" : ObjectId("59a47287cfa9a3a73e51e87d"), "theaterId" : 1531 }
290+
{ "_id" : ObjectId("59a47287cfa9a3a73e51eb63"), "theaterId" : 482 }
285291

286292
Additional Resources
287293
--------------------

source/indexes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ Text Index
154154
To learn more about text indexes, see the :ref:`pymongo-text-index`
155155
guide.
156156

157+
.. _geospatial-indexes:
158+
157159
Geospatial Index
158160
----------------
159161

0 commit comments

Comments
 (0)