Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-21 Thread Nathan Woodrow
I was thinking of working on something like this tonight.  Coincidence?  I
think not.. :) Well considering my C++ skills are pretty weak, I think I
will leave it up to someone with more knowledge in the area.

On Tue, Dec 21, 2010 at 7:32 PM, Marco Hugentobler <
marco.hugentob...@sourcepole.ch> wrote:

> Hi Allesandro
>
> > Did you foresee the possibility to insert kvp substitution parameters for
> > text strings in print templates ?
>
> Yes, the possibility to replace label text (as well as extent, rotation,
> layers for composer maps) is planned.
>
> Regards,
> Marco
>
> Am Dienstag, 21. Dezember 2010, um 09.08:48 schrieb Alessandro Pasotti:
> > 2010/12/20 Andreas Neumann 
> >
> > >  Hi Allesandro,
> > >
> > > In fact, Marco is currently working on exactly what you want. He is
> > > extending QGIS mapserver with a GetPrint command that allows to specify
> > > the map extent, the layout/template to use, rotation parameter, dpi,
> > > etc. and you'll get a PDF/SVG/PNG/JPEG as output. The templates will be
> > > picked up from the QGIS project file.
> > >
> > > If you can wait until next year (probably mid to end of January) it
> will
> > > be part of QGIS mapserver.
> > >
> > > So no need to work on it in parallel - unless you have something else
> in
> > > mind.
> >
> > Great!
> >
> > This is exactly what I had in mind, so I will wait for your solution.
> >
> > Did you foresee the possibility to insert kvp substitution parameters for
> > text strings in print templates ?
> >
> > Something that allows sending substitution strings in the request, for
> > example the name of the customer or similar short text snippets.
> >
> > example:
> >
> > [ Printed by: {username}]
> >
> >
> >
> > Thanks a lot for this developments!
>
>
> --
> Dr. Marco Hugentobler
> Sourcepole - Linux & Open Source Solutions
> Churerstr. 22, CH-8808 Pfäffikon SZ, Switzerland
> marco.hugentob...@sourcepole.ch http://www.sourcepole.ch
> Technical Advisor QGIS Project Steering Committee
> ___
> Qgis-developer mailing list
> Qgis-developer@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-21 Thread Marco Hugentobler
Hi Allesandro

> Did you foresee the possibility to insert kvp substitution parameters for
> text strings in print templates ?

Yes, the possibility to replace label text (as well as extent, rotation, 
layers for composer maps) is planned.

Regards,
Marco

Am Dienstag, 21. Dezember 2010, um 09.08:48 schrieb Alessandro Pasotti:
> 2010/12/20 Andreas Neumann 
> 
> >  Hi Allesandro,
> > 
> > In fact, Marco is currently working on exactly what you want. He is
> > extending QGIS mapserver with a GetPrint command that allows to specify
> > the map extent, the layout/template to use, rotation parameter, dpi,
> > etc. and you'll get a PDF/SVG/PNG/JPEG as output. The templates will be
> > picked up from the QGIS project file.
> > 
> > If you can wait until next year (probably mid to end of January) it will
> > be part of QGIS mapserver.
> > 
> > So no need to work on it in parallel - unless you have something else in
> > mind.
> 
> Great!
> 
> This is exactly what I had in mind, so I will wait for your solution.
> 
> Did you foresee the possibility to insert kvp substitution parameters for
> text strings in print templates ?
> 
> Something that allows sending substitution strings in the request, for
> example the name of the customer or similar short text snippets.
> 
> example:
> 
> [ Printed by: {username}]
> 
> 
> 
> Thanks a lot for this developments!


-- 
Dr. Marco Hugentobler
Sourcepole - Linux & Open Source Solutions
Churerstr. 22, CH-8808 Pfäffikon SZ, Switzerland
marco.hugentob...@sourcepole.ch http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-21 Thread Alessandro Pasotti
2010/12/20 Andreas Neumann 

>  Hi Allesandro,
>
> In fact, Marco is currently working on exactly what you want. He is
> extending QGIS mapserver with a GetPrint command that allows to specify the
> map extent, the layout/template to use, rotation parameter, dpi, etc. and
> you'll get a PDF/SVG/PNG/JPEG as output. The templates will be picked up
> from the QGIS project file.
>
> If you can wait until next year (probably mid to end of January) it will be
> part of QGIS mapserver.
>
> So no need to work on it in parallel - unless you have something else in
> mind.
>

Great!

This is exactly what I had in mind, so I will wait for your solution.

Did you foresee the possibility to insert kvp substitution parameters for
text strings in print templates ?

Something that allows sending substitution strings in the request, for
example the name of the customer or similar short text snippets.

example:

[ Printed by: {username}]



Thanks a lot for this developments!

-- 
Alessandro Pasotti
w3:   www.itopen.it
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Martin Dobias
On Mon, Dec 20, 2010 at 4:54 PM, Alessandro Pasotti  wrote:
>>
>> Looking at the code, I see that you create an instance of
>> QgsMapRenderer, but do not initialize. You should call its
>> setLayerSet() and setExtent() methods so that it knows what to render.
>
> Yes you're right, I did too much cut-n-paste, just added:
> lst = [ vlayer.getLayerID() ]
> mapRenderer.setLayerSet(lst)
> rect = core.QgsRectangle(mapRenderer.fullExtent())
> rect.scale(0.8)
> mapRenderer.setExtent(rect)
>
> and now the image shows the map correctly but it still segfaults.

Hmm, weird. When I add "del c" at the end of the script, it works
fine. Another solution you might try is to do this:

--
def init():
  # init QApplication and QgsApplication
  return app

def do_stuff():
  # do rendering/printing here

app = init()
do_stuff()
--

Like this, the composer related stuff will be initialized and
finalized properly within do_stuff() method and then the application
instance will be destroyed. Just remember that it's necessary to keep
the reference to application instance - if it gets out of scope it
will be destroyed and any rendering will end up with a complete
failure.


> Dou you think is it also possible (always from a standalone script) to load
> a map composer template and a qgis project from their XML files?

>From a brief look into the code (src/app/composer/qgscomposer.cpp -
QgsComposer::readXML) the loading code is bound to GUI, so it's not
possible to load them using a single api call. But if you look into
the code, you'll see that it basically just creates the composer items
and sets their properties using readXML method of each item. It should
be possible to mimic this with a dozen (or two) of lines in python.

Btw. I have updated the composer section in the cookbook - including a
sample code for pdf export. The changes will be visible tomorrow. In
the meanwhile you can use the plain source:
http://svn.osgeo.org/qgis/docs/trunk/english_us/developer_cookbook/source/composer.rst

Regards
Martin
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Andreas Neumann

Hi Allesandro,

In fact, Marco is currently working on exactly what you want. He is 
extending QGIS mapserver with a GetPrint command that allows to specify 
the map extent, the layout/template to use, rotation parameter, dpi, 
etc. and you'll get a PDF/SVG/PNG/JPEG as output. The templates will be 
picked up from the QGIS project file.


If you can wait until next year (probably mid to end of January) it will 
be part of QGIS mapserver.


So no need to work on it in parallel - unless you have something else in 
mind.


Andreas



Thanks Martin,

I have already found your example, but it is for a plugin, isn't it ?

I remember I tried to make it work from outside qgis (standalone) 
without success.


What I would like to achieve is a CGI-style application which takes 
WMS-like parameters (like qgis-mapserver does) and a printcomposer 
template to generate a (vectorial) PDF.



--
Alessandro Pasotti
w3: www.itopen.it 


___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Alessandro Pasotti
2010/12/20 Martin Dobias 

> On Mon, Dec 20, 2010 at 4:36 PM, Alessandro Pasotti 
> wrote:
> >>
> >> It seems that the segfault happens in the python finalization code.
> >> Such crashes happen if the qt objects are deleted in wrong order.
> >> Presumably the QApplication object has been deleted earlier than the
> >> composition. That could be solved by various ways, for example,
> >> delete the composition at the end or set QApplication to be parent of
> >> the composition.
> >>
> >> Since the code crashes in the finalization stage, you should get the
> >> output png file anyway. Can you please check?
> >
> > Yes, the out.png is there but it contains a blank (white) image.
>
> Looking at the code, I see that you create an instance of
> QgsMapRenderer, but do not initialize. You should call its
> setLayerSet() and setExtent() methods so that it knows what to render.
>

Yes you're right, I did too much cut-n-paste, just added:

lst = [ vlayer.getLayerID() ]
mapRenderer.setLayerSet(lst)
rect = core.QgsRectangle(mapRenderer.fullExtent())
rect.scale(0.8)
mapRenderer.setExtent(rect)


and now the image shows the map correctly but it still segfaults.

Dou you think is it also possible (always from a standalone script) to load
a map composer template and a qgis project from their XML files?


-- 
Alessandro Pasotti
w3:   www.itopen.it
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Martin Dobias
On Mon, Dec 20, 2010 at 4:36 PM, Alessandro Pasotti  wrote:
>>
>> It seems that the segfault happens in the python finalization code.
>> Such crashes happen if the qt objects are deleted in wrong order.
>> Presumably the QApplication object has been deleted earlier than the
>> composition. That could be solved by various ways, for example,
>> delete the composition at the end or set QApplication to be parent of
>> the composition.
>>
>> Since the code crashes in the finalization stage, you should get the
>> output png file anyway. Can you please check?
>
> Yes, the out.png is there but it contains a blank (white) image.

Looking at the code, I see that you create an instance of
QgsMapRenderer, but do not initialize. You should call its
setLayerSet() and setExtent() methods so that it knows what to render.

> adding
> c.setParent(app)
> did not help, nor did
> del c
> gdb bt is similar: still crashes in the destructor of QGraphicsScene.

I will try your code in the evening on my dev computer.

Martin
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Alessandro Pasotti
2010/12/20 Martin Dobias 

> On Mon, Dec 20, 2010 at 4:03 PM, Alessandro Pasotti 
> wrote:
> >
> > I've also tried that way...
> > I've got no more than segfaults:
> > http://dpaste.com/288618/
> > Can you please take a quick look to my experiment ?
> > http://dpaste.com/288616/
>
> It seems that the segfault happens in the python finalization code.
> Such crashes happen if the qt objects are deleted in wrong order.
> Presumably the QApplication object has been deleted earlier than the
> composition. That could be solved by various ways, for example,
> delete the composition at the end or set QApplication to be parent of
> the composition.
>
> Since the code crashes in the finalization stage, you should get the
> output png file anyway. Can you please check?
>

Yes, the out.png is there but it contains a blank (white) image.

adding
c.setParent(app)

did not help, nor did
del c

gdb bt is similar: still crashes in the destructor of QGraphicsScene.


PS: I'm using current qgis trunk.
-- 
Alessandro Pasotti
w3:   www.itopen.it
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Martin Dobias
On Mon, Dec 20, 2010 at 4:03 PM, Alessandro Pasotti  wrote:
>
> I've also tried that way...
> I've got no more than segfaults:
> http://dpaste.com/288618/
> Can you please take a quick look to my experiment ?
> http://dpaste.com/288616/

It seems that the segfault happens in the python finalization code.
Such crashes happen if the qt objects are deleted in wrong order.
Presumably the QApplication object has been deleted earlier than the
composition. That could be solved by various ways, for example,
delete the composition at the end or set QApplication to be parent of
the composition.

Since the code crashes in the finalization stage, you should get the
output png file anyway. Can you please check?

Regards
Martin
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Alessandro Pasotti
2010/12/20 Martin Dobias 

> On Mon, Dec 20, 2010 at 3:19 PM, Alessandro Pasotti 
> wrote:
> > 2010/12/20 Martin Dobias 
> >>
> http://www.qgis.org/pyqgis-cookbook/composer.html#output-using-map-composer
> >
> > Thanks Martin,
> > I have already found your example, but it is for a plugin, isn't it ?
> > I remember I tried to make it work from outside qgis (standalone) without
> > success.
>
> Yes that code should work from python console in qgis or within a
> plugin. You can also make it working from outside of qgis application
> as a command line tool, you will just have to do some bootstrapping:
> initialize qgis libraries (QgsApplication: setPrefixPath, initQgis),
> load some layers, construct and set up a map renderer
> (QgsMapRenderer). The example code omits that for simplicity and uses
> map renderer from canvas.
>
>
> > What I would like to achieve is a CGI-style application which takes
> WMS-like
> > parameters (like qgis-mapserver does) and a printcomposer template to
> > generate a (vectorial) PDF.
>
> This is indeed possible - one just has to initialize all the machinery
> as briefly described above.
>
> Regards
> Martin
>


I've also tried that way...

I've got no more than segfaults:

http://dpaste.com/288618/

Can you please take a quick look to my experiment ?

http://dpaste.com/288616/


-- 
Alessandro Pasotti
w3:   www.itopen.it
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Martin Dobias
On Mon, Dec 20, 2010 at 3:19 PM, Alessandro Pasotti  wrote:
> 2010/12/20 Martin Dobias 
>> http://www.qgis.org/pyqgis-cookbook/composer.html#output-using-map-composer
>
> Thanks Martin,
> I have already found your example, but it is for a plugin, isn't it ?
> I remember I tried to make it work from outside qgis (standalone) without
> success.

Yes that code should work from python console in qgis or within a
plugin. You can also make it working from outside of qgis application
as a command line tool, you will just have to do some bootstrapping:
initialize qgis libraries (QgsApplication: setPrefixPath, initQgis),
load some layers, construct and set up a map renderer
(QgsMapRenderer). The example code omits that for simplicity and uses
map renderer from canvas.


> What I would like to achieve is a CGI-style application which takes WMS-like
> parameters (like qgis-mapserver does) and a printcomposer template to
> generate a (vectorial) PDF.

This is indeed possible - one just has to initialize all the machinery
as briefly described above.

Regards
Martin
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Alessandro Pasotti
2010/12/20 Martin Dobias 

> Hi Alessandro
>
> On Mon, Dec 20, 2010 at 2:47 PM, Alessandro Pasotti 
> wrote:
> > Hi,
> > I've spent a few hours exploring the codebase while I was thinking about
> > building a web service to generate (vectorial) PDF for a map.
> > IMHO this would be a must, expecially now that QGIS has entered in the
> web
> > service arena with qgis-mapserver.
> > The idea is to build a qgis-mapserver companion which would take care of
> > building a PDF representation of the map using the configured project(s)
> and
> > a print template.
> > The idea is that the user can configure the WMS and print template from
> QGIS
> > GUI, and have a  WMS + PDF-print service running with a few clicks.
> > The obvious road for such a service is qgis-mapserver (read layers, map
> > extent etc. from request like WMS does), + qgis-print-composer (read the
> > template name, the resolutions and paper format from request) but it
> seems
> > like the print-composer cannot work without a GUI, is this correct ?
>
> Marco has refactored the composer code few releases ago, so now it's
> possible to use the print composer by calling only qgis_core code.
> There is also a simple example how to use the composer:
>
> http://www.qgis.org/pyqgis-cookbook/composer.html#output-using-map-composer
>
> The code saves only a raster image, though saving a PDF should require
> only minor modifications of that code. If you will have any problems
> adapting it, I'll try to provide also PDF example.
>
> Regards
> Martin
>


Thanks Martin,

I have already found your example, but it is for a plugin, isn't it ?

I remember I tried to make it work from outside qgis (standalone) without
success.

What I would like to achieve is a CGI-style application which takes WMS-like
parameters (like qgis-mapserver does) and a printcomposer template to
generate a (vectorial) PDF.


-- 
Alessandro Pasotti
w3:   www.itopen.it
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Martin Dobias
Hi Alessandro

On Mon, Dec 20, 2010 at 2:47 PM, Alessandro Pasotti  wrote:
> Hi,
> I've spent a few hours exploring the codebase while I was thinking about
> building a web service to generate (vectorial) PDF for a map.
> IMHO this would be a must, expecially now that QGIS has entered in the web
> service arena with qgis-mapserver.
> The idea is to build a qgis-mapserver companion which would take care of
> building a PDF representation of the map using the configured project(s) and
> a print template.
> The idea is that the user can configure the WMS and print template from QGIS
> GUI, and have a  WMS + PDF-print service running with a few clicks.
> The obvious road for such a service is qgis-mapserver (read layers, map
> extent etc. from request like WMS does), + qgis-print-composer (read the
> template name, the resolutions and paper format from request) but it seems
> like the print-composer cannot work without a GUI, is this correct ?

Marco has refactored the composer code few releases ago, so now it's
possible to use the print composer by calling only qgis_core code.
There is also a simple example how to use the composer:

http://www.qgis.org/pyqgis-cookbook/composer.html#output-using-map-composer

The code saves only a raster image, though saving a PDF should require
only minor modifications of that code. If you will have any problems
adapting it, I'll try to provide also PDF example.

Regards
Martin
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] Is it possible to re-use print composer code to build a web service ?

2010-12-20 Thread Alessandro Pasotti
Hi,

I've spent a few hours exploring the codebase while I was thinking about
building a web service to generate (vectorial) PDF for a map.

IMHO this would be a must, expecially now that QGIS has entered in the web
service arena with qgis-mapserver.

The idea is to build a qgis-mapserver companion which would take care of
building a PDF representation of the map using the configured project(s) and
a print template.

The idea is that the user can configure the WMS and print template from QGIS
GUI, and have a  WMS + PDF-print service running with a few clicks.

The obvious road for such a service is qgis-mapserver (read layers, map
extent etc. from request like WMS does), + qgis-print-composer (read the
template name, the resolutions and paper format from request) but it seems
like the print-composer cannot work without a GUI, is this correct ?

Of course with a lot of efforts, this program could be built with
python-qgis bindings, but why can't we re-use the existing code? Most of the
functionality is already available in mapserver and printcomposer.

I would really like to hear your opinion on this topic

-- 
Alessandro Pasotti
w3:   www.itopen.it
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer