[Qgis-user] QgsComposerAttributeTableV2

2015-06-23 Thread Benoît Laurent

Hello,

I am still writing Python script. At the present time, I would like to 
add a QgsComposerAttributeTableV2 
 to a 
QgsComposition 
. 



However, I don't know how to use the addComposerTableFrame 
 
method. I don't understand the second parameter of the method. Is there 
a example of code somewhere ?


Thank you in advance.

Regards,

Benoît



---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
https://www.avast.com/antivirus
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Transparency for vector symbol layers

2015-06-23 Thread Benoît Laurent

Hello Andreas,

Thank you very much for your complete answer.

Actually, I reached my goal using rule based renderers.

Regards,

Benoît


Hi Benoit,

It depends. Yes - you can mix transparent and opaque features. For 
each color you can also set the opacity/transparency value.


However, if two features overlap and you use transparency on the 
feature level, you can see the features shine through - whereas when 
the transparency would be on the symbol level (which isn't implemented 
yet in QGIS) you would first composite all elements in a symbol level 
and then apply the opacity on the whole group. See 
http://www.w3.org/TR/2011/REC-SVG11-20110816/masking.html#ObjectAndGroupOpacityProperties 
for the difference. In 
http://www.w3.org/TR/2011/REC-SVG11-20110816/images/masking/opacity01.png 
- if you look at the bottom row of circles - the second pair of 
circles has the opacity on the group of two circles, whereas the third 
pair has opacity on every single element. I hope you can see the 
difference.


It would be very cool if QGIS could have a more fine-grained opacity - 
new opacity on symbol level and new opacity on a whole group of 
layers. It would make the cartographic options even better ;-)


Andreas

On 19.06.2015 16:40, Benoît Laurent wrote:

Hello,

I noticed this feature request : https://hub.qgis.org/issues/3438.

Is it possible to have semi-transparent and opaque features within 
the same layer ?


Best regards,

Benoît

---
L'absence de virus dans ce courrier électronique a été vérifiée par 
le logiciel antivirus Avast.

https://www.avast.com/antivirus

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


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


--
Signature_Benoit_Laurent
Heurisis <http://www.heurisis.eu>
    

Benoît LAURENT Consultant Optimisation

9, rue Alexandre Fleming, 49066 Angers CEDEX

Portable +33 (0)6 28 03 81 32 e-mail : blaur...@heurisis.eu 
<mailto:blaur...@heurisis.eu>

tel : +33 (0)9 54 30 41 14 site : www.heurisis.eu <http://www.heurisis.eu/>


Visitez le site www.optiscolaire.fr <http://www.optiscolaire.fr>

éco : Avant d’imprimer ce mail, pensez à l’environnement




---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
https://www.avast.com/antivirus
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user

[Qgis-user] Transparency for vector symbol layers

2015-06-19 Thread Benoît Laurent

Hello,

I noticed this feature request : https://hub.qgis.org/issues/3438.

Is it possible to have semi-transparent and opaque features within the 
same layer ?


Best regards,

Benoît

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
https://www.avast.com/antivirus

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

Re: [Qgis-user] Maps generation with Python (or Atlas ?)

2015-05-20 Thread Benoît Laurent

*Sorry, I left a mistake in my code:

The comment must be removed for this line:
#for g in range(0,nbGroups-1):

This line must be removed of course:
for g in range(0,2):

Benoît
*


---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
http://www.avast.com
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Maps generation with Python (or Atlas ?)

2015-05-20 Thread Benoît Laurent



Le 20/05/2015 15:55, Bernd Vogelgesang a écrit :

Hi Benoît,

would you mind sharing your hole script as reference for others?

"As reference"... Hum... It would be very presumptuous of me :-).

I think you touched a common problem which isn't covered with built-in 
functions yet, and not everyone is gifted with profound coding 
abilities in python (like me ;) )

"gifted with profound coding abilities in python". Same comment... :-)

However, I simplified the code a little and translated my comments in 
English. By the way, the picture inclusion does not work. If someone can 
help me on that point, it would be nice. If it helps, here is my code:



*#!/usr/bin/env Python
# encoding: utf-8
"""
Generate pdf maps
Assumptions :
- the QGis project contains a set of groups of 2 
layers, the first one just containting a linear feature, the second 
containing points along the track.

- the last group contains raster layers.

"""
from glob import glob
from os import *
from os.path import splitext

from qgis import core

from qgis.core import (QgsComposition,
   QgsComposerMap,
   QgsComposerLabel,
   QgsComposerScaleBar,
   QgsComposerPicture,
   QgsMapLayer,
   QgsRectangle,
QgsComposerArrow,
   QGis)


from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *

import os
import sys
import re
import time

def run_script(iface):
## Generator
genCartes = GenCartes(iface)


## Generates the maps
genCartes.generer()


class GenCartes:
"""
***
Constructeur
***
"""
def __init__(self, iface):
### Initialization using qgis.utils.iface
self.iface = iface

# Attribute of the class
self.composerMap = None

"""Compute an extent of geometry, with given margin (in %)
to be able to show it in the selected map item
Deal with non-square geometries to keep same ratio"""
def getNewExtent(self, geom, margin = None):
# compute coordinates and ratio
new_extent = None
x1, y1, x2, y2 = (0, 0, 0, 0)
geom_rect = geom
geom_ratio = geom_rect.width() / geom_rect.height()
xa1 = geom_rect.xMinimum()
xa2 = geom_rect.xMaximum()
ya1 = geom_rect.yMinimum()
ya2 = geom_rect.yMaximum()

map_rect = self.composerMap.boundingRect()
map_ratio = map_rect.width() / map_rect.height()
# geometry height is too big
if geom_ratio < map_ratio:
y1 = ya1
y2 = ya2
x1 = (xa1 + xa2 + map_ratio * (ya1 - ya2)) / 2.0
x2 = x1 + map_ratio * (ya2 - ya1)
new_extent = core.QgsRectangle(x1, y1, x2, y2)
# geometry width is too big
elif geom_ratio > map_ratio:
x1 = xa1
x2 = xa2
y1 = (ya1 + ya2 + (xa1 - xa2) / map_ratio) / 2.0
y2 = y1 + (xa2 - xa1) / map_ratio
new_extent = core.QgsRectangle(x1, y1, x2, y2)
# same ratio: send geom bounding box
else:
new_extent = geom_rect
# add margin to computed extent
if margin:
new_extent.scale(1 + margin / 100.0)

return new_extent

"""
***
Generate the maps
***
"""
def generer(self):
## Makes the vector layer transparent except raster layers
## Hide labels
layers = self.iface.legendInterface().layers()
for layer in layers:
if layer.type() <> QgsMapLayer.RasterLayer:
layer.rendererV2().symbol().setAlpha(0.3)
layer.setCustomProperty("labeling/enabled", "False")


## Creation of QgsComposition
mapRenderer = self.iface.mapCanvas().mapRenderer()
c = QgsComposition(mapRenderer)

## Format of the maps
c.setPaperSize(420, 297)

Re: [Qgis-user] Maps generation with Python (or Atlas ?)

2015-05-20 Thread Benoît Laurent
I eventually managed to solve my problem. In case somebody encounters 
the same or a similar one, I provide my solution: I used a Python script 
iterating over the groups. Apparently, it is not possible (or I failed) 
to refresh the mapCanvas during the Python script.


Instead of using |"legend.setLayerVisible(layer,True)", I played with 
symbols:


layers[2*g].rendererV2().symbol().setWidth(2)
layers[2*g].rendererV2().symbol().setAlpha(1)

There were others problems in my code but the main difficulty lied 
there. Symbols can be updated during Python scripts and it perfectly 
meets my needs.


Regards,

Benoît
|


---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
http://www.avast.com
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user

[Qgis-user] Entering atlas generator process via a python script ?

2015-05-19 Thread Benoît Laurent

Hello,

This question is bound to my previous one. For the moment, I am not able 
to generate my maps as I wish neither using atlas generator nor using a 
Python script.


Is it possible to enter the atlas generator rendering process via a 
python script ? I noticed some methods like 
QgsAtlasComposition::prepareForFeature( i )... Has somebody made 
something like that ?


Regards,

Benoît

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
http://www.avast.com

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

Re: [Qgis-user] Maps generation with Python (or Atlas ?)

2015-05-18 Thread Benoît Laurent


Thank you for your help.


Hi,

2015-05-18 17:51 GMT+02:00 Benoît Laurent <mailto:blaur...@heurisis.eu>>:


Hello,

I would like to generate a series of maps representing tracks with
stops along them.

For each track, I have got a group of two layers, one for the
linear, one for the points that have associated information
(basically name and time of the stops). First, is there a better
way to achieve this ? For the moment, I have to handle two types
of layer. It is the beginning of my problems.

As the tracks overlap, I would like to generate a map for each
track where only the current selected track appears. The others
would be hidden.

I had a try with Atlas generation. It perfectly works except that
I can't hide the other tracks.

You can style your coverage layer so that only atlas current feature 
will appear. In categorized style, use an expression like 
$id=$atlasfeatureid. You'll get 0 (false) and 1 (true) when classing. 
Set the 0 features style so that they become invisible or transparent.
It is a little better : with your help, I can highlight the current 
linear layer. Actually, I aggregated all my linear layers to constitute 
the coverage layer. However, I can't hide the points layers.




I also had a try with a Python script. I managed to iterate over
the groups of layers but I can't refresh the map canvas during the
Python script. So, it doesn't work.

A snippet of your code may help but I remember I had to face such a 
problem and it was because after *myatlas.beginRender()*, I forgot to 
set active the export of the atlas, sthg like 
*mycomposition.setAtlasMode(QgsComposition.ExportAtlas)*


Actually, I did not use the Atlas generator (maybe a mistake ?). I 
wanted to reproduce/modify its behavior. Here is a piece of code 
(remember that for each track, there is linear layer and a points layer) :


| # Iterate over groups of pair of layers
for  gin  range(0,nbGroups-1):

# Display layers of the current group
layer=  layers[2*g]
rectTrajet=  layer.extent() 
legend.setLayerVisible(layer,  True)

layer=  layers[2*g+1]
rectPtsArr=  layer.extent()
legend.setLayerVisible(layer,  True) 


# extent area
rectGlb=  QgsRectangle
xMin=  min(rectTrajet.xMinimum(),  rectPtsArr.xMinimum())
xMax=  max(rectTrajet.xMaximum(),  rectPtsArr.xMaximum())
yMin=  min(rectTrajet.yMinimum(),  rectPtsArr.yMinimum())
yMax=  max(rectTrajet.yMaximum(),  rectPtsArr.yMaximum())
rectGlb=  QgsRectangle(xMin,  yMin,  xMax,  yMax)
self.iface.mapCanvas().setExtent(rectGlb)

self.iface.mapCanvas().zoomToSelected()
self.iface.mapCanvas().updateScale()
self.iface.mapCanvas().zoomByFactor(1.5)

# Nothing works here !!
self.iface.mapCanvas().updateOverview()
self.iface.mapCanvas().refresh()
layers[2*g].triggerRepaint()
layers[2*g+1].triggerRepaint()


# Map composer
composerMap=  QgsComposerMap(c,x,y,w,h)
composerMap.setPreviewMode(QgsComposerMap.Render)
composerMap.updateBoundingRect()
composerMap.renderModeUpdateCachedImage()
composerMap.setFrameEnabled(True)
c.addItem(composerMap)


# Launch printing
printer=  QtGui.QPrinter()
printer.setOutputFormat(QtGui.QPrinter.PdfFormat)
printer.setOutputFileName(nomFichier)
printer.setPaperSize(QSizeF(c.paperWidth(),  c.paperHeight()),  
QtGui.QPrinter.Millimeter)
printer.setFullPage(True)
printer.setColorMode(QtGui.QPrinter.Color)
printer.setResolution(c.printResolution())

pdfPainter=  QPainter(printer)
paperRectMM=  printer.pageRect(QtGui.QPrinter.Millimeter)
paperRectPixel=  printer.pageRect(QtGui.QPrinter.DevicePixel)
c.render(pdfPainter,  paperRectPixel,  paperRectMM)
pdfPainter.end()

# Remove map composer
c.removeItem(composerMap)

# Hide layers of the current group
legend.setLayerVisible(layers[2*g],  False)
legend.setLayerVisible(layers[2*g+1],  False)

 |




---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
http://www.avast.com
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user

[Qgis-user] Maps generation with Python (or Atlas ?)

2015-05-18 Thread Benoît Laurent

Hello,

I would like to generate a series of maps representing tracks with stops 
along them.


For each track, I have got a group of two layers, one for the linear, 
one for the points that have associated information (basically name and 
time of the stops). First, is there a better way to achieve this ? For 
the moment, I have to handle two types of layer. It is the beginning of 
my problems.


As the tracks overlap, I would like to generate a map for each track 
where only the current selected track appears. The others would be hidden.


I had a try with Atlas generation. It perfectly works except that I 
can't hide the other tracks.


I also had a try with a Python script. I managed to iterate over the 
groups of layers but I can't refresh the map canvas during the Python 
script. So, it doesn't work.


Do others faced a similar problem ? Any help would be appreciated.

Regards,

Benoît



---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
http://www.avast.com

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