Is there a way to calculate the XMIN, YMIN, XMAX and YMAX of a polygon and write it to a field in an attribute table?
The Geometry functions available in the Field Calculator are for points.
I am using 1.8.0 for Windows.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
The Field Calculator in QGIS now contains functions that will work fine for this.
You can now use:
Given a polygon shapefilename, the following python script should do the job:
layer = QgsVectorLayer(shapefilename,"","ogr") iter = layer.getFeatures() layer.startEditing() for ft in iter: geom=ft.geometry() ft.setAttribute('XMAX',geom.boundingBox().xMaximum()) ft.setAttribute('XMIN',geom.boundingBox().xMinimum()) ft.setAttribute('YMAX',geom.boundingBox().yMaximum()) ft.setAttribute('YMIN',geom.boundingBox().yMinimum()) layer.updateFeature(ft) layer.commitChanges()