0

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?

  • 3
    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 '19 at 1:54
  • 2
    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 '19 at 3:31
  • Yes, definitely don't need that much precision, thanks for the links – David1212k Sep 15 '19 at 10:44
  • What does print(dataframe.total_bounds[0]) print? – inc42 Sep 15 '19 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 '19 at 14:43
0

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

| improve this answer | |

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.