Dear Nathan,
thank you very much for the link. I have started playing around a bit
with your code. In general it works fine. I removed the cause of an
exception by simply adding:
job.waitForFinished()
in updatebackmap(), since sometimes the job object was not valid in
the updatemap() function.
I have a question regarding the background color of the map overlay
(othermap). I tried to set the background to transparent, but my
attempt failed using this code:
alpha = QColor(255,255,255,0)
settings.setBackgroundColor(alpha)
So my question is:
Is my approach wrong or is transparency not support by QgsMapSettings?
I have attached you code including my tiny changes.
Best regards
Soeren
2014-10-06 15:03 GMT+02:00 Nathan Woodrow <[email protected]>:
> Hey Soeren,
>
> The code that I was playing with is here.
> https://gist.github.com/NathanW2/dc1b665cbce627ce0350#file-sipe-py
>
> hopefully I will find some time soon to build the plugin correctly.
>
> - Nathan
>
> On Sun, Oct 5, 2014 at 8:37 PM, Sören Gebbert <[email protected]>
> wrote:
>>
>> Dear Nathan,
>> have you found some time to work on the map swipe QGIS plugin?
>> I would be happy to help developing the plugin or testing it, if you like?
>> Do you have a public source code repository, so that i can start to
>> study your code?
>>
>>
>> Best regards
>> Soeren
>>
>> 2014-07-31 11:28 GMT+02:00 Nathan Woodrow <[email protected]>:
>> > Hey Soeren,
>> >
>> > Nothing yet. I might have some time next week for the plugin.
>> >
>> > - Nathan
>> >
>> >
>> > On Thu, Jul 31, 2014 at 7:26 PM, Sören Gebbert
>> > <[email protected]> wrote:
>> >>
>> >> Hi Nathan,
>> >> that is exactly what i am looking for. Do you have any release date or
>> >> is the plugin already available?
>> >>
>> >> Many thanks and best regards
>> >> Soeren
>> >>
>> >> 2014-07-31 10:37 GMT+02:00 Nathan Woodrow <[email protected]>:
>> >> > No something like this
>> >> >
>> >> > https://twitter.com/madmanwoo/status/478866023345426433
>> >> >
>> >> > On Jul 31, 2014 6:32 PM, "Paolo Cavallini" <[email protected]>
>> >> > wrote:
>> >> >>
>> >> >> On 2014-07-31 10:16, Sören Gebbert wrote:
>> >> >>>
>> >> >>> Dear list,
>> >> >>> i would like to know if it is possible to implement a plugin in
>> >> >>> QGIS
>> >> >>> to overlay two map layer for interactive comparison, like the Map
>> >> >>> Swipe tool in GRASS GIS[1,2].
>> >> >>>
>> >> >>> If it is possible, what would be the best approach to implement it?
>> >> >>
>> >> >>
>> >> >> Hi.
>> >> >> You mean this?
>> >> >> http://plugins.qgis.org/plugins/DockableMirrorMap/
>> >> >> All the best.
>> >> >> --
>> >> >> Paolo Cavallini - Faunalia
>> >> >> www.faunalia.eu
>> >> >> Full contact details at www.faunalia.eu/pc
>> >> >> Nuovi corsi QGIS e PostGIS: http://www.faunalia.it/calendario
>> >> >> _______________________________________________
>> >> >> Qgis-developer mailing list
>> >> >> [email protected]
>> >> >> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > Qgis-developer mailing list
>> >> > [email protected]
>> >> > http://lists.osgeo.org/mailman/listinfo/qgis-developer
>> >
>> >
>
>
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.gui import *
class SwipeMap(QgsMapCanvasMap):
def __init__(self, canvas):
super(SwipeMap, self).__init__(canvas)
self.width = 0
self.height = self.boundingRect().height() - 2
self.setZValue(-9.0)
self.image = QImage()
def setContent(self, image, rect):
self.image = image
self.setRect(rect)
def setWidth(self, width):
self.width = width
self.update()
def setHeight(self, height):
self.height = height
self.update()
def paint(self, painter, *args):
w = self.width
h = self.height
image = self.image.copy(0,0, self.width, h)
painter.drawImage(QRect(0,0,w,h), image )
painter.drawRect(0,0,w,h)
map = iface.mapCanvas().map()
othermap = SwipeMap(iface.mapCanvas())
legend = iface.legendInterface()
def updatebackmap():
def updatemap():
othermap.setContent(job.renderedImage(), settings.extent())
groups = legend.groupLayerRelationship()
slidergroup = [layers for group, layers in groups if group == 'Slider'][0]
settings = QgsMapSettings(iface.mapCanvas().mapSettings())
print settings.layers()
print settings.scale()
settings.setLayers(slidergroup)
alpha = QColor(255,255,255,0)
settings.setBackgroundColor(alpha)
print "Settings valid?: ", settings.hasValidSettings()
job = QgsMapRendererParallelJob(settings)
job.finished.connect(updatemap)
job.start()
job.waitForFinished()
def width_value(i):
w = (i * iface.mapCanvas().map().boundingRect().width()) / 1000
othermap.setWidth(w)
def height_value(i):
h = (i * iface.mapCanvas().map().boundingRect().height()) / 1000
othermap.setHeight(h)
iface.mapCanvas().mapCanvasRefreshed.connect(updatebackmap)
#iface.mapCanvas().renderStarting.connect(updatebackmap)
slider1 = QSlider(1)
slider1.setTickInterval(1)
slider1.setRange(0,1000)
slider1.show()
slider1.valueChanged.connect(width_value)
slider2 = QSlider(1)
slider2.setTickInterval(1)
slider2.setRange(0,1000)
slider2.show()
slider2.valueChanged.connect(height_value)_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer