[Qgis-developer] Scripting QGIS from the outside using Python

Marco Hugentobler marco.hugentobler at sourcepole.ch
Mon Mar 19 03:37:05 EDT 2012


Hi Nathan

 >What I have seen so far looks like you have to handle recreating the 
composer and all its items using the xml like in

There has been some rearrangement in the composer classes (the first API 
break :-) ). With git master version, you should be able to create a 
QgsComposition by calling its readXML Method, then call 
QgsComposition::readItemsFromXML.

The composer is a bit of a special case because it is possible to 
replace label strings, map extent / layer / rotation with parameters. 
And with the legend, there is a workaround to avoid using the x-server. 
So with an external python script, I'd recommend to use 
QgsComposition::readItemsFromXML.

Regards,
Marco

On 19.03.2012 01:22, Nathan Woodrow wrote:
> Martin,
>
> It's not so much that I don't know how to create a new composer from 
> Python more that I don't now how to restore a composer item from the 
> project file using Python.
>
> I'm using the project file that contains composers as a template which 
> I need to open and print.  What I have seen so far looks like you have 
> to handle recreating the composer and all its items using the xml like 
> in 
> https://github.com/qgis/Quantum-GIS/blob/master/src/mapserver/qgsprojectparser.cpp
>
> Maybe the composer object could do with a createFromXML() method which 
> constructs a composer, and all its children, as per the project file.
>
> - Nathan
>
> On Mon, Mar 19, 2012 at 4:51 AM, Martin Dobias <wonder.sk at gmail.com 
> <mailto:wonder.sk at gmail.com>> wrote:
>
>     On Thu, Mar 15, 2012 at 2:29 PM, Nathan Woodrow
>     <madmanwoo at gmail.com <mailto:madmanwoo at gmail.com>> wrote:
>     > Is it possible to:
>     >
>     > Load QGIS from Python (well I know how to do this using
>     > QgsApplicaiton.Init())
>     > Open the project file
>     > Zoom to a location
>     > Print the first composer to pdf
>     > OR render out the map canvas to a image.
>
>     Hi Nathan
>
>     yes that's all possible from an external python script with PyQGIS,
>     without actually starting GUI.
>
>     > From what I can see the only way is to create a new composer
>     item and pass
>     > it the composer node from the xml.
>
>     No need to play with XML, everything can be done using API, there is
>     an example in the cookbook:
>     http://qgis.org/pyqgis-cookbook/composer.html
>
>     Martin
>
>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer


-- 
Dr. Marco Hugentobler
Sourcepole -  Linux&  Open Source Solutions
Churerstrasse 22, CH-8808 Pfäffikon SZ, Switzerland
marco.hugentobler at sourcepole.ch http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120319/8672ded1/attachment.html


More information about the Qgis-developer mailing list