January 30, 2016 Afternoon

Good afternoon. Currently mostly sunny and 39 degrees in Delmar. Tonight will be mostly cloudy, with a low around 33. South wind 6 to 10 mph. Bit of a chilly breeze this evening but fairly mild.

Sunset will be at 5:06 pm with twilight at 5:36 pm which is one minute and 19 seconds later then yesterday. Tonight we will have a Waining Gibbous Moon with 53% illuminated. It will rise at 11:40 pm.

Sunday will be mostly cloudy, with a high near 47. South wind around 7 mph. Warmer but not as nice today. There have been too many cloudy days recently.

Recovering from last night today. I also spent a fair bit of time working on maps of various state lands and finishing my PyQGIS scripting project. Going out to Five Rivers to watch the sun clear on this nice but cold evening.

Code Scrap for Exporting a QGIS Composer to a Vector PDF

This is the traditional method of Python Scripting to export a QGIS Composer as an Adobe Acrobat PDF file. This produces a vector PDF file regardless of your setting under “Print as a Raster”. This provides the highest quality print output, but may cause incorrect rendering if you use effects like multiply layers. Tomorrow I will post code I use for making PDFs, using compressed (but high resolution) Raster JPEG files embedded in the PDF files.

It’s possible you won’t need to import as many classes as I did. I just didn’t carefully go through the list to remove classes that are unnecessary (as they are neccessary for my plugin code). You will need to adjust the output file name and the window title for the Composer to whatever you named your Composer as. Remember if you use this in a plugin class, to make iface to self.iface or this code won’t work. Stupid stuff like that will trip you up.

from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication,QFileInfo,QSizeF
from PyQt4.QtGui import QAction, QIcon, QPrinter,QPainter

composerId = 0
composers = iface.activeComposers()
for item in composers:
	if item.composerWindow().windowTitle() == 'Horizontal':
		break
	composerId += 1

c = composers[composerId].composition()

image = c.printPageAsRaster(True, QSize(),c.printResolution())

printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName("/tmp/"+QgsProject.instance().title()+".pdf")
printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()), QPrinter.Millimeter)
printer.setFullPage(True)
printer.setColorMode(QPrinter.Color)
printer.setResolution(c.printResolution())

pdfPainter = QPainter(printer)
c.renderPage(pdfPainter,0)
pdfPainter.end()

I hope this is helpful. I’m not a real PyQGIS pro, but if you have ideas or comments, please add them below.

Rensslear Plateau

I had trouble finding a clear example online of how to export a composer file as a Vector Adobe Acrobat PDF you have loaded in Quantum GIS via a Python plugin or script. This code that I put together does the trick.

33rd Birthday of Andy 2016 Night

Good evening. Currently overcast and 26 degrees in Delmar. With the wind it seems pretty frigid outside. Tonight will be partly cloudy, with a low around 22. Northwest wind 8 to 17 mph, with gusts as high as 28 mph. I’m under the covers and in bed, so I don’t really care. It was however cold at the bus stop. Warming up for the weekend.

Tonight we will have a Waining Gibbous Moon with 60% illuminated. It will rise at 10:43 pm. Tomorrow’s sunrise will be at 7:11 am with first light at 6:41 am, which is one minute earlier then today.

I hope you had a good week and are looking forward to a relaxing weekend. I had a truly special birthday thanks to my friends at work. Sleep well!