# Rounding coordinates to 5 decimals in GeoPandas?

I have a shapefile, which I converted into geopandas dataframe. I would like to round the coordinates to 5 decimals.

Is there a method/function in geopandas that can do this?

My shapefile contains multipolygons.

• Be careful. Rounding of coordinates can damage polygon topology. Rounding degrees to 5 places could change coordinate placement by 1 meter. – Vince May 2 at 18:08
• I saw the precision table and decided 1 meter is good enough for my application. Hence 5 decimals. – Vinay May 2 at 18:09
• Except it doesn't work like that. If the data has centimeter resolution, coordinates may come closer than a meter, and the resulting truncation could cause polygon rings to touch. It takes a more sophisticated approach than just rounding coordinates. – Vince May 2 at 18:18
• But why? What do you gain from this? The object will still occupy the same size in memory, you might snap nodes together and break topology, you'll modify the area and perimeter of your features. Maybe you can do this validly for point features, but I'd never do this for lines or polygons, unless its for display purposes only (ie showing a table of vertex coordinates). – Spacedman May 2 at 18:18
• We are developing an interactive d3 visualization tool which shows all the US zips on a map with other features. Interaction speed is important in this case and I thought decreasing the precision will help in loading and displaying data fast. Is there any validity in my argument? @Vince - I really don't care if they overlap little bit. – Vinay May 2 at 18:24

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'