1

Geopandas

Reading a shapefile with GeoPandas and printing its total bounds:

dataframe = gpd.read_file('example.shp')
print(dataframe.total_bounds)

Prints: [ 663590.5817 1541419.8307 724630.0589 1595869.4839]

PyQGIS

Doing the same with PyQGIS:

QgsApplication.setPrefixPath("/usr", True)
qgs = QgsApplication([], False)
qgs.initQgis()
layer = QgsVectorLayer('example.shp', 'layer1', 'ogr')
print(layer.extent())

Prints: <QgsRectangle: 663590.58169999998062849 1541419.83070000074803829, 724630.05890000029467046 1595869.48389999940991402>


As you can see doing it with PyQGIS gives you more precision than doing it with GeoPandas.

Is there any way to get the same precision with GeoPandas?

6
  • 4
    Why do you want <0.1mm precision? Your data is not that accurate. It might be worthwhile to have a read about floating point representation error as well.
    – user2856
    Sep 15, 2019 at 1:54
  • 3
    If you aren't mapping Higgs Boson detection in UTM, then it seems unlikely that a tenth millimeter is an appropriate precision much less tens of femtometers. You'd probably be better off rounding to meters. Obligatory XKCD reference: xkcd.com/2170
    – Vince
    Sep 15, 2019 at 3:31
  • Yes, definitely don't need that much precision, thanks for the links
    – David1212k
    Sep 15, 2019 at 10:44
  • What does print(dataframe.total_bounds[0]) print?
    – inc42
    Sep 15, 2019 at 11:30
  • 1
    Next to not needing such high precision in most cases, it is probably also just a "representation" issue: pandas and numpy will by default only show the first decimals when printing them.
    – joris
    Sep 15, 2019 at 14:43

2 Answers 2

1

Try using pandas (pd) settings: pd.set_option('max_colwidth', value)

look here for more info: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.set_option.html

1

Use geopandas.options.display_precision to specify how many decimal places to be visualized when printing the dataframe.

Note that internally the precision is not rounded, this is just a matter if displaying the coordinates.

Example, default behaviour:

>>> import geopandas
>>> world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
>>> world['centroid_column'].head()
0    POINT (163.85316 -17.31631)
1      POINT (34.75299 -6.25773)
2     POINT (-12.13783 24.29117)
3     POINT (-98.14238 61.46908)
4    POINT (-112.59944 45.70563)
Name: centroid_column, dtype: geometry

With 9 decimal places now:

>>> geopandas.options.display_precision = 9
>>>
>>> world['centroid_column'].head()
0    POINT (163.853164645 -17.316309426)
1      POINT (34.752989855 -6.257732429)
2     POINT (-12.137831112 24.291172960)
3     POINT (-98.142381372 61.469076145)
4    POINT (-112.599435912 45.705628002)
Name: centroid_column, dtype: geometry

Taken from geopandas official documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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