WealthAfrica_Python / helpers /reduce_precision.py
chrisli124's picture
add heatmap layer
ebae247
raw
history blame contribute delete
535 Bytes
import json
def reduce_coordinate_precision(geojson_data, precision=5):
"""Reduces the decimal precision of coordinates in GeoJSON data."""
features = geojson_data.get('features', [])
for feature in features:
if feature['geometry']['type'] == 'Polygon':
coords = feature['geometry']['coordinates']
rounded_coords = [[[round(coord, precision) for coord in point] for point in ring] for ring in coords]
feature['geometry']['coordinates'] = rounded_coords
return geojson_data