[Qgis-developer] Atlas export Python script not working in 2.2

mattwalsh matthew at miningsearchesuk.com
Thu Feb 27 03:19:24 PST 2014


Hello, 

I am having a bit trouble migrating a script to QGIS 2.2. 

In QGIS 2.0 I have the following Python script which will load a composer
from template, generate an atlas and export to image. 

        myFile = os.path.join(os.path.dirname(__file__), template)
        myTemplateFile = file(myFile, 'rt')
        myTemplateContent = myTemplateFile.read()
        myTemplateFile.close()
        myDocument = QDomDocument()
        myDocument.setContent(myTemplateContent)
        myComposition.loadFromTemplate(myDocument)

        # Get map composition and define scale
        myAtlasMap = myComposition.getComposerMapById(0)
        myAtlasMap.setNewScale(int(scale))

        # Setup Atlas
        myAtlas = QgsAtlasComposition(myComposition)
        myAtlas.setCoverageLayer(atlas_desktop)
        myAtlas.setComposerMap(myAtlasMap)
        myAtlas.setFixedScale(True)
        myAtlas.fixedScale()
        myAtlas.setHideCoverage(False)
        myAtlas.setFilterFeatures(True)
        myAtlas.setFeatureFilter("reference = '%s'" % (str(ref)))
        myAtlas.setFilterFeatures(True)
        print myAtlas.composerMap()

        # Generate atlas
        myAtlas.beginRender()
        for i in range(0, myAtlas.numFeatures()):
            myAtlas.prepareForFeature( i )
            jobs = r"\\myserver\a folder\Jobs"
            job_fol = os.path.join(jobs, str(ref))
            if not os.path.exists(job_fol):
                os.makedirs(job_fol)
            output_jpeg = os.path.join(job_fol, ref + "_BMS_plan.jpg")
            myImage = myComposition.printPageAsRaster(0)
            myImage.save(output_jpeg)
        myAtlas.endRender()
        if os.path.isfile(output_jpeg) is False:
            QMessageBox.warning(self.iface.mainWindow(), "Uh Oh!",
"Something went wrong, no image exported!")
            return
        else:
            return

In QGIS 2.2 this script is no longer working correctly. The template is
loaded and a map is exported to image, however, the map does not display the
correct area. The map area draws the correct layers but the extent is wrong
(no where near the feature from the atlas). Had a look at the documentation
and wasn't really able to see what has changed/deprecated? 

Thanks
Matt





--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Atlas-export-Python-script-not-working-in-2-2-tp5106328.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list