Skip to main content
typo. Use proper variable name
Source Link
JGH
  • 43.3k
  • 3
  • 46
  • 93

After setting the current layer extent, you would need to refresh the map display

iface.mapCanvas().refresh()

If you want to do a particular action when the layer is empty, you can count the features

layer.featureCount()

The function would look like:

def exportImages():
    i = 1
    for j in LAYERS:
        sleep(3)

        if layerj.featureCount() == 0:
          #do something with empty layer... (skip, copy a blank image etc)
        else:
          #Zoom to layer
          iface.mapCanvas().setExtent(j.extent())
          iface.mapCanvas().refresh()
          # Take screenshot
          print("Screen Shotting:  " + IMAGE_DIR + FILENAME + str(i) + ".png")
          iface.mapCanvas().saveAsImage(IMAGE_DIR + FILENAME + str(i) + ".png")
        i = i + 1

After setting the current layer extent, you would need to refresh the map display

iface.mapCanvas().refresh()

If you want to do a particular action when the layer is empty, you can count the features

layer.featureCount()

The function would look like:

def exportImages():
    i = 1
    for j in LAYERS:
        sleep(3)

        if layer.featureCount() == 0:
          #do something with empty layer... (skip, copy a blank image etc)
        else:
          #Zoom to layer
          iface.mapCanvas().setExtent(j.extent())
          iface.mapCanvas().refresh()
          # Take screenshot
          print("Screen Shotting:  " + IMAGE_DIR + FILENAME + str(i) + ".png")
          iface.mapCanvas().saveAsImage(IMAGE_DIR + FILENAME + str(i) + ".png")
        i = i + 1

After setting the current layer extent, you would need to refresh the map display

iface.mapCanvas().refresh()

If you want to do a particular action when the layer is empty, you can count the features

layer.featureCount()

The function would look like:

def exportImages():
    i = 1
    for j in LAYERS:
        sleep(3)

        if j.featureCount() == 0:
          #do something with empty layer... (skip, copy a blank image etc)
        else:
          #Zoom to layer
          iface.mapCanvas().setExtent(j.extent())
          iface.mapCanvas().refresh()
          # Take screenshot
          print("Screen Shotting:  " + IMAGE_DIR + FILENAME + str(i) + ".png")
          iface.mapCanvas().saveAsImage(IMAGE_DIR + FILENAME + str(i) + ".png")
        i = i + 1
Source Link
JGH
  • 43.3k
  • 3
  • 46
  • 93

After setting the current layer extent, you would need to refresh the map display

iface.mapCanvas().refresh()

If you want to do a particular action when the layer is empty, you can count the features

layer.featureCount()

The function would look like:

def exportImages():
    i = 1
    for j in LAYERS:
        sleep(3)

        if layer.featureCount() == 0:
          #do something with empty layer... (skip, copy a blank image etc)
        else:
          #Zoom to layer
          iface.mapCanvas().setExtent(j.extent())
          iface.mapCanvas().refresh()
          # Take screenshot
          print("Screen Shotting:  " + IMAGE_DIR + FILENAME + str(i) + ".png")
          iface.mapCanvas().saveAsImage(IMAGE_DIR + FILENAME + str(i) + ".png")
        i = i + 1