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?

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

Your Answer

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

Browse other questions tagged or ask your own question.