-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-35744 geospatial page #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,296 @@ | ||||||||||||||||||||
.. _pymongo-geo-queries: | ||||||||||||||||||||
|
||||||||||||||||||||
================== | ||||||||||||||||||||
Geospatial Queries | ||||||||||||||||||||
================== | ||||||||||||||||||||
|
||||||||||||||||||||
.. contents:: On this page | ||||||||||||||||||||
:local: | ||||||||||||||||||||
:backlinks: none | ||||||||||||||||||||
:depth: 2 | ||||||||||||||||||||
:class: singlecol | ||||||||||||||||||||
|
||||||||||||||||||||
.. facet:: | ||||||||||||||||||||
:name: genre | ||||||||||||||||||||
:values: reference | ||||||||||||||||||||
|
||||||||||||||||||||
.. meta:: | ||||||||||||||||||||
:keywords: code example, coordinates, location, geographic | ||||||||||||||||||||
|
||||||||||||||||||||
Overview | ||||||||||||||||||||
-------- | ||||||||||||||||||||
|
||||||||||||||||||||
In this guide, you can learn how to work with **geospatial data**, data formats, | ||||||||||||||||||||
indexes, and queries. | ||||||||||||||||||||
|
||||||||||||||||||||
Geospatial data represents a geographic location on the surface of the Earth. | ||||||||||||||||||||
|
||||||||||||||||||||
Examples of geospatial data include: | ||||||||||||||||||||
|
||||||||||||||||||||
- Locations of movie theaters | ||||||||||||||||||||
- Borders of countries | ||||||||||||||||||||
- Routes of bicycle rides | ||||||||||||||||||||
- Dog exercise areas in New York City | ||||||||||||||||||||
- Points on a graph | ||||||||||||||||||||
|
||||||||||||||||||||
Geospatial Data Formats | ||||||||||||||||||||
----------------------- | ||||||||||||||||||||
|
||||||||||||||||||||
All geospatial data in MongoDB is stored in one of the following formats: | ||||||||||||||||||||
|
||||||||||||||||||||
- GeoJSON, a format that represents geospatial data on an earth-like | ||||||||||||||||||||
sphere. | ||||||||||||||||||||
|
||||||||||||||||||||
- Legacy coordinate pairs, a format that represents geospatial data | ||||||||||||||||||||
on a Euclidean plane. | ||||||||||||||||||||
|
||||||||||||||||||||
GeoJSON | ||||||||||||||||||||
~~~~~~~ | ||||||||||||||||||||
|
||||||||||||||||||||
Use GeoJSON to store data that represents geospatial information on | ||||||||||||||||||||
an earth-like sphere. GeoJSON is composed of one or more **positions** | ||||||||||||||||||||
and a **type**. | ||||||||||||||||||||
|
||||||||||||||||||||
Positions | ||||||||||||||||||||
````````` | ||||||||||||||||||||
|
||||||||||||||||||||
A position represents a single location and exists in code as an array | ||||||||||||||||||||
containing the following values: | ||||||||||||||||||||
|
||||||||||||||||||||
- Longitude in the first position (required) | ||||||||||||||||||||
- Latitude in the second position (required) | ||||||||||||||||||||
- Elevation in the third position (optional) | ||||||||||||||||||||
|
||||||||||||||||||||
The following is the position of the MongoDB Headquarters in New York City, NY. | ||||||||||||||||||||
|
||||||||||||||||||||
.. code-block:: python | ||||||||||||||||||||
|
||||||||||||||||||||
[-73.986805, 40.7620853] | ||||||||||||||||||||
|
||||||||||||||||||||
.. important:: Longitude then Latitude | ||||||||||||||||||||
|
||||||||||||||||||||
GeoJSON orders coordinates with longitude first and latitude second. | ||||||||||||||||||||
Make sure to check what format any other tools you are working with use, since many popular | ||||||||||||||||||||
tools such as OpenStreetMap and Google Maps list coordinates with latitude first and | ||||||||||||||||||||
longitude second. | ||||||||||||||||||||
|
||||||||||||||||||||
Types | ||||||||||||||||||||
````` | ||||||||||||||||||||
|
||||||||||||||||||||
The type of your GeoJSON object determines the geometric shape it represents. Geometric | ||||||||||||||||||||
shapes are made up of positions. | ||||||||||||||||||||
|
||||||||||||||||||||
Here are some common GeoJSON types and how you can specify them with positions: | ||||||||||||||||||||
|
||||||||||||||||||||
- ``Point``: a single position. The following ``Point`` represents the location of | ||||||||||||||||||||
the MongoDB Headquarters: | ||||||||||||||||||||
|
||||||||||||||||||||
.. code-block:: python | ||||||||||||||||||||
|
||||||||||||||||||||
{ | ||||||||||||||||||||
"type": "Point", | ||||||||||||||||||||
"coordinates": [-73.856077, 40.848447] | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applies to all the dictionaries on this page.
Suggested change
|
||||||||||||||||||||
- ``LineString``: an array of two or more positions that forms a series of line | ||||||||||||||||||||
segments. A ``LineString`` can represent a path, route, border, or any other linear | ||||||||||||||||||||
geospatial data. The following ``LineString`` represents a segment of | ||||||||||||||||||||
the Great Wall of China: | ||||||||||||||||||||
|
||||||||||||||||||||
.. code-block:: python | ||||||||||||||||||||
|
||||||||||||||||||||
{ | ||||||||||||||||||||
"type": "LineString", | ||||||||||||||||||||
"coordinates": | ||||||||||||||||||||
[[116.572, 40.430], | ||||||||||||||||||||
[116.570, 40.434], | ||||||||||||||||||||
[116.567, 40.436], | ||||||||||||||||||||
[116.566, 40.441]] | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
- ``Polygon``: an array of positions in which the first and last | ||||||||||||||||||||
position are the same and enclose some space. The following | ||||||||||||||||||||
``Polygon`` roughly represents the land within the Vatican City: | ||||||||||||||||||||
|
||||||||||||||||||||
.. code-block:: python | ||||||||||||||||||||
|
||||||||||||||||||||
{ | ||||||||||||||||||||
"type": "Polygon", | ||||||||||||||||||||
"coordinates": | ||||||||||||||||||||
[[[12.446086, 41.901977], | ||||||||||||||||||||
[12.457952, 41.901559], | ||||||||||||||||||||
[12.455375, 41.907351], | ||||||||||||||||||||
[12.449863, 41.905186], | ||||||||||||||||||||
[12.446086, 41.901977]]] | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
To learn more about the GeoJSON types you can use in MongoDB, see the | ||||||||||||||||||||
:manual:`GeoJSON manual entry </reference/geojson/>`. | ||||||||||||||||||||
|
||||||||||||||||||||
For more information on the GeoJSON format, see the | ||||||||||||||||||||
`official IETF specification <https://datatracker.ietf.org/doc/html/rfc7946>`__. | ||||||||||||||||||||
|
||||||||||||||||||||
Legacy Coordinate Pairs | ||||||||||||||||||||
~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
|
||||||||||||||||||||
Use legacy coordinate pairs to store data that represents geospatial information | ||||||||||||||||||||
on a two-dimensional plane. | ||||||||||||||||||||
|
||||||||||||||||||||
Legacy coordinate pairs are represented by an array of two values, in which the first | ||||||||||||||||||||
represents the ``x`` axis value and the second represents the ``y`` axis value. | ||||||||||||||||||||
|
Legacy coordinate pairs are represented by an array of two values, in which the first | |
represents the ``x`` axis value and the second represents the ``y`` axis value. | |
Legacy coordinate pairs are represented by an array of two values, in which the first value | |
represents the ``x`` axis value and the second represents the ``y`` axis value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken link at the moment, you'll need to add the geospatial-indexes
ref to the Indexes landing page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What could be confusing here is understanding which ones can be used in find
and aggregate
queries. I know in the geospatial querying it goes deeper in, but what are thoughts on specifying which one is only available in aggregate
.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: For this example and the next one you could combine this with the code example using the io-code-block
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit