-
-
Save antoniolocandro/c6a66d8b8c100650a2fc to your computer and use it in GitHub Desktop.
QgisCommand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works great. Thanks!