Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Forked from antoniolocandro/bbox
Last active August 29, 2015 14:23
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 NathanW2/c059dc40cde320bdfbcd to your computer and use it in GitHub Desktop.
Save NathanW2/c059dc40cde320bdfbcd to your computer and use it in GitHub Desktop.
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)
@NathanW2
Copy link
Author

from qgis.utils import iface
from qgis.core import QGis
from qgiscommand.command import command

@command()
def bbox():
    layer = iface.activeLayer()

    usingselection = not layer.selectedFeatureCount()
    if not usingselection:
        e = layer.extent()
    else:
        e = layer.boundingBoxOfSelected()

    title = "bbx layer"
    if usingselection:
        title = "bbox selected features"

    iface.messageBar().pushInfo(title,"x,y {}".format(extent.toString()))

@NathanW2
Copy link
Author

:)

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