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

Hugo Mercier hugo.mercier at oslandia.com
Thu Feb 27 05:41:02 PST 2014


Hello,

Yes.
You should now call QgsComposerMap.setAtlasDriven(True) and set your
scale preferences (fixed or margin) on each composer map.

Old functions are marked as deprecated.

Le 27/02/2014 12:41, Alexandre Neto a écrit :
> Hello matt,
> 
> That must have to do with the fact that now it's possible to control
> more that one map extent with atlas, that means that for each map item
> you need to check the control by atlas option.
> 
> The same probably applies to the python scripts.
> 
> Hope I helped,
> 
> Alexandre Neto
> 
> 
> On Thu, Feb 27, 2014 at 11:19 AM, mattwalsh
> <matthew at miningsearchesuk.com <mailto:matthew at miningsearchesuk.com>> wrote:
> 
>     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.
>     _______________________________________________
>     Qgis-developer mailing list
>     Qgis-developer at lists.osgeo.org <mailto:Qgis-developer at lists.osgeo.org>
>     http://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> 
> 
> 
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
> 


-- 
Hugo Mercier
Oslandia


More information about the Qgis-developer mailing list