Re: [Qgis-developer] Render with labels

2014-10-06 Thread Anita Graser

Thanks a lot Stefan! QgsMapRendererCustomPainterJob works like a charm.

Best wishes,
Anita


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


Re: [Qgis-developer] Render with labels

2014-10-06 Thread Ziegler Stefan
Yes, they were introduced in 2.4.

Regards
Stefan

Von: Geo DrinX [mailto:geodr...@gmail.com]
Gesendet: Montag, 6. Oktober 2014 12:12
An: Ziegler Stefan
Cc: Anita Graser; qgis-developer@lists.osgeo.org
Betreff: Re: [Qgis-developer] Render with labels

Hi Stefan,


I did have some problems with dpi output and qgsmaprenderer. Martin Dobias 
helped me at the hackfest. Now I’m using qgsmaprendererjob classes and it works 
with custom dpi and labels

Great  !Thank you also to Martin   :)
I am studing your source code...
BTW,   are  "qgsmaprendererjob"   classes  introduced from 2.4 version ?
In that case, I need to use a conditional like this :

  if  QGis.QGIS_VERSION_INT > 20200:

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

Re: [Qgis-developer] Render with labels

2014-10-06 Thread Geo DrinX
Hi Stefan,


>
> I did have some problems with dpi output and qgsmaprenderer. Martin Dobias
> helped me at the hackfest. Now I’m using qgsmaprendererjob classes and it
> works with custom dpi and labels
>

Great  !Thank you also to Martin   :)

I am studing your source code...

BTW,   are  "qgsmaprendererjob"   classes  introduced from 2.4 version ?

In that case, I need to use a conditional like this :

  if  QGis.QGIS_VERSION_INT > 20200:
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [Qgis-developer] Render with labels

2014-10-06 Thread Ziegler Stefan
Hi

I did have some problems with dpi output and qgsmaprenderer. Martin Dobias 
helped me at the hackfest. Now I’m using qgsmaprendererjob classes and it works 
with custom dpi and labels:

mapSettings = QgsMapSettings()
mapSettings.setMapUnits(0)
mapSettings.setExtent(rect)
mapSettings.setOutputDpi(DPI)
mapSettings.setOutputSize(QSize(width, height))
mapSettings.setLayers(lst)
mapSettings.setFlags(QgsMapSettings.Antialiasing | 
QgsMapSettings.UseAdvancedEffects | QgsMapSettings.ForceVectorOutput | 
QgsMapSettings.DrawLabeling)

img = QImage(QSize(width, height), QImage.Format_RGB32)
#img = QImage(QSize(width, height), QImage.Format_Mono)
img.setDotsPerMeterX(DPI / 25.4 * 1000)
img.setDotsPerMeterY(DPI / 25.4 * 1000)

p = QPainter()
p.begin(img)

mapRenderer = QgsMapRendererCustomPainterJob(mapSettings, p)

mapRenderer.start()
mapRenderer.waitForFinished()

p.end()

img.save("/tmp/"+filename+".png","png")

regards
Stefan

Von: qgis-developer-boun...@lists.osgeo.org 
[mailto:qgis-developer-boun...@lists.osgeo.org] Im Auftrag von Geo DrinX
Gesendet: Montag, 6. Oktober 2014 11:25
An: Anita Graser
Cc: qgis-developer@lists.osgeo.org
Betreff: Re: [Qgis-developer] Render with labels

Hello,
Sorry if I repeat my question that I sent some time ago,  but it seems very 
relevant to the topic.

I noticed that using  the.render()function  with  pyQgis > 2.2   the 
labels are not  visible.
This is my test source code (taken from my GEarthView plugin):


iface = qgis.utils.iface

mapRenderer = mapCanvas.mapRenderer()
mapRect = mapRenderer.extent()
width = mapRenderer.width()
height = mapRenderer.height()
srs = mapRenderer.destinationCrs()

# create output image and initialize it
image = QImage(QSize(width, height), QImage.Format_ARGB32)
image.fill(0)

#adjust map canvas (renderer) to the image size and render
imagePainter = QPainter(image)

zoom = 1
target_dpi = int(round(zoom * mapRenderer.outputDpi()))

mapRenderer.setOutputSize(QSize(width, height), target_dpi)

mapRenderer.render(imagePainter)
imagePainter.end()

xN = mapRect.xMinimum()
yN = mapRect.yMinimum()

nomePNG = ("TestImage")

input_file = out_folder + "/" + nomePNG + ".png"

image.save(input_file, "png")

So, my question is :  how need to change my code to have labels again visible ?

:)

Thank you for any link and answer
Roberto

2014-10-05 22:18 GMT+02:00 Anita Graser 
mailto:anitagra...@gmx.at>>:
Am 05.10.2014, 18:54 Uhr, schrieb Larry Shaffer 
mailto:lar...@dakotacarto.com>>:
Here's a small script you can use to test the Python bindings for labeling

Thanks a lot Larry! I'll give it a try!
Feel free to add this to the Cookbook. However, the API for labeling may
change during the 2.7 dev cycle, if rule- and style-based labeling is
introduced.

You mean it will change without breaking it? ;-)


Best wishes,
Anita


--
anitagraser.com<http://anitagraser.com>
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org<mailto: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] Render with labels

2014-10-06 Thread Geo DrinX
Hello,

Sorry if I repeat my question that I sent some time ago,  but it seems
very relevant
to the topic.

I noticed that using  the.render()function  with  pyQgis > 2.2
the labels are not  visible.

This is my test source code (taken from my GEarthView plugin):


iface = qgis.utils.iface

mapRenderer = mapCanvas.mapRenderer()
mapRect = mapRenderer.extent()
width = mapRenderer.width()
height = mapRenderer.height()
srs = mapRenderer.destinationCrs()

# create output image and initialize it
image = QImage(QSize(width, height), QImage.Format_ARGB32)
image.fill(0)

#adjust map canvas (renderer) to the image size and render
imagePainter = QPainter(image)

zoom = 1
target_dpi = int(round(zoom * mapRenderer.outputDpi()))


mapRenderer.setOutputSize(QSize(width, height), target_dpi)

mapRenderer.render(imagePainter)
imagePainter.end()

xN = mapRect.xMinimum()
yN = mapRect.yMinimum()

nomePNG = ("TestImage")

input_file = out_folder + "/" + nomePNG + ".png"

image.save(input_file, "png")


So, my question is :  how need to change my code to have labels again
visible ?

:)


Thank you for any link and answer

Roberto

2014-10-05 22:18 GMT+02:00 Anita Graser :

> Am 05.10.2014, 18:54 Uhr, schrieb Larry Shaffer :
>
>> Here's a small script you can use to test the Python bindings for labeling
>>
>
> Thanks a lot Larry! I'll give it a try!
>
>  Feel free to add this to the Cookbook. However, the API for labeling may
>> change during the 2.7 dev cycle, if rule- and style-based labeling is
>> introduced.
>>
>
> You mean it will change without breaking it? ;-)
>
>
> Best wishes,
> Anita
>
>
> --
> anitagraser.com
> ___
> 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] Render with labels

2014-10-05 Thread Anita Graser

Am 05.10.2014, 18:54 Uhr, schrieb Larry Shaffer :
Here's a small script you can use to test the Python bindings for  
labeling


Thanks a lot Larry! I'll give it a try!


Feel free to add this to the Cookbook. However, the API for labeling may
change during the 2.7 dev cycle, if rule- and style-based labeling is
introduced.


You mean it will change without breaking it? ;-)

Best wishes,
Anita


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


Re: [Qgis-developer] Render with labels

2014-10-05 Thread Larry Shaffer
Hi Anita,

On Sun, Oct 5, 2014 at 9:45 AM, Anita Graser  wrote:

> Hi,
>
> I'm trying to use one of the examples from the PyQGIS Cookbook to render a
> map at custom resolution:
>
> http://docs.qgis.org/testing/en/docs/pyqgis_developer_
> cookbook/composer.html#simple-rendering
>
> While the layers render fine, no labels are drawn. Do you know how I can
> add labels to the output?
>
> I tried
>
> render.setLabelingEngine(QgsPalLabeling())
>
> but no luck.
>

Here's a small script you can use to test the Python bindings for labeling
[0]. It is intended to be run from within the PyQGIS console's script
editor, and uses the Spatialite db for labeling unit tests, called '
pal_features_v3.sqlite' [1].

Setup:

* Load the 'background' layer
* Load the 'point' layer on top of 'background'
* Select the 'point' layer in the legend
* Open script in console's editor and run it

When script is run, you should end up with something like this [2],
probably with different fill color for 'background'.

See the Python labeling test suite for more examples, from
'test_qgspallabeling_*.py' [3], specifically the
'test_qgspallabeling_tests.py' file.

Feel free to add this to the Cookbook. However, the API for labeling may
change during the 2.7 dev cycle, if rule- and style-based labeling is
introduced.

[0] https://gist.github.com/dakcarto/33115cd569e17b9419c0
[1] https://github.com/qgis/QGIS/tree/master/tests/testdata/labeling
[2] http://drive.dakotacarto.com/qgis/labeling_py-api.png
[3] https://github.com/qgis/QGIS/tree/master/tests/src/python

Regards,

Larry Shaffer
Dakota Cartography
Black Hills, South Dakota


>
> Thanks and best wishes,
> Anita
>
>
> --
> anitagraser.com
> ___
> 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

[Qgis-developer] Render with labels

2014-10-05 Thread Anita Graser

Hi,

I'm trying to use one of the examples from the PyQGIS Cookbook to render a  
map at custom resolution:


http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/composer.html#simple-rendering

While the layers render fine, no labels are drawn. Do you know how I can  
add labels to the output?


I tried

render.setLabelingEngine(QgsPalLabeling())

but no luck.

Thanks and best wishes,
Anita


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