How to quickly transform a bounding box from one CRS to another using QGIS
Posted by: Gavin Fleming | in FOSSGIS, QGIS | 6 years, 6 months ago | Comments

Today I needed to convert a bounding box for a tilemill project that I want to bring into QGIS as a tile layer (more on that in a future post if I get it to work...).  I needed to convert a bounding box from EPSG:4326 ('Geographic') coordinates to EPSG:3857 (Spherical Mercator). Fortunately it is a fairly trivial process if you don't mind writing a few lines of python in the QGIS python console:

box = QgsRectangle(-19.6875,-37.9962,59.0625,37.4400)
source_crs = QgsCoordinateReferenceSystem(4326)
dest_crs = QgsCoordinateReferenceSystem(3857)
transform = QgsCoordinateTransform(source_crs, dest_crs)
new_box = transform.transformBoundingBox(box)
u'-2191602.4749925746582448,-4578889.0142234507948160 : 6574807.4249777207151055,4500615.8633687794208527'


It really is quite trivial to do arbitrary once-off things in QGIS if you roll up your sleeves and get to grips with the python API!

Current rating: 4


Have any questions? Contact us.
We would love to hear from you!
Subscribe to our Mailing list (spam-free, industry-relevant occasional emails)

Subscribe to our mailing list

* indicates required