Skip to content
Open
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
13 changes: 12 additions & 1 deletion cmr/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from abc import abstractmethod
from collections import defaultdict
from decimal import Decimal
from datetime import date, datetime, timezone
from inspect import getmembers, ismethod
from re import search
Expand Down Expand Up @@ -625,7 +626,17 @@ def point(self, lon: FloatLike, lat: FloatLike) -> Self:
if "point" not in self.params:
self.params["point"] = []

self.params["point"].append(f"{lon},{lat}")
# CMR rejects scientific notation in point query parameters.
lon_as_str = format(Decimal(str(lon)), "f")
lat_as_str = format(Decimal(str(lat)), "f")

if "." not in lon_as_str:
lon_as_str += ".0"

if "." not in lat_as_str:
lat_as_str += ".0"

self.params["point"].append(f"{lon_as_str},{lat_as_str}")

return self

Expand Down
6 changes: 6 additions & 0 deletions tests/test_granule.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ def test_valid_parameters(self):
self.assertEqual(query.params["version"], "003")
self.assertEqual(query.params["point"], ["-100.0,42.0"])

def test_point_avoids_scientific_notation(self):
query = GranuleQuery().short_name("FOO").point(42, 0.00001)

self.assertEqual(query.params["point"], ["42.0,0.00001"])
self.assertIn("point[]=42.0,0.00001", query._build_url())

def test_invalid_parameters(self):
query = GranuleQuery()

Expand Down