Rounding coordinates to 5 decimals in GeoPandas?

I recommend researching topojson and mapshaper as these tools were created to intelligently simplify shapes, preserving topology. Both tools are written in javascript. Mapshaper has a precision option for the output. You can run Mapshaper through a website, mapshaper.org or download the command line tools.


You can use the regex module to find the coordinates in a wkt representation of the geometries, round and load back:

import geopandas as gpd
from shapely.wkt import loads
import re

simpledec = re.compile(r"\d*\.\d+")
def mround(match):
    return "{:.5f}".format(float(match.group()))

shapefile = '/home/bera/GIS/data/test/polys.shp'
df = gpd.read_file(shapefile)
df.geometry = df.geometry.apply(lambda x: loads(re.sub(simpledec, mround, x.wkt)))
df.to_file('/home/bera/GIS/data/test/polys_round.shp')

See: Rounding using regular expressions

enter image description here

Or try this: Is it possible to round all coordinates in shapely?