Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmr/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,18 @@ def point(self, lon, lat):

return self

def circle(self, lon: float, lat: float, dist: int):
"""Filter by granules within the circle around lat/lon

:param lon: longitude of geographic point
:param lat: latitude of geographic point
:param dist: distance in meters around waypoint (lat,lon)
:returns: Query instance
"""
self.params['circle'] = f"{lon},{lat},{dist}"

return self

def polygon(self, coordinates):
"""
Filter by granules that overlap a polygonal area. Must be used in combination with a
Expand Down
12 changes: 12 additions & 0 deletions tests/test_granule.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TestGranuleClass(unittest.TestCase):
version = "version"

point = "point"
circle = "circle"
online_only = "online_only"
downloadable = "downloadable"
entry_id = "entry_title"
Expand Down Expand Up @@ -51,6 +52,14 @@ def test_point_invalid_set(self):
query.point("invalid", 15.1)
query.point(10, None)

def test_circle_set(self):
query = GranuleQuery()

query.circle(10.0, 15.1, 1000)

self.assertIn(self.circle, query.params)
self.assertEqual(query.params[self.circle], "10.0,15.1,1000")

def test_temporal_invalid_strings(self):
query = GranuleQuery()

Expand Down Expand Up @@ -336,6 +345,9 @@ def test_invalid_spatial_state(self):
query.point(1, 2)
self.assertFalse(query._valid_state())

query.circle(1, 2, 3)
self.assertFalse(query._valid_state())

query.polygon([(1, 1), (2, 1), (2, 2), (1, 1)])
self.assertFalse(query._valid_state())

Expand Down