Creating PNG images using QGIS 3 pygisInterpolation plugin from PyGIS?“unexpected indent” in the...

What to do if authors don't respond to my serious concerns about their paper?

Is there a better way to make this?

Using only 1s, make 29 with the minimum number of digits

What kind of hardware implements Fourier transform?

What does "at rest" mean involving data encryption?

Why is working on the same position for more than 15 years not a red flag?

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Why do neural networks need so many training examples to perform?

Issues with new Macs: Hardware makes them difficult for me to use. What options might be available in the future?

Why did Jodrell Bank assist the Soviet Union to collect data from their spacecraft in the mid 1960's?

What's a good word to describe a public place that looks like it wouldn't be rough?

Using loops to create tables

What is the purpose of easy combat scenarios that don't need resource expenditure?

page split between longtable caption and table

How would one buy a used TIE Fighter or X-Wing?

Why do members of Congress in committee hearings ask witnesses the same question multiple times?

Am I a Rude Number?

Could flying insects re-enter the Earth's atmosphere from space without burning up?

Quenching swords in dragon blood; why?

Is it safe to try charging my laptop with a USB-C PD charger that has less wattage than recommended?

Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?

Knowing when to use pictures over words

Can pricing be copyrighted?

Why did Bush enact a completely different foreign policy to that which he espoused during the 2000 Presidential election campaign?



Creating PNG images using QGIS 3 pygis


Interpolation plugin from PyGIS?“unexpected indent” in the scriptqgis python + layout/template + exporting in .png + filtering layersReplacing urls in QGIS attribute table with images using pythonSave Raster Layer as PNG using PyQGISCompiling resources in QGIS 2.99 (Windows) for creating plugin?NameError: name '**' is not definedaccess r.in.lidar through pyGIS consoleCreating and manipulating an HTML frame in QGIS 3.2.0 Print Composer using PyQGISCreating VRT or index of large amount of aerial images to create mosaic in QGIS?













0















Some days ago I upgraded from QGIS 2.18 to 3.6.0 - not knowing that many Python scripts won't run without modifications.



I could convert all of them but not this one:



from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui
import processing, sys, time, psycopg2
import pprint

...
creatin layers skipped (got this running)
...

################### Create Graph #####################

mapRenderer = iface.mapCanvas().mapRenderer()

layers = [missingLayer.id(),clipLayer.id()]
mapRenderer.setLayerSet(layers)

c = QgsComposition(mapRenderer)
c.setPlotStyle(QgsComposition.Print)

c.setPaperSize(148,90)
c.setPrintResolution(300)

# add map
x, y = 0, 0
w, h = c.paperWidth(), c.paperHeight()
composerMap = QgsComposerMap(c, x,y,w,h)
c.addItem(composerMap)

#output to image
dpi = c.printResolution()
dpmm = dpi / 25.4
width = int(dpmm * c.paperWidth())
height = int(dpmm * c.paperHeight())

BackgroundColor = QColor(0,0,255)

# create output image and initialize it
image = QImage(QSize(width, height), QImage.Format_ARGB32)
image.setDotsPerMeterX(dpmm * 1000)
image.setDotsPerMeterY(dpmm * 1000)
image.fill(BackgroundColor)

header = QgsComposerLabel(c)
header.setItemPosition(40,1)
header.setBackgroundEnabled(0)
newFont = QFont("Comic Sans MS", 18)
header.setFont(newFont)
header.setText("Missing Countries Map")
header.adjustSizeToText()
c.addItem(header)

header2 = QgsComposerLabel(c)
header2.setItemPosition(50,11)
header2.setBackgroundEnabled(0)
newFont2 = QFont("Comic Sans MS", 10)
header2.setFont(newFont2)
header2.setText("TS="+ts)
header2.adjustSizeToText()
c.addItem(header2)

footer = QgsComposerLabel(c)
footer.setItemPosition(124,87.5)
footer.setBackgroundEnabled(0)
newFont3 = QFont("Times Roman", 4)
footer.setFont(newFont3)
footer.setText(time.ctime())
footer.adjustSizeToText()
c.addItem(footer)

legend = QgsComposerLegend(c)
legend.model().setLayerSet(mapRenderer.layerSet())
legend.setItemPosition(5,65)
legend.setFrameEnabled(1)
newFont = QFont("Comic Sans MS", 6)
legend.setStyleFont(QgsComposerLegendStyle.Title, newFont)
legend.setStyleFont(QgsComposerLegendStyle.Subgroup, newFont)
legend.setStyleFont(QgsComposerLegendStyle.SymbolLabel, newFont)
legend.setStyleMargin(QgsComposerLegendStyle.Title,2)
legend.setTitle("Legend")
legend.setSymbolHeight(2)
legend.adjustBoxSize()
c.addItem(legend)

# render the composition
imagePainter = QPainter(image)
imagePainter.setRenderHint(QPainter.Antialiasing)
sourceArea = QRectF(0, 0, c.paperWidth(), c.paperHeight())
targetArea = QRectF(0, 0, width, height)
c.render(imagePainter, targetArea, sourceArea)
imagePainter.end()
imageFile = "missing_boundaries"+ts+".png"
print "saving to "+imageFile
image.save(imageFile)



Yes, I do know the QqsComposer has gone but I can't find any documentation or example for QGIS3 plotting. Except the API description of COURSE.



Any hints how to start? I don't need the whole script converted by you, only the first few lines should be enough.










share|improve this question





























    0















    Some days ago I upgraded from QGIS 2.18 to 3.6.0 - not knowing that many Python scripts won't run without modifications.



    I could convert all of them but not this one:



    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from PyQt4 import QtGui
    import processing, sys, time, psycopg2
    import pprint

    ...
    creatin layers skipped (got this running)
    ...

    ################### Create Graph #####################

    mapRenderer = iface.mapCanvas().mapRenderer()

    layers = [missingLayer.id(),clipLayer.id()]
    mapRenderer.setLayerSet(layers)

    c = QgsComposition(mapRenderer)
    c.setPlotStyle(QgsComposition.Print)

    c.setPaperSize(148,90)
    c.setPrintResolution(300)

    # add map
    x, y = 0, 0
    w, h = c.paperWidth(), c.paperHeight()
    composerMap = QgsComposerMap(c, x,y,w,h)
    c.addItem(composerMap)

    #output to image
    dpi = c.printResolution()
    dpmm = dpi / 25.4
    width = int(dpmm * c.paperWidth())
    height = int(dpmm * c.paperHeight())

    BackgroundColor = QColor(0,0,255)

    # create output image and initialize it
    image = QImage(QSize(width, height), QImage.Format_ARGB32)
    image.setDotsPerMeterX(dpmm * 1000)
    image.setDotsPerMeterY(dpmm * 1000)
    image.fill(BackgroundColor)

    header = QgsComposerLabel(c)
    header.setItemPosition(40,1)
    header.setBackgroundEnabled(0)
    newFont = QFont("Comic Sans MS", 18)
    header.setFont(newFont)
    header.setText("Missing Countries Map")
    header.adjustSizeToText()
    c.addItem(header)

    header2 = QgsComposerLabel(c)
    header2.setItemPosition(50,11)
    header2.setBackgroundEnabled(0)
    newFont2 = QFont("Comic Sans MS", 10)
    header2.setFont(newFont2)
    header2.setText("TS="+ts)
    header2.adjustSizeToText()
    c.addItem(header2)

    footer = QgsComposerLabel(c)
    footer.setItemPosition(124,87.5)
    footer.setBackgroundEnabled(0)
    newFont3 = QFont("Times Roman", 4)
    footer.setFont(newFont3)
    footer.setText(time.ctime())
    footer.adjustSizeToText()
    c.addItem(footer)

    legend = QgsComposerLegend(c)
    legend.model().setLayerSet(mapRenderer.layerSet())
    legend.setItemPosition(5,65)
    legend.setFrameEnabled(1)
    newFont = QFont("Comic Sans MS", 6)
    legend.setStyleFont(QgsComposerLegendStyle.Title, newFont)
    legend.setStyleFont(QgsComposerLegendStyle.Subgroup, newFont)
    legend.setStyleFont(QgsComposerLegendStyle.SymbolLabel, newFont)
    legend.setStyleMargin(QgsComposerLegendStyle.Title,2)
    legend.setTitle("Legend")
    legend.setSymbolHeight(2)
    legend.adjustBoxSize()
    c.addItem(legend)

    # render the composition
    imagePainter = QPainter(image)
    imagePainter.setRenderHint(QPainter.Antialiasing)
    sourceArea = QRectF(0, 0, c.paperWidth(), c.paperHeight())
    targetArea = QRectF(0, 0, width, height)
    c.render(imagePainter, targetArea, sourceArea)
    imagePainter.end()
    imageFile = "missing_boundaries"+ts+".png"
    print "saving to "+imageFile
    image.save(imageFile)



    Yes, I do know the QqsComposer has gone but I can't find any documentation or example for QGIS3 plotting. Except the API description of COURSE.



    Any hints how to start? I don't need the whole script converted by you, only the first few lines should be enough.










    share|improve this question



























      0












      0








      0








      Some days ago I upgraded from QGIS 2.18 to 3.6.0 - not knowing that many Python scripts won't run without modifications.



      I could convert all of them but not this one:



      from PyQt4.QtCore import *
      from PyQt4.QtGui import *
      from PyQt4 import QtGui
      import processing, sys, time, psycopg2
      import pprint

      ...
      creatin layers skipped (got this running)
      ...

      ################### Create Graph #####################

      mapRenderer = iface.mapCanvas().mapRenderer()

      layers = [missingLayer.id(),clipLayer.id()]
      mapRenderer.setLayerSet(layers)

      c = QgsComposition(mapRenderer)
      c.setPlotStyle(QgsComposition.Print)

      c.setPaperSize(148,90)
      c.setPrintResolution(300)

      # add map
      x, y = 0, 0
      w, h = c.paperWidth(), c.paperHeight()
      composerMap = QgsComposerMap(c, x,y,w,h)
      c.addItem(composerMap)

      #output to image
      dpi = c.printResolution()
      dpmm = dpi / 25.4
      width = int(dpmm * c.paperWidth())
      height = int(dpmm * c.paperHeight())

      BackgroundColor = QColor(0,0,255)

      # create output image and initialize it
      image = QImage(QSize(width, height), QImage.Format_ARGB32)
      image.setDotsPerMeterX(dpmm * 1000)
      image.setDotsPerMeterY(dpmm * 1000)
      image.fill(BackgroundColor)

      header = QgsComposerLabel(c)
      header.setItemPosition(40,1)
      header.setBackgroundEnabled(0)
      newFont = QFont("Comic Sans MS", 18)
      header.setFont(newFont)
      header.setText("Missing Countries Map")
      header.adjustSizeToText()
      c.addItem(header)

      header2 = QgsComposerLabel(c)
      header2.setItemPosition(50,11)
      header2.setBackgroundEnabled(0)
      newFont2 = QFont("Comic Sans MS", 10)
      header2.setFont(newFont2)
      header2.setText("TS="+ts)
      header2.adjustSizeToText()
      c.addItem(header2)

      footer = QgsComposerLabel(c)
      footer.setItemPosition(124,87.5)
      footer.setBackgroundEnabled(0)
      newFont3 = QFont("Times Roman", 4)
      footer.setFont(newFont3)
      footer.setText(time.ctime())
      footer.adjustSizeToText()
      c.addItem(footer)

      legend = QgsComposerLegend(c)
      legend.model().setLayerSet(mapRenderer.layerSet())
      legend.setItemPosition(5,65)
      legend.setFrameEnabled(1)
      newFont = QFont("Comic Sans MS", 6)
      legend.setStyleFont(QgsComposerLegendStyle.Title, newFont)
      legend.setStyleFont(QgsComposerLegendStyle.Subgroup, newFont)
      legend.setStyleFont(QgsComposerLegendStyle.SymbolLabel, newFont)
      legend.setStyleMargin(QgsComposerLegendStyle.Title,2)
      legend.setTitle("Legend")
      legend.setSymbolHeight(2)
      legend.adjustBoxSize()
      c.addItem(legend)

      # render the composition
      imagePainter = QPainter(image)
      imagePainter.setRenderHint(QPainter.Antialiasing)
      sourceArea = QRectF(0, 0, c.paperWidth(), c.paperHeight())
      targetArea = QRectF(0, 0, width, height)
      c.render(imagePainter, targetArea, sourceArea)
      imagePainter.end()
      imageFile = "missing_boundaries"+ts+".png"
      print "saving to "+imageFile
      image.save(imageFile)



      Yes, I do know the QqsComposer has gone but I can't find any documentation or example for QGIS3 plotting. Except the API description of COURSE.



      Any hints how to start? I don't need the whole script converted by you, only the first few lines should be enough.










      share|improve this question
















      Some days ago I upgraded from QGIS 2.18 to 3.6.0 - not knowing that many Python scripts won't run without modifications.



      I could convert all of them but not this one:



      from PyQt4.QtCore import *
      from PyQt4.QtGui import *
      from PyQt4 import QtGui
      import processing, sys, time, psycopg2
      import pprint

      ...
      creatin layers skipped (got this running)
      ...

      ################### Create Graph #####################

      mapRenderer = iface.mapCanvas().mapRenderer()

      layers = [missingLayer.id(),clipLayer.id()]
      mapRenderer.setLayerSet(layers)

      c = QgsComposition(mapRenderer)
      c.setPlotStyle(QgsComposition.Print)

      c.setPaperSize(148,90)
      c.setPrintResolution(300)

      # add map
      x, y = 0, 0
      w, h = c.paperWidth(), c.paperHeight()
      composerMap = QgsComposerMap(c, x,y,w,h)
      c.addItem(composerMap)

      #output to image
      dpi = c.printResolution()
      dpmm = dpi / 25.4
      width = int(dpmm * c.paperWidth())
      height = int(dpmm * c.paperHeight())

      BackgroundColor = QColor(0,0,255)

      # create output image and initialize it
      image = QImage(QSize(width, height), QImage.Format_ARGB32)
      image.setDotsPerMeterX(dpmm * 1000)
      image.setDotsPerMeterY(dpmm * 1000)
      image.fill(BackgroundColor)

      header = QgsComposerLabel(c)
      header.setItemPosition(40,1)
      header.setBackgroundEnabled(0)
      newFont = QFont("Comic Sans MS", 18)
      header.setFont(newFont)
      header.setText("Missing Countries Map")
      header.adjustSizeToText()
      c.addItem(header)

      header2 = QgsComposerLabel(c)
      header2.setItemPosition(50,11)
      header2.setBackgroundEnabled(0)
      newFont2 = QFont("Comic Sans MS", 10)
      header2.setFont(newFont2)
      header2.setText("TS="+ts)
      header2.adjustSizeToText()
      c.addItem(header2)

      footer = QgsComposerLabel(c)
      footer.setItemPosition(124,87.5)
      footer.setBackgroundEnabled(0)
      newFont3 = QFont("Times Roman", 4)
      footer.setFont(newFont3)
      footer.setText(time.ctime())
      footer.adjustSizeToText()
      c.addItem(footer)

      legend = QgsComposerLegend(c)
      legend.model().setLayerSet(mapRenderer.layerSet())
      legend.setItemPosition(5,65)
      legend.setFrameEnabled(1)
      newFont = QFont("Comic Sans MS", 6)
      legend.setStyleFont(QgsComposerLegendStyle.Title, newFont)
      legend.setStyleFont(QgsComposerLegendStyle.Subgroup, newFont)
      legend.setStyleFont(QgsComposerLegendStyle.SymbolLabel, newFont)
      legend.setStyleMargin(QgsComposerLegendStyle.Title,2)
      legend.setTitle("Legend")
      legend.setSymbolHeight(2)
      legend.adjustBoxSize()
      c.addItem(legend)

      # render the composition
      imagePainter = QPainter(image)
      imagePainter.setRenderHint(QPainter.Antialiasing)
      sourceArea = QRectF(0, 0, c.paperWidth(), c.paperHeight())
      targetArea = QRectF(0, 0, width, height)
      c.render(imagePainter, targetArea, sourceArea)
      imagePainter.end()
      imageFile = "missing_boundaries"+ts+".png"
      print "saving to "+imageFile
      image.save(imageFile)



      Yes, I do know the QqsComposer has gone but I can't find any documentation or example for QGIS3 plotting. Except the API description of COURSE.



      Any hints how to start? I don't need the whole script converted by you, only the first few lines should be enough.







      pyqgis qgis-3 plot






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 14 mins ago









      Vince

      14.7k32749




      14.7k32749










      asked 3 hours ago









      wambacherwambacher

      317




      317






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f314170%2fcreating-png-images-using-qgis-3-pygis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f314170%2fcreating-png-images-using-qgis-3-pygis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          Meter-Bus Содержание Параметры шины | Стандартизация |...