<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: QGIS Python  in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/qgis-python/m-p/595444#M46620</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Best directed to the &lt;A href="http://gis.stackexchange.com"&gt;unofficial QGIS website&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Aug 2016 19:23:14 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-08-22T19:23:14Z</dc:date>
    <item>
      <title>QGIS Python</title>
      <link>https://community.esri.com/t5/python-questions/qgis-python/m-p/595443#M46619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This question pertains to QGIS. I'm trying to automate a process where I'm joining attribute data with a shapefile. I'm able to create the desired map I'm looking for but I am having issues exporting it from the QGIS interface via PDF. When I run the code it only produces my legend in the PDF format and not my map. Please refer to the code below. I appreciate any help as I am new to coding and GIS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from qgis.core import *&lt;BR /&gt;from PyQt4 import QtGui&lt;BR /&gt;from qgis.core import *&lt;BR /&gt;from qgis.gui import *&lt;BR /&gt;from qgis.utils import iface&lt;BR /&gt;from qgis.core import *&lt;BR /&gt;from PyQt4.QtXml import QDomDocument&lt;/P&gt;&lt;P&gt;from PyQt4.QtCore import *&lt;BR /&gt;from PyQt4.QtGui import *&lt;/P&gt;&lt;P&gt;import pyodbc&lt;BR /&gt;import os&lt;BR /&gt;import sys&lt;BR /&gt;import socket&lt;BR /&gt;import csv&lt;BR /&gt;import processing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;county_uri = 'O:/Broker Support/Cat Modeling/QGIS/Shapefiles/US Counties/UScounties.shp'&lt;BR /&gt;shp = QgsVectorLayer(county_uri, 'UScounties', 'ogr')&lt;BR /&gt;QgsMapLayerRegistry.instance().addMapLayer(shp)&lt;/P&gt;&lt;P&gt;csv_uri = "file:///O:/Broker Support/Cat Modeling/ArcGIS/File.csv?delimeter=,"&lt;BR /&gt;csv = QgsVectorLayer(csv_uri, "File", "delimitedtext")&lt;BR /&gt;QgsMapLayerRegistry.instance().addMapLayer(csv)&lt;/P&gt;&lt;P&gt;shpField='state_coun'&lt;BR /&gt;csvField='state_coun'&lt;BR /&gt;joinObject = QgsVectorJoinInfo()&lt;BR /&gt;joinObject.joinLayerId = csv.id()&lt;BR /&gt;joinObject.joinFieldName = csvField&lt;BR /&gt;joinObject.targetFieldName = shpField&lt;BR /&gt;joinObject.memoryCache = True&lt;BR /&gt;shp.addJoin(joinObject)&lt;BR /&gt;True&lt;/P&gt;&lt;P&gt;colorRamp = QgsVectorGradientColorRampV2.create({'color1':'188,255,255,255', 'color2':'0,0,128,255','stops':'0.25;176,196,222,255:0.50;70,130,180,255:0.75;65,105,225,255'})&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;renderer = QgsGraduatedSymbolRendererV2.createRenderer(shp, 'File', 6, QgsGraduatedSymbolRendererV2.Jenks, QgsSymbolV2.defaultSymbol( shp.geometryType() ), colorRamp )&lt;BR /&gt;shp.setRendererV2( renderer )&lt;BR /&gt;QgsMapLayerRegistry.instance().addMapLayer(shp)&lt;/P&gt;&lt;P&gt;qgis.utils.iface.activeLayer()&lt;/P&gt;&lt;P&gt;qgis.utils.iface.actionZoomToLayer().trigger()&lt;/P&gt;&lt;P&gt;def savePDF():&lt;BR /&gt; mapRenderer = iface.mapCanvas().mapRenderer()&lt;BR /&gt; c = QgsComposition(mapRenderer)&lt;BR /&gt; c.setPlotStyle(QgsComposition.Print)&lt;BR /&gt; x, y = 0, 0&lt;BR /&gt; w, h = c.paperWidth(), c.paperHeight()&lt;BR /&gt; composerMap = QgsComposerMap(c, x ,y, w, h)&lt;BR /&gt; rect = iface.mapCanvas().currentLayer().extent()&lt;BR /&gt; composerMap.setNewExtent(rect)&lt;BR /&gt; c.addItem(composerMap)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; legend = QgsComposerLegend(c)&lt;BR /&gt; legend.model().setLayerSet(mapRenderer.layerSet())&lt;BR /&gt; c.addItem(legend)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;outpath = "\\\\ba-fs-nc\\data\\Broker Support\\Cat Modeling\\QGIS\File.pdf"&lt;BR /&gt; printer = QPrinter()&lt;BR /&gt; printer.setOutputFormat(QPrinter.PdfFormat)&lt;BR /&gt; printer.setOutputFileName(outpath)&lt;BR /&gt; printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()), QPrinter.Millimeter)&lt;BR /&gt; printer.setFullPage(True)&lt;BR /&gt; printer.setColorMode(QPrinter.Color)&lt;BR /&gt; printer.setResolution(c.printResolution())&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; pdfPainter = QPainter(printer)&lt;BR /&gt; paperRectMM = printer.pageRect(QPrinter.Millimeter)&lt;BR /&gt; paperRectPixel = printer.pageRect(QPrinter.DevicePixel)&lt;BR /&gt; c.render(pdfPainter, paperRectPixel, paperRectMM)&lt;BR /&gt; pdfPainter.end()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;QTimer.singleShot(3000, savePDF)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2016 19:18:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/qgis-python/m-p/595443#M46619</guid>
      <dc:creator>paulmcburney2</dc:creator>
      <dc:date>2016-08-22T19:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: QGIS Python</title>
      <link>https://community.esri.com/t5/python-questions/qgis-python/m-p/595444#M46620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Best directed to the &lt;A href="http://gis.stackexchange.com"&gt;unofficial QGIS website&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2016 19:23:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/qgis-python/m-p/595444#M46620</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-08-22T19:23:14Z</dc:date>
    </item>
  </channel>
</rss>

