Spatial Queries Map View
-
Spatial queries retrieve documents using geographical criteria,
provided that the documents contain spatial data. -
The spatial query defines geographic regions (circles or polygons)
and queries for documents that have some relation to those regions. -
When executing a dynamic spatial query in the Studio, in addition to the regular document results,
a Spatial Map view will be displayed, showing the search results on a global map.The spatial map view is added only for a dynamic spatial query.
It is not added when querying a spatial index. -
In this page:
Spatial data in documents
-
Documents that contain geographic data can be queried for using a spatial query.
The spatial data in a document can be in the form of:- Latitude & Longitude
- WKT string
-
For example, the following Employee document contains fields:
Address.Location.Latitude
&Address.Location.Longitude
and can be searched for by this spatial data. -
Note:
Using "Latitude" and "Longitude" as the document fields' names is Not mandatory.
Any custom name can be assigned to those coordinate fields.
Figure 1. A document containing spatial data
Running a dynamic spatial query
Figure 2. The query section
- 1. Indexes
Open the Indexes section. - 2. Query
Choose Query.
Figure 3. Running the query
- 1. Query box
Type your query in this area. The query is written in RQL.
// Specify the collection queried
from Employees
// Make a spatial query
where spatial.within(
// Use 'spatial.point' to specify the document field names containing the spatial data.
// The latitude field is always passed as the first param.
// (Note: 'spatial.wkt' is used when the document contains a WKT string.)
spatial.point(Address.Location.Latitude, Address.Location.Longitude),
// Specify a geographical area.
// This query will search for documents whose latitude & longitude are within this circle.
spatial.circle(20,47.623473, -122.3060097, 'miles')
)
-
2. Run query
Click this button to execute the query.
The query results will include two tabs:- Results tab - listing all resulting documents in textual form
- Spatial map tab - showing results on the global map
Figure 4. Textual results view
Spatial map view
Figure 5. Spatial map view
-
1. Spatial map
If there are any resulting documents that match the spatial query, a Spatial Map tab is added to the results view.
Click the tab to view the resulting documents in their geographical locations on the map. -
2. Expand results
Click to expand the spatial map.
Figure 6. Zoom and drag
- 1. Zoom control
Click +/- or roll your mouse wheel to zoom in and out. - 2. Map
Click anywhere in the map area and drag to move the map.
Figure 7. Region and points
Figure 8. Same points, zoomed in
-
1. Region
The region (a circle in this case) that was defined in the query. -
2. Location markers
-
Red markers
A red marker locates a single document result.
Hovering over the marker pops up the document's name.
Clicking the marker pops up the document's contents.
-
Green markers
A green marker gathers two or more neighboring red markers (documents).
Zooming in will reveal the individual locations.
The number on the green marker represents the number of documents gathered by this marker.- If a green marker gathers at least three document locations,
hovering over it would display a crude scheme of these locations on the map.
- Clicking a green marker zooms in to reveal the locations it gathers.
- If a green marker gathers at least three document locations,
-
Figure 12. Viewing-options tooltip
- 1. Viewing-options toggler
Hovering over the toggler will open the viewing options. - 2. Viewing Options
The map view options. - 3. Map view
Select Streets or Topography map. - 4. Point fields
When checked, the documents that contain these fields will be visible as marker points on the map. - 5. Regions
Show or hide circular/polygonal search regions.
Examples
Circular region example
The following query locates companies within two separate circular regions.
from Companies
where
spatial.within(
spatial.point(Address.Location.Latitude, Address.Location.Longitude),
spatial.circle(200, 45.5137863, -122.675375, 'miles')
)
or
spatial.within(
spatial.point(Address.Location.Latitude, Address.Location.Longitude),
spatial.circle(200, 37.7774357, -122.418, 'miles')
)
Figure 13. Multiple Regions
-
Circular region syntax
A circular region can be defined using two different syntaxes,spatial.circle
andspatial.wkt
.
from Employees where spatial.within( spatial.point(Address.Location.Latitude, Address.Location.Longitude), spatial.circle(20, 47.623473, -122.3060097, 'miles') )
from Employees where spatial.within( spatial.point(Address.Location.Latitude, Address.Location.Longitude), spatial.wkt('CIRCLE(-122.3060097 47.623473 d=20)') )
Forspatial.circle
, provide the Latitude first and the Longitude second.
Forspatial.wkt
, provide the Longitude first and the Latitude second. -
Region color
When multiple regions are defined, they are given different colors in the spatial map view.
Polygonal region example
The following query searches for companies within the boundaries of a polygonal region.
- The polygon's coordinates must be provided in counterclockwise order.
- The first and last coordinates must mark the same location to form a closed region.
- You can use tools like this one to draw a polygon on the world map and copy the coordinates to your query.
from companies
where
spatial.within(
spatial.point(Address.Location.Latitude, Address.Location.Longitude),
spatial.wkt('POLYGON ((
-118.6527948 32.7114894,
-95.8040242 37.5929338,
-102.8344151 53.3349629,
-127.5286633 48.3485664,
-129.4620208 38.0786067,
-118.7406746 32.7853769,
-118.6527948 32.7114894))')
)
Figure 14. Polygon
Mixed shapes intersection example
This query searches for companies at the intersection of a circular region and a polygonal region.
Though additional companies are located in each region, only companies located in both regions are retrieved.
from Companies
where
spatial.within(
spatial.point(Address.Location.Latitude, Address.Location.Longitude),
spatial.wkt('CIRCLE(-119.5 45.5137863 d=400)')
)
and
spatial.within(
spatial.point(Address.Location.Latitude, Address.Location.Longitude),
spatial.wkt('POLYGON ((
-119.7105226 47.1000662,
-117.0712682 40.3896178,
-110.7439164 34.3929116,
-97.9134529 38.0071749,
-98.1770925 45.2197803,
-119.7105226 47.1000662))')
)
Figure 15. Multiple shapes intersection