Skip to content
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

restore floats (as per RFC 7946 Section 3.1.1) #229

Merged
merged 1 commit into from
Oct 4, 2024
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
6 changes: 3 additions & 3 deletions geojson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def map_geometries(func, obj):


def generate_random(featureType, numberVertices=3,
boundingBox=[-180, -90, 180, 90]):
boundingBox=[-180.0, -90.0, 180.0, 90.0]):
"""
Generates random geojson features depending on the parameters
passed through.
Expand Down Expand Up @@ -190,8 +190,8 @@ def create_poly():
r_i = clip(random.gauss(ave_radius, spikeyness), 0, 2 * ave_radius)
x = ctr_x + r_i * math.cos(angle)
y = ctr_y + r_i * math.sin(angle)
x = (x + 180) * (abs(lon_min - lon_max) / 360) + lon_min
y = (y + 90) * (abs(lat_min - lat_max) / 180) + lat_min
x = (x + 180.0) * (abs(lon_min - lon_max) / 360.0) + lon_min
y = (y + 90.0) * (abs(lat_min - lat_max) / 180.0) + lat_min
x = clip(x, lon_min, lon_max)
y = clip(y, lat_min, lat_max)
points.append((x, y))
Expand Down
10 changes: 5 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@


def generate_bbox():
min_lat = random.random() * 180 - 90
max_lat = random.random() * 180 - 90
min_lat = random.random() * 180.0 - 90.0
max_lat = random.random() * 180.0 - 90.0
if min_lat > max_lat:
min_lat, max_lat = max_lat, min_lat
min_lon = random.random() * 360 - 180
max_lon = random.random() * 360 - 180
min_lon = random.random() * 360.0 - 180.0
max_lon = random.random() * 360.0 - 180.0
if min_lon > max_lon:
min_lon, max_lon = max_lon, min_lon
return [min_lon, min_lat, max_lon, max_lat]
Expand Down Expand Up @@ -46,7 +46,7 @@ def check_point_bbox(point, bbox):
class TestGenerateRandom(unittest.TestCase):
def test_simple_polygon(self):
for _ in range(5000):
bbox = [-180, -90, 180, 90]
bbox = [-180.0, -90.0, 180.0, 90.0]
result = generate_random('Polygon')
self.assertIsInstance(result, geojson.geometry.Polygon)
self.assertTrue(geojson.geometry.check_polygon(result))
Expand Down
Loading