0

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

3

2 Answers 2

0

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.

2
  • Not really practical if you have tens or hundreds of fields
    – Andre Geo
    Commented Jun 4 at 8:08
  • my clients getting shape from my server and many of them dont want to change this himselves
    – Ilya
    Commented Jun 10 at 10:01
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.