I need to limit or round decimals in my GeoDataFrame so that when importing to a shapefile and opening a file in QGIS, the number of decimals remains the same as in the dataframe.
In GDF looks like: 20.00000
In QGIS: 20.000000000000000
I need to limit or round decimals in my GeoDataFrame so that when importing to a shapefile and opening a file in QGIS, the number of decimals remains the same as in the dataframe.
In GDF looks like: 20.00000
In QGIS: 20.000000000000000
After importing, you can use the QGIS field calculator to create a new integer or decimal field. If it's decimal, set the number of decimal places. And in the field value, define that it will use the values from the pre-existing field.
I found a solution to my question, everything turned out to be quite simple.
GeoPandas uses a schema from Fiona, and all that was needed according to the documentation was to fill in schema['properties']['key'] = 'float:the length of the integer part.precision after the decimal point'
. Example: 'float:32.11'
, where 32 is the maximum length to the decimal point, and 11 is the precision. After this manipulation, I got the correct data in the Shape.
My code:
gdf = df.copy()
type_mapping = Structure().get_type_mappings()
schema = gpd.io.file.infer_schema(gdf)
schema['properties']['date_act'] = 'date'
for col, new_type in type_mapping.items():
schema['properties'][col] = new_type
Structure is my class in which I have defined all data types.