-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement QgsPaintEngineHack.fixEngineFlags http://qgis.org/api/2.0/q…
…gspaintenginehack_8cpp_source.html to get correct styles with PDF export.
- Loading branch information
1 parent
bef911e
commit d8d0823
Showing
11 changed files
with
238 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from PyQt4.QtCore import QFile | ||
from PyQt4.QtXml import QDomDocument | ||
from PyQt4.QtCore import QIODevice | ||
from PyQt4.QtCore import QSizeF | ||
from PyQt4.QtGui import QPrinter | ||
from PyQt4.QtGui import QPainter | ||
import os | ||
|
||
pdf_out = '/home/bergw/_TEMP/out.pdf' | ||
if os.path.isfile(pdf_out): | ||
os.remove(pdf_out) | ||
mapRenderer = iface.mapCanvas().mapRenderer() | ||
c = QgsComposition(mapRenderer) | ||
c.setPlotStyle(QgsComposition.Print) | ||
#print dir(c) | ||
#c.setAtlasMode(QgsComposition.AtlasMode.ExportAtlas) | ||
|
||
xml_file = QFile('/home/bergw/VoGIS-Raumplanung-Daten/A4_hoch_template.qpt') | ||
if xml_file.open(QIODevice.ReadOnly) is False: | ||
throwError | ||
|
||
doc = QDomDocument('mydoc') | ||
doc.setContent(xml_file) | ||
if c.loadFromTemplate(doc) is False: | ||
throwError | ||
|
||
cov_lyr = iface.activeLayer() | ||
print 'cov_lyr', cov_lyr.name() | ||
ac = c.atlasComposition() | ||
ac.setEnabled(True) | ||
ac.setSingleFile(True) | ||
ac.setCoverageLayer(cov_lyr) | ||
#ac.setFeatureFilter('length("GNR") > 7 AND left("GNR",3)=\'120\'') | ||
ac.setFeatureFilter('"GNR" = \'905\'') | ||
ac.setHideCoverage(False) | ||
|
||
print 'beginRender, feats:', ac.numFeatures() | ||
ac.beginRender() | ||
for i in range(0, ac.numFeatures()): | ||
print 'prepareForFeature', i | ||
ac.prepareForFeature(i) | ||
img = c.printPageAsRaster(0) | ||
tmp_file = '/home/bergw/_TEMP/' + str(i) + '.jpg' | ||
if os.path.isfile(tmp_file): | ||
os.remove(tmp_file) | ||
img.save(tmp_file) | ||
ac.endRender() | ||
print 'render finished' | ||
|
||
|
||
#printer = QPrinter() | ||
#printer.setOutputFormat(QPrinter.PdfFormat) | ||
#printer.setOutputFileName(pdf_out) | ||
#printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()), QPrinter.Millimeter) | ||
#printer.setFullPage(True) | ||
#printer.setColorMode(QPrinter.Color) | ||
#printer.setResolution(c.printResolution()) | ||
|
||
#pdfPainter = QPainter(printer) | ||
#paperRectMM = printer.pageRect(QPrinter.Millimeter) | ||
#paperRectPixel = printer.pageRect(QPrinter.DevicePixel) | ||
#TODO: checken ob File vorhanden? | ||
#LOESCHEN!!! | ||
#c.render(pdfPainter, paperRectPixel, paperRectMM) | ||
#pdfPainter.end() | ||
|
||
print 'FERTIG' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from PyQt4.QtCore import QFile | ||
from PyQt4.QtXml import QDomDocument | ||
from PyQt4.QtCore import QIODevice | ||
from PyQt4.QtCore import QSizeF | ||
from PyQt4.QtGui import QPrinter | ||
from PyQt4.QtGui import QPainter | ||
import os | ||
import subprocess | ||
|
||
pdf_out = '/home/bergw/_TEMP/out.pdf' | ||
if os.path.isfile(pdf_out): | ||
os.remove(pdf_out) | ||
mapRenderer = iface.mapCanvas().mapRenderer() | ||
c = QgsComposition(mapRenderer) | ||
|
||
xml_file = QFile('/home/bergw/VoGIS-Raumplanung-Daten/A4_hoch_template.qpt') | ||
if xml_file.open(QIODevice.ReadOnly) is False: | ||
throwError | ||
|
||
doc = QDomDocument('mydoc') | ||
doc.setContent(xml_file) | ||
if c.loadFromTemplate(doc) is False: | ||
throwError | ||
|
||
if QGis.QGIS_VERSION_INT > 20200: | ||
#compmaps = self.__get_items(QgsComposerMap) | ||
#compmap = compmaps[0] | ||
pass | ||
else: | ||
compmap = c.composerMapItems()[0] | ||
|
||
c.setPlotStyle(QgsComposition.Print) | ||
compmap.setPreviewMode(QgsComposerMap.Render) | ||
#compmap.updateItem() | ||
#emit compmap.itemChanged(); | ||
#compmap.extentChanged(); | ||
#compmap.toggleAtlasPreview() | ||
#compmap.setNewScale(compmap.scale()+1) | ||
#c.setPrintResolution(150) | ||
#print c.printResolution() | ||
c.setPrintAsRaster(False) | ||
|
||
printer = QPrinter() | ||
printer.setOutputFormat(QPrinter.PdfFormat) | ||
printer.setOutputFileName(pdf_out) | ||
printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()), QPrinter.Millimeter) | ||
printer.setFullPage(True) | ||
printer.setColorMode(QPrinter.Color) | ||
printer.setResolution(c.printResolution()) | ||
|
||
pdfPainter = QPainter(printer) | ||
paperRectMM = printer.pageRect(QPrinter.Millimeter) | ||
paperRectPixel = printer.pageRect(QPrinter.DevicePixel) | ||
|
||
QgsPaintEngineHack.fixEngineFlags(printer.paintEngine()) | ||
|
||
#c.renderPage(pdfPainter, 0) | ||
c.doPrint(printer,pdfPainter) | ||
|
||
pdfPainter.end() | ||
subprocess.call(('xdg-open', pdf_out)) | ||
|
||
print 'FERTIG' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from PyQt4.QtCore import QFile | ||
from PyQt4.QtXml import QDomDocument | ||
from PyQt4.QtCore import QIODevice | ||
from PyQt4.QtCore import QSizeF | ||
from PyQt4.QtGui import QPrinter | ||
from PyQt4.QtGui import QPainter | ||
import os | ||
|
||
pdf_out = '/home/bergw/_TEMP/out.pdf' | ||
if os.path.isfile(pdf_out): | ||
os.remove(pdf_out) | ||
mapRenderer = iface.mapCanvas().mapRenderer() | ||
c = QgsComposition(mapRenderer) | ||
c.setPlotStyle(QgsComposition.Print) | ||
#print dir(c) | ||
#c.setAtlasMode(QgsComposition.AtlasMode.ExportAtlas) | ||
|
||
xml_file = QFile('/home/bergw/VoGIS-Raumplanung-Daten/A4_hoch_template.qpt') | ||
if xml_file.open(QIODevice.ReadOnly) is False: | ||
throwError | ||
|
||
doc = QDomDocument('mydoc') | ||
doc.setContent(xml_file) | ||
if c.loadFromTemplate(doc) is False: | ||
throwError | ||
|
||
cov_lyr = iface.activeLayer() | ||
print 'cov_lyr', cov_lyr.name() | ||
ac = c.atlasComposition() | ||
ac.setEnabled(True) | ||
ac.setSingleFile(True) | ||
ac.setCoverageLayer(cov_lyr) | ||
#ac.setFeatureFilter('length("GNR") > 7 AND left("GNR",3)=\'120\'') | ||
ac.setFeatureFilter('"GNR" = \'905\'') | ||
ac.setHideCoverage(False) | ||
|
||
print 'beginRender, feats:', ac.numFeatures() | ||
ac.beginRender() | ||
for i in range(0, ac.numFeatures()): | ||
print 'prepareForFeature', i | ||
ac.prepareForFeature(i) | ||
img = c.printPageAsRaster(0) | ||
tmp_file = '/home/bergw/_TEMP/' + str(i) + '.jpg' | ||
if os.path.isfile(tmp_file): | ||
os.remove(tmp_file) | ||
img.save(tmp_file) | ||
ac.endRender() | ||
print 'render finished' | ||
|
||
|
||
#printer = QPrinter() | ||
#printer.setOutputFormat(QPrinter.PdfFormat) | ||
#printer.setOutputFileName(pdf_out) | ||
#printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()), QPrinter.Millimeter) | ||
#printer.setFullPage(True) | ||
#printer.setColorMode(QPrinter.Color) | ||
#printer.setResolution(c.printResolution()) | ||
|
||
#pdfPainter = QPainter(printer) | ||
#paperRectMM = printer.pageRect(QPrinter.Millimeter) | ||
#paperRectPixel = printer.pageRect(QPrinter.DevicePixel) | ||
#TODO: checken ob File vorhanden? | ||
#LOESCHEN!!! | ||
#c.render(pdfPainter, paperRectPixel, paperRectMM) | ||
#pdfPainter.end() | ||
|
||
print 'FERTIG' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
lyr = iface.activeLayer() | ||
#r = QgsFeatureRequest() | ||
#print dir(r) | ||
#r.setFilterExpression(u'PGEM_NAME = \'Dornbirn\'') | ||
gst = {} | ||
for f in lyr.getFeatures(): | ||
if f['PGEM_NAME'] == 'Dornbirn': | ||
gnr = f['GNR'] | ||
if not gnr in gst: | ||
gst[gnr] = f | ||
print len(gst), 'Grundstuecke' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import multiprocessing as mp | ||
import sys, os | ||
|
||
from multiprocessing import Process | ||
|
||
print("I'm in main module") | ||
# OSGeo4W does not bundle python in exec_prefix for python | ||
path = os.path.abspath(os.path.join(sys.exec_prefix, '../../bin/pythonw.exe')) | ||
mp.set_executable(path) | ||
print("Setting executable path to {:s}".format(path)) | ||
sys.argv = [ None ] # '../tst.py' __file__ | ||
mgr = mp.Manager() | ||
print("I'm past Manager()") |
Binary file not shown.