Skip to content

Instantly share code, notes, and snippets.

@antoniolocandro
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save antoniolocandro/c6a66d8b8c100650a2fc to your computer and use it in GitHub Desktop.

Select an option

Save antoniolocandro/c6a66d8b8c100650a2fc to your computer and use it in GitHub Desktop.
QgisCommand
from qgis.utils import iface
from qgis.core import QGis
from qgiscommand.command import command
@command()
def bbox():
layer = iface.activeLayer()
def pbounds (Lextent,s):
e = Lextent
if s =='no':
iface.messageBar().pushInfo("bbox layer\n",'x,y\n%s,%s\n%s,%s' %(e.xMinimum(), e.yMinimum(), e.xMaximum(), e.yMaximum()))
else:
iface.messageBar().pushInfo("bbox selected features\n",'x,y\n%s,%s\n%s,%s' %(e.xMinimum(), e.yMinimum(), e.xMaximum(), e.yMaximum()))
if layer.wkbType()== QGis.WKBPolygon or layer.wkbType() == QGis.WKBMultiPolygon or layer.wkbType() == QGis.WKBLineString:
if layer.selectedFeatureCount() < 1:
s = 'no'
e = layer.extent()
else:
s = 'yes'
e = layer.boundingBoxOfSelected()
pbounds(e, s)
else:
if layer.featureCount() <=1:
iface.messageBar().pushInfo("point layer",'less than 2 points')
else:
if layer.selectedFeatureCount() <2:
s = 'no'
e = layer.extent()
pbounds(e, s)
else:
s = 'yes'
e = layer.boundingBoxOfSelected()
pbounds(e, s)
@mtravis

mtravis commented Jun 19, 2015

Copy link
Copy Markdown

Works great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment