[Qgis-developer] Rendering a map in QgsComposition on Win 7 / 8
pgierski
pgierski at o2.pl
Sat May 10 13:33:20 PDT 2014
Ok, problem solved.
Your hint with the extent setting put me on a right track.
It turns out that I had a total mess with coordinate reference systems beetween layers and projects. QGIS was reprojecting everything on the fly, but I had to double check everything to get it right in the end.
So after all there is no problem with rendering on Win 7/8, it was just my problems with coordinates.
To solve the issue I had to check every time which crs I have in one layer and convert the extent to destination crs (used in map canvas).
This code does the trick:
map_centroid_point_layer_crs = desired_layer.crs()
destination_crs = mapRenderer.destinationCrs()
xform = QgsCoordinateTransform(map_centroid_point_layer_crs, destination_crs)
map_centroid_point_in_dest_crs = xform.transform(map_centroid_point)
# here is the code for calculating the extent
map_width_on_print_mm = 182
map_height_on_print_mm = 160
map_x_min = map_x - (((map_width_on_print_mm * scale) / 1000.0) / 2.0)
map_x_max = map_x + (((map_width_on_print_mm * scale) / 1000.0) / 2.0)
map_y_min = map_y - (((map_height_on_print_mm * scale) / 1000.0) / 2.0)
map_y_max = map_y + (((map_height_on_print_mm * scale) / 1000.0) / 2.0)
rect = QgsRectangle(map_x_min, map_y_min, map_x_max, map_y_max)
Thank again for your help!
--
Cheers, Przemysław Gierski.
Dnia 8 maja 2014 12:39 Nyall Dawson <nyall.dawson at gmail.com> napisał(a):
> On 8 May 2014 20:23, pgierski <pgierski at o2.pl> wrote:
>
> >
> > composerMap = QgsComposerMap(c,
> > 14.7026,113.85,map_width_on_print_mm,map_height_on_print_mm)
> > composerMap.setFrameEnabled(True)
> > composerMap.setFrameOutlineWidth(0.5)
> > c.addItem(composerMap)
>
> What if you try explicitly setting composerMap's extent here? ie,
> composerMap.setNewExtent(rect)
>
> Nyall
>
More information about the Qgis-developer
mailing list