#!/usr/bin/python3
# -*- coding: cp1251 -*-
import axioma.gui
import axioma.render
import axioma.app
import axioma.core
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
txtuch = axioma.render.TextRenderer()
fontuch = QFont("Arial")
fontuch.setPointSize(9)
txtuch.setFont(fontuch)
txtuch.setColor(Qt.red)
layer0 = axioma.app.render.createLayerForDataObject(tuchr)
properties0 = layer0.featureLayerProperties()
properties0.setTextRenderer(txtuch)
properties0.setShowLabels(True)
properties0.setLabelingAttributeName("NAME")
layer1 = axioma.app.render.createLayerForDataObject(tuchl)
txtop = axioma.render.TextRenderer()
fontop = QFont("Arial")
fontop.setPointSize(7)
txtop.setFont(fontop)
txtop.setColor(Qt.black)
layer2 = axioma.app.render.createLayerForDataObject(toldp)
properties2 = layer2.featureLayerProperties()
properties2.setTextRenderer(txtop)
properties2.setShowLabels(True)
properties2.setLabelingAttributeName("NAME")
txtnp = axioma.render.TextRenderer()
fontnp = QFont("Arial")
fontnp.setPointSize(7)
txtnp.setFont(fontnp)
txtnp.setColor(Qt.red)
layer3 = axioma.app.render.createLayerForDataObject(tnewp)
properties3 = layer3.featureLayerProperties()
properties3.setTextRenderer(txtnp)
properties3.setShowLabels(True)
properties3.setLabelingAttributeName("NAME")
imRect = QRect(0, 0, 473, 302)
image = QImage(imRect.size(), QImage.Format_ARGB32_Premultiplied)
image.fill(Qt.white)
painter = QPainter(image)
map = axioma.render.Map([layer0,layer1,layer2,layer3])
renderer = axioma.render.ConcurrentMapRenderer()
mapView = axioma.app.mainWindow.createMapView(map)
mapView.parentWidget().resize(QSize(473,302))
mapView.parentWidget().setWindowTitle("Схема расположения Тюмень А4")
cs = tuchl.coordSystem()
viewport = axioma.render.MapViewport(QRectF(mapView.rect()), QRectF(15797, 12659, 828, 420), cs)
mapView.setViewport(viewport)
mapWidth = (mapView.width() / mapView.logicalDpiX() / 39.3701)
mapZoom = viewport.zoom(cs.unit())
mapScale = mapZoom / mapWidth
scales = [100, 200, 250, 500, 1000, 2000, 2500, 5000, 10000, 15000, 25000, 50000, 100000, 200000, 500000, 1000000]
for scale in scales:
    if scale > mapScale:
        mapScale = scale
        viewport.setZoom(scale * mapWidth)
        mapView.setViewport(viewport)
        break
container = mapView.map().labelContainer()
lp = properties0.labelProperties()
lp.layout.alignment = axioma.render.LabelLayout.BottomLeft
properties0.setLabelProperties(lp)
for feature in tuchr.allFeatures():
    lp.layout.alignment = axioma.render.LabelLayout.BottomLeft
    lp.position = Point(mapView.viewport().coordSystem(), 0, 0)
    lp.callout.setEndType(axioma.render.LabelCallout.Line)
    feature_id = feature.id()
    container.insert(layer0, feature_id, lp)
lp = properties2.labelProperties()
lp.layout.alignment = axioma.render.LabelLayout.BottomLeft
properties2.setLabelProperties(lp)
for feature in toldp.allFeatures():
    lp.layout.alignment = axioma.render.LabelLayout.BottomLeft
    lp.position = Point(mapView.viewport().coordSystem(), 0, 0)
    lp.callout.setEndType(axioma.render.LabelCallout.Line)
    feature_id = feature.id()
    container.insert(layer2, feature_id, lp)
lp = properties3.labelProperties()
lp.layout.alignment = axioma.render.LabelLayout.BottomLeft
properties3.setLabelProperties(lp)
for feature in tnewp.allFeatures():
    lp.layout.alignment = axioma.render.LabelLayout.BottomLeft
    lp.position = Point(mapView.viewport().coordSystem(), 0, 0)
    lp.callout.setEndType(axioma.render.LabelCallout.Line)
    feature_id = feature.id()
    container.insert(layer3, feature_id, lp)
context = axioma.render.MapContext(painter,viewport)
renderer.blockingRender(mapView.map(), context)
image.save("D:\TestQGIS\Схема расположения Тюмень А4.bmp")
