Skip to content

Instantly share code, notes, and snippets.

@brianbancroft
Last active September 5, 2018 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianbancroft/148b854f5918ede51e79e8bf12a30998 to your computer and use it in GitHub Desktop.
Save brianbancroft/148b854f5918ede51e79e8bf12a30998 to your computer and use it in GitHub Desktop.
Get bounding boxes for all CMAs in Canada using QGIS
bounding_boxes = []
features = iface.activeLayer().selectedFeatures()
for feature in features:
bounding_boxes.append({
'city': feature.attributes()[2],
'max_x': feature.geometry().boundingBox().toRectF().topRight().x(),
'max_y': feature.geometry().boundingBox().toRectF().topRight().y(),
'min_x': feature.geometry().boundingBox().toRectF().bottomLeft().x(),
'min_y': feature.geometry().boundingBox().toRectF().bottomLeft().y()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment