From 28570c836e4157d9075942b3cff44b5a95a1aae5 Mon Sep 17 00:00:00 2001 From: Marco Bernasocchi Date: Tue, 29 Sep 2015 18:57:01 +0200 Subject: [PATCH] fixing many PEP8 issues --- gearthview.py | 3454 +++++++++++++++++++++++++------------------------ 1 file changed, 1797 insertions(+), 1657 deletions(-) diff --git a/gearthview.py b/gearthview.py index d021bf4..3f4920c 100644 --- a/gearthview.py +++ b/gearthview.py @@ -31,30 +31,29 @@ ***************************************************************************/ """ # Import the PyQt and QGIS libraries -from PyQt4.QtCore import * -from PyQt4.QtGui import * from qgis.core import * from qgis.gui import * import qgis - -import sys, itertools, os, glob, subprocess, zipfile, zlib, tempfile +import os +import glob import platform - -from math import * import datetime -import time import codecs +from PyQt4.QtCore import * +from PyQt4.QtGui import * + -#from http.server import HTTPServer, CGIHTTPRequestHandler -#import BaseHTTPServer, CGIHTTPServer + +# from http.server import HTTPServer, CGIHTTPRequestHandler + +# import BaseHTTPServer, CGIHTTPServer # https://pypi.python.org/pypi/qrcode -#import qrcode +# import qrcode # Initialize Qt resources from file resources.py -import resources_rc # Import the code for the dialog from gearthviewdialog import gearthviewDialog @@ -64,9 +63,10 @@ from osgeo import gdalconst -### important +# important from twisted.internet.error import ReactorAlreadyInstalledError import qtreactor.qt4reactor as reactor + try: reactor.install() except ReactorAlreadyInstalledError: @@ -76,1569 +76,1693 @@ except: raise -## INSTALL qt4reactor before importing the twisted stuff +# INSTALL qt4reactor before importing the twisted stuff from twisted.internet import reactor -from twisted.web import server +from twisted.web import server ### # ---------------------------------------------------- def startGeoDrink_Server(self): - - global serverStarted + global serverStarted + + webServerDir = unicode(QFileInfo( + QgsApplication.qgisUserDbFilePath()).path()) + \ + "/python/plugins/gearthview/_WebServer/" + port = 5558 + + from twisted.web.resource import Resource + + # from twisted.web.twcgi import CGIScript + + # resource = CGIScript(webServerDir) + + # if platform.system() == "Windows": + # os.startfile(webServerDir + 'QGIS_link.kmz') + + # if platform.system() == "Darwin": + # os.system("open " + str(webServerDir + + # 'QGIS_link.kmz')) + + # if platform.system() == "Linux": + # os.system("xdg-open " + str(webServerDir + + # 'QGIS_link.kmz')) + + GDX_Publisher(self) + + if (serverStarted == 0): + + serverStarted = 1 + + print ("Start GDX_Server Start --------!!!\n") + + # --------------------------------------------- + class FormPage(Resource): + def __init__(self, iface, pluginDir): + self.iface = iface + self.pluginDir = pluginDir + + def render_GET(self, request): + + global lat, lon + global Zeta + global description + + # ------ newdata = + # request.content.getvalue() + + # print request + + # + # + # + # + # + # + + # + # BBOX=[bboxWest],[bboxSouth],[bboxEast], + # [bboxNorth]; + # LookatTerrain=[lookatTerrainLon], + # [lookatTerrainLat],[lookatTerrainAlt]; + # terrain=[terrainEnabled]; + # CAMERA=[lookatLon],[lookatLat],[lookatRange], + # [lookatTilt],[lookatHeading]; + # VIEW=[horizFov],[vertFov],[horizPixels], + # [vertPixels] + # + + stringa = str(request) + stringa = stringa.replace('', '') + params = stringa.split('&') + + param0 = params[0].replace('p=', '') + pony = param0 + + param1 = params[1].replace('BBOX=', '') + + bbox = param1.split(',') + + param2 = params[2].replace('LookatTerrain=', '') + LookatTerrain = param2.split(',') + + param3 = params[3].replace('terrain=', '') + param4 = params[4].replace('CAMERA=', '') + param5 = params[5].replace('VIEW=', '') + + CAMERA = param4.split(',') + + lookatLon = float(CAMERA[0]) + lookatLat = float(CAMERA[1]) + lookatRange = float(CAMERA[2]) + lookatTilt = float(CAMERA[3]) + lookatHeading = float(CAMERA[4]) + + # print("lookatLon %f") %(lookatLon) + # print("lookatLat %f") %(lookatLat) + # print("lookatRange %f") %( + # lookatRange) + # print("lookatTilt %f") %( + # lookatTilt) + # print("lookatHeading %f") %( + # lookatHeading) + - webServerDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()) + "/python/plugins/gearthview/_WebServer/" - port = 5558 + west = float(bbox[0]) + south = float(bbox[1]) + east = float(bbox[2]) + north = float(bbox[3]) - from twisted.web.resource import Resource + lon = float(LookatTerrain[0]) + lat = float(LookatTerrain[1]) + Zeta = float(LookatTerrain[2]) -# from twisted.web.twcgi import CGIScript - -# resource = CGIScript(webServerDir) - -# if platform.system() == "Windows": -# os.startfile(webServerDir + 'QGIS_link.kmz') - -# if platform.system() == "Darwin": -# os.system("open " + str(webServerDir + 'QGIS_link.kmz')) - -# if platform.system() == "Linux": -# os.system("xdg-open " + str(webServerDir + 'QGIS_link.kmz')) - - GDX_Publisher(self) - - if ( serverStarted == 0) : - - serverStarted = 1 - - print ("Start GDX_Server Start --------!!!\n") - -# --------------------------------------------- - class FormPage(Resource): - def __init__(self, iface, pluginDir): - self.iface = iface - self.pluginDir = pluginDir - - - def render_GET(self, request): - - global lat,lon - global Zeta - global description - -#------ newdata = request.content.getvalue() -# print request - -# -# -# -# -# -# - -# -# BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]; -# LookatTerrain=[lookatTerrainLon],[lookatTerrainLat],[lookatTerrainAlt]; -# terrain=[terrainEnabled]; -# CAMERA=[lookatLon],[lookatLat],[lookatRange],[lookatTilt],[lookatHeading]; -# VIEW=[horizFov],[vertFov],[horizPixels],[vertPixels] -# - - stringa = str(request) - stringa = stringa.replace('','') - params = stringa.split('&') - - param0 = params[0].replace('p=','') - pony = param0 - - param1 = params[1].replace('BBOX=','') - - bbox = param1.split(',') - - param2 = params[2].replace('LookatTerrain=','') - LookatTerrain = param2.split(',') - - param3 = params[3].replace('terrain=','') - param4 = params[4].replace('CAMERA=','') - param5 = params[5].replace('VIEW=','') - - CAMERA = param4.split(',') - - lookatLon = float(CAMERA[0]) - lookatLat = float(CAMERA[1]) - lookatRange = float(CAMERA[2]) - lookatTilt = float(CAMERA[3]) - lookatHeading = float(CAMERA[4]) - -# print("lookatLon %f") %(lookatLon) -# print("lookatLat %f") %(lookatLat) -# print("lookatRange %f") %(lookatRange) -# print("lookatTilt %f") %(lookatTilt) -# print("lookatHeading %f") %(lookatHeading) - - west = float(bbox[0]) - south = float(bbox[1]) - east = float(bbox[2]) - north = float(bbox[3]) - - lon = float(LookatTerrain[0]) - lat = float(LookatTerrain[1]) - Zeta = float(LookatTerrain[2]) - -# print ("Zeta = %f") %(Zeta) - - msg = ("LonLatH = %s, %s elev = %s m alt = %s m") %(lon,lat,Zeta, lookatRange) - self.iface.mainWindow().statusBar().showMessage(msg) - -# lon = ((east - west) / 2) + west -# lat = ((north - south) / 2) + south - - kml = ( - - '\n' - '\n') - - - if(pony != '0'): - kml = kml + ( - ' \n' - ' Z=%s\n') %(Zeta) - - kml = kml + ( - ' \n' - ' \n') - - qrCodeUrl = ("http://qrcode.kaywa.com/img.php?s=8&d=%.14f,%.14f,%.2f") %(lat,lon,Zeta) - - descript = ('lat long H

%.14f,%.14f,%.2f

CODE ') %(lat,lon,Zeta) - qrCodeImg = ('') %(qrCodeUrl) - - description = descript + qrCodeImg - - kml = kml + ('\n') - - kml = kml + (' \n') - - kml = kml + ( - ' \n' - ' %.14f,%.14f\n' - ' \n' - ' \n') %( lon, lat) + # print ("Zeta = %f") %(Zeta) + + msg = ("LonLatH = %s, %s elev = %s m alt = %s m") % ( + lon, lat, Zeta, lookatRange) + self.iface.mainWindow().statusBar().showMessage(msg) + + # lon = ((east - west) / 2) + west + # lat = ((north - south) / 2) + south + + kml = ( + + '\n' + '\n') + + if (pony != '0'): + kml = kml + ( + ' \n' + ' Z=%s\n') % (Zeta) + + kml = kml + ( + ' \n' + ' \n') + + qrCodeUrl = ( + "http://qrcode.kaywa.com/img.php?s=8&d=%.14f,%.14f,%.2f") % ( + lat, lon, Zeta) + + descript = ( + 'lat long H

%.14f,%.14f,' + '%.2f

CODE ') % ( + lat, lon, Zeta) + qrCodeImg = ('') % ( + qrCodeUrl) + + description = descript + qrCodeImg + + kml = kml + ('\n') + + kml = kml + (' \n') + + kml = kml + ( + ' \n' + ' %.14f,' + '%.14f\n' + ' \n' + ' \n') % (lon, lat) + + + # Tag close KML ---- + # kml = kml + ('') + + canvas = self.iface.mapCanvas() + mapRenderer = canvas.mapRenderer() + srs = mapRenderer.destinationCrs() + + crsSrc = QgsCoordinateReferenceSystem(4326) + crsDest = QgsCoordinateReferenceSystem(srs) + xform = QgsCoordinateTransform(crsSrc, crsDest) + + GEraggio = (lookatRange - Zeta) / 2. + + raggio = GEraggio - - # Tag close KML ---- -# kml = kml + ('') - - - - canvas = self.iface.mapCanvas() - mapRenderer = canvas.mapRenderer() - srs = mapRenderer.destinationCrs() - - crsSrc = QgsCoordinateReferenceSystem(4326) - crsDest = QgsCoordinateReferenceSystem(srs) - xform = QgsCoordinateTransform(crsSrc, crsDest) - - - GEraggio = (lookatRange - Zeta) / 2. - - raggio = GEraggio - - # Calculate QgisViewBox from 3D geoCoords - -# print ("raggio = %f") %(raggio) - - ilMetroGeo = 0.000011922282515 - raggioGeo = raggio * ilMetroGeo + # print ("raggio = %f") %(raggio) - x1Geo = lon - float(raggioGeo) - y1Geo = lat - float(raggioGeo) - x2Geo = lon + float(raggioGeo) - y2Geo = lat + float(raggioGeo) + ilMetroGeo = 0.000011922282515 - pt1 = xform.transform(QgsPoint(x1Geo, y1Geo)) - pt2 = xform.transform(QgsPoint(x2Geo, y2Geo)) + raggioGeo = raggio * ilMetroGeo - x1 = pt1.x() - y1 = pt1.y() - x2 = pt2.x() - y2 = pt2.y() + x1Geo = lon - float(raggioGeo) + y1Geo = lat - float(raggioGeo) + x2Geo = lon + float(raggioGeo) + y2Geo = lat + float(raggioGeo) + pt1 = xform.transform(QgsPoint(x1Geo, y1Geo)) + pt2 = xform.transform(QgsPoint(x2Geo, y2Geo)) - box = QgsRectangle(x1, y1, x2, y2) + x1 = pt1.x() + y1 = pt1.y() + x2 = pt2.x() + y2 = pt2.y() - - canvas = self.iface.mapCanvas() - - canvas.setExtent(box) + box = QgsRectangle(x1, y1, x2, y2) - if QGis.QGIS_VERSION_INT >= 20801: - canvas.setRotation(-lookatHeading) + canvas = self.iface.mapCanvas() + canvas.setExtent(box) - canvas.refresh() - + if QGis.QGIS_VERSION_INT >= 20801: + canvas.setRotation(-lookatHeading) - if(pony == '2'): - QGEarth_addPoint(self) + canvas.refresh() - -# print 'Content-Type: application/vnd.google-earth.kml+xml\n' + if (pony == '2'): + QGEarth_addPoint(self) -# kml_2 = GDX_Publisher2(self) -# kml = kml + kml_2 - - kml = kml + ('') - - return kml - + # print 'Content-Type: + # application/vnd.google-earth.kml+xml\n' + # kml_2 = GDX_Publisher2(self) + # kml = kml + kml_2 - def render_POST(self, request): - print request.__dict__ - newdata = request.content.getvalue() - print newdata, type(newdata) -# QtGui.QMessageBox.information(self.iface.mainWindow(), "GEarthViewServer", u"recieved something.\n{}".format(newdata)) + kml = kml + ('') - if newdata['bbox']: - self.iface.mapCanvas().setExtent(QgsRectangle(newdata['bbox']['xmin'], newdata['bbox']['ymin'], newdata['bbox']['xmax'], newdata['bbox']['ymax'])) - else: - self.iface.mapCanvas().zoomToFullExtent() - - return '' + return kml - root = Resource() - root.putChild("form", FormPage(self.iface, self.plugin_dir)) + def render_POST(self, request): + print request.__dict__ + newdata = request.content.getvalue() + print newdata, type(newdata) + # QtGui.QMessageBox.information( + # self.iface.mainWindow(), "GEarthViewServer", u"recieved + # something.\n{}".format(newdata)) - reactor.listenTCP(5558, server.Site(root)) - reactor.run() + if newdata['bbox']: + self.iface.mapCanvas().setExtent( + QgsRectangle(newdata['bbox']['xmin'], + newdata['bbox']['ymin'], + newdata['bbox']['xmax'], + newdata['bbox']['ymax'])) + else: + self.iface.mapCanvas().zoomToFullExtent() + return '' + root = Resource() + root.putChild("form", FormPage(self.iface, self.plugin_dir)) -#------------------------------------------------------------------------------ -# Add the current GEarth point in QGis current drawing function ------------------------------------------ + reactor.listenTCP(5558, server.Site(root)) + reactor.run() + + +# ------------------------------------------------------------------------------ +# Add the current GEarth point in QGis current drawing function +# ------------------------------------------ def QGEarth_addPoint(self): + if (serverStarted == 0): + # QMessageBox.critical(self.iface.mainWindow(), + # "You need to startQrCoding, before !!!", "") + self.iface.messageBar().pushMessage("WARNING", + "You need to startQrCoding, " + "before !!!", + level=QgsMessageBar.WARNING, + duration=3) + print ("You need to startQrCoding, before !!!\n") + return + + global lat, lon + global Zeta + global description + + # print ("QGEarth %f %f") %(lat, lon) + + canvas = self.iface.mapCanvas() + layer = canvas.currentLayer() + + if layer: + if layer.type() == layer.VectorLayer: + + provider = layer.dataProvider() + Edit = layer.isEditable() + + if (Edit == 0): + # QMessageBox.critical( + # self.iface.mainWindow(), "WARNING: Layer not editable", + # str(layer.name())) + self.iface.messageBar().pushMessage("WARNING", + "Layer not editable", + level=QgsMessageBar.WARNING, + duration=3) + + return + + srs = layer.crs(); + crsSrc = QgsCoordinateReferenceSystem(4326) + crsDest = QgsCoordinateReferenceSystem(srs) + xform = QgsCoordinateTransform(crsSrc, crsDest) + pt = xform.transform(QgsPoint(lon, lat)) + + gPnt = QgsGeometry.fromPoint(QgsPoint(pt.x(), pt.y())) + + # print ("QGEarth %f %f %f %f") %(lat, lon, + # pt.x(), pt.y()) + + feature = QgsFeature() + feature.setGeometry(gPnt) + + # print ("description = <%s>") %(description) + + feature.initAttributes(5) + + adesso = str(datetime.datetime.now()) + adesso = adesso.replace(" ", "_") + adesso = adesso.replace(":", "_") + adesso = adesso.replace(".", "_") + + res = provider.addAttributes([QgsField("name", QVariant.String), + QgsField("description", + QVariant.String), + QgsField("DateTime", + QVariant.String), + QgsField("lat", QVariant.String), + QgsField("lon", QVariant.String), + QgsField("Height", QVariant.String)]) + + print feature.id() + name = ("%s,%s,%s") % (lat, lon, Zeta) + + values = [(name), (description), adesso, lat, lon, Zeta] + + feature.setAttributes(values) + + provider.addFeatures([feature]) + + layer.updateFields() + + layer.updateExtents() + + # layer.commitChanges() + + canvas.refresh() + + else: + + self.iface.messageBar().pushMessage("WARNING", + "Creating a Point Layer...", + level=QgsMessageBar.WARNING, + duration=3) + + geomType = "Point" + '?crs=proj4:' + \ + QgsProject.instance().readEntry("SpatialRefSys", + "/ProjectCRSProj4String")[0] + DronePlan = "GEarthView_Points" + memLay = QgsVectorLayer(geomType, DronePlan, 'memory') + provider = memLay.dataProvider() + + memLay.updateExtents() + memLay.commitChanges() + QgsMapLayerRegistry.instance().addMapLayer(memLay) + + # GDX_Publisher -------------------------------------- - if ( serverStarted == 0) : -# QMessageBox.critical(self.iface.mainWindow(), "You need to startQrCoding, before !!!", "") - self.iface.messageBar().pushMessage("WARNING", "You need to startQrCoding, before !!!", level=QgsMessageBar.WARNING, duration=3) - print ("You need to startQrCoding, before !!!\n") - return - - global lat, lon - global Zeta - global description - -# print ("QGEarth %f %f") %(lat, lon) - - canvas = self.iface.mapCanvas() - layer = canvas.currentLayer() - - if layer: - if layer.type() == layer.VectorLayer: - - provider = layer.dataProvider() - Edit = layer.isEditable() - - if ( Edit == 0 ): -# QMessageBox.critical(self.iface.mainWindow(), "WARNING: Layer not editable", str(layer.name())) - self.iface.messageBar().pushMessage("WARNING", "Layer not editable", level=QgsMessageBar.WARNING, duration=3) - - return - - srs = layer.crs(); - crsSrc = QgsCoordinateReferenceSystem(4326) - crsDest = QgsCoordinateReferenceSystem(srs) - xform = QgsCoordinateTransform(crsSrc, crsDest) - pt = xform.transform(QgsPoint(lon, lat)) - - gPnt = QgsGeometry.fromPoint(QgsPoint(pt.x(),pt.y())) - -# print ("QGEarth %f %f %f %f") %(lat, lon, pt.x(), pt.y()) - - feature = QgsFeature() - feature.setGeometry( gPnt ) - -# print ("description = <%s>") %(description) - - feature.initAttributes(5) - - adesso = str(datetime.datetime.now()) - adesso = adesso.replace(" ","_") - adesso = adesso.replace(":","_") - adesso = adesso.replace(".","_") - - res = provider.addAttributes( [ QgsField("name", QVariant.String), QgsField("description", QVariant.String), QgsField("DateTime", QVariant.String),QgsField("lat", QVariant.String), QgsField("lon", QVariant.String), QgsField("Height", QVariant.String)] ) - - print feature.id() - name = ("%s,%s,%s") %(lat, lon, Zeta) - - values = [(name), (description), adesso, lat, lon, Zeta] - - feature.setAttributes(values) - - provider.addFeatures([feature]) - - layer.updateFields() - - layer.updateExtents() - -# layer.commitChanges() - - canvas.refresh() - - else: - - self.iface.messageBar().pushMessage("WARNING", "Creating a Point Layer...", level=QgsMessageBar.WARNING, duration=3) - - geomType = "Point" + '?crs=proj4:' + QgsProject.instance().readEntry("SpatialRefSys","/ProjectCRSProj4String")[0] - DronePlan = "GEarthView_Points" - memLay = QgsVectorLayer(geomType, DronePlan, 'memory') - provider = memLay.dataProvider() - - - memLay.updateExtents() - memLay.commitChanges() - QgsMapLayerRegistry.instance().addMapLayer(memLay) - -# GDX_Publisher -------------------------------------- def GDX_Publisher(self): + mapCanvas = self.iface.mapCanvas() + tempdir = unicode(QFileInfo( + QgsApplication.qgisUserDbFilePath()).path()) + \ + "/python/plugins/gearthview/temp" - mapCanvas = self.iface.mapCanvas() - - tempdir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()) + "/python/plugins/gearthview/temp" + adesso = str(datetime.datetime.now()) + adesso = adesso.replace(" ", "_") + adesso = adesso.replace(":", "_") + adesso = adesso.replace(".", "_") - adesso = str(datetime.datetime.now()) - adesso = adesso.replace(" ","_") - adesso = adesso.replace(":","_") - adesso = adesso.replace(".","_") + # print "adesso: <%s>\n" %(adesso) -# print "adesso: <%s>\n" %(adesso) + # Prendo le coordinate della finestra + # attuale--------------------------------------- + # 13.5702225179249876,41.2134192420407501 : 13.5768356834183166, + # 41.2182110366311107 + text = mapCanvas.extent().toString() + text1 = text.replace(",", " ") + text2 = text1.replace(" : ", ",") + # the_filter = "bbox($geometry, geomFromWKT ( 'LINESTRING(" + # + text2 + ")'))" + # self.doPaste(the_filter) -# Prendo le coordinate della finestra attuale--------------------------------------- -# 13.5702225179249876,41.2134192420407501 : 13.5768356834183166,41.2182110366311107 - text = mapCanvas.extent().toString() - text1 = text.replace("," , " ") - text2 = text1.replace(" : ", ",") -# the_filter = "bbox($geometry, geomFromWKT ( 'LINESTRING(" + text2 + ")'))" -# self.doPaste(the_filter) + # HERE IT DELETES THE OLD IMAGE ------------------------------------ + # (if you comment these, images still remain ... :) + for filename in glob.glob(str(tempdir + '/*.png')): + os.remove(str(filename)) + for filename in glob.glob(str(tempdir + '/*.pngw')): + os.remove(str(filename)) + # ------------------------------------------------------------------ -# HERE IT DELETES THE OLD IMAGE ------------------------------------ -# (if you comment these, images still remain ... :) - for filename in glob.glob(str(tempdir + '/*.png')) : - os.remove( str(filename) ) - for filename in glob.glob(str(tempdir + '/*.pngw')) : - os.remove( str(filename) ) -# ------------------------------------------------------------------ + tname = 'ZIPPA' - - tname = 'ZIPPA' - - out_folder = tempdir - - kml = codecs.open(out_folder + '/doc.kml', 'w', encoding='utf-8') -# kml=open(out_folder + '/doc.kml', 'w') - # - - iface = qgis.utils.iface - - if QGis.QGIS_VERSION_INT <= 120200: - - 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 = ("QGisView_%lf_%lf_%s") % (xN, yN, adesso) - - input_file = out_folder + "/" + nomePNG + ".png" - - #Save the image - image.save(input_file, "png") - - else: # ovvero QGis.QGIS_VERSION_INT > 120200 - - - - mapRenderer = mapCanvas.mapRenderer() - mapRect = mapRenderer.extent() - width = mapRenderer.width() - height = mapRenderer.height() - srs = mapRenderer.destinationCrs() - - xN = mapRect.xMinimum() - yN = mapRect.yMinimum() - - mapSettings = QgsMapSettings() - mapSettings.setMapUnits(0) - mapSettings.setExtent(mapRect) - DPI = 300 - mapSettings.setOutputDpi(DPI) - - mapSettings.setOutputSize(QSize(width, height)) - - lst = [] - layerTreeRoot = QgsProject.instance().layerTreeRoot() - for id in layerTreeRoot.findLayerIds(): - node = layerTreeRoot.findLayer(id) - lst.append(id) - - mapSettings.setLayers(lst) - - mapSettings.setFlags(QgsMapSettings.Antialiasing | QgsMapSettings.UseAdvancedEffects | QgsMapSettings.ForceVectorOutput | QgsMapSettings.DrawLabeling) - image = QImage(QSize(width, height), QImage.Format_RGB32) - - image.fill(0) - - image.setDotsPerMeterX(DPI / 25.4 * 1000) - image.setDotsPerMeterY(DPI / 25.4 * 1000) - p = QPainter() - p.begin(image) - mapRenderer = QgsMapRendererCustomPainterJob(mapSettings, p) - mapRenderer.start() - mapRenderer.waitForFinished() - p.end() - - nomePNG = ("QGisView_%lf_%lf_%s") % (xN, yN, adesso) - input_file = out_folder + "/" + nomePNG + ".png" - - #Save the image - image.save(input_file, "png") - - - # EndIf # QGis.QGIS_VERSION_INT > 120200 - - layer = mapCanvas.currentLayer() - crsSrc = srs # QgsCoordinateReferenceSystem(layer.crs()) # prendere quello attuale - crsDest = QgsCoordinateReferenceSystem(4326) # Wgs84LLH - xform = QgsCoordinateTransform(crsSrc, crsDest) - - x1 = mapRect.xMinimum() - y1 = mapRect.yMinimum() - - x2 = mapRect.xMaximum() - y2 = mapRect.yMinimum() - - x3 = mapRect.xMaximum() - y3 = mapRect.yMaximum() - - x4 = mapRect.xMinimum() - y4 = mapRect.yMaximum() - - xc = (x1 + x3) / 2. - yc = (y1 + y3) / 2. - - pt1 = xform.transform(QgsPoint(x1, y1)) - pt2 = xform.transform(QgsPoint(x2, y2)) - pt3 = xform.transform(QgsPoint(x3, y3)) - pt4 = xform.transform(QgsPoint(x4, y4)) - - pt5 = xform.transform(QgsPoint(xc, yc)) - - xc = pt5.x() - yc = pt5.y() - - x1 = pt1.x() - y1 = pt1.y() - - x2 = pt2.x() - y2 = pt2.y() - - x3 = pt3.x() - y3 = pt3.y() - - x4 = pt4.x() - y4 = pt4.y() - - - - #Write kml header - kml.write('\n') - kml.write('\n') - kml.write(' \n') - kml.write(' QGisView\n') - kml.write(' \n') - loc = (" \n") %(yc, xc) - - kml.write(loc) -# - - -# kml.write(' http://map.project-osrm.org/?hl=it&loc=45.989486,12.778154&loc=45.985624,12.781076&z=16¢er=45.984058,12.774417&alt=0&df=0&re=0&ly=-940622518\n') - - kml.write(' 1\n') - - kml.write(' \n') - kml.write(' \n') - kml.write(' \n') - kml.write(' \n') - kml.write(' normal\n') - kml.write(' #sn_ylw-pushpin\n') - kml.write(' \n') - kml.write(' \n') - kml.write(' highlight\n') - kml.write(' #sh_ylw-pushpin\n') - kml.write(' \n') - kml.write(' \n') - - kml.write(' \n') - kml.write(' \n') - kml.write(' \n') - kml.write(' \n') - kml.write(' normal\n') - kml.write(' #default\n') - kml.write(' \n') - kml.write(' \n') - kml.write(' highlight\n') - kml.write(' #hl\n') - kml.write(' \n') - kml.write(' \n') - - - rotazio = 0.0 - if QGis.QGIS_VERSION_INT >= 20801: - rotazio = -(mapCanvas.rotation()) - - - kml.write(' \n') - - xc = (x1 + x3) / 2. - yc = (y1 + y3) / 2. - dx = (x3 - x1) * 75000. #100000. - - - kml.write(' 1\n') - kml.write(' \n') - kml.write(' QGIS_link\n') - kml.write(' 1\n') - kml.write(' 1\n') - kml.write(' \n') - kml.write(' ../_WebServer/QGIS_link.kmz\n') - kml.write(' \n') - kml.write(' \n') - - - kml.write(' \n') - stringazza = (" %lf\n") %(xc) - kml.write(stringazza) - stringazza = (" %lf\n") %(yc) - kml.write(stringazza) - kml.write(' 0\n') - - stringazza = (" %lf\n") %(rotazio) - kml.write(stringazza) - - kml.write(' 0\n') - stringazza = (" %lf\n") %(dx) - kml.write(stringazza) - kml.write(' relativeToGround\n') - kml.write(' \n') - - kml.write(' \n') - kml.write(' QGisView\n') - - kml.write(' \n') - -# nomePNG = ("QGisView_%lf_%lf_%s") % (xN, yN, adesso) - stringazza = (" %s.png\n") % (nomePNG) - kml.write(stringazza) - kml.write(' 1.0\n') - kml.write(' \n') - kml.write(' \n') - kml.write(' \n') - - stringazza = ("%.9lf,%.9lf,0 %.9lf,%.9lf,0 %.9lf,%.9lf,0 %.9lf,%.9lf,0\n") % (x1, y1, x2, y2, x3, y3, x4, y4) - kml.write(stringazza) - - kml.write(' \n') - kml.write(' \n') - kml.write(' \n') - -# #Write kml footer -# kml.write('\n') -# #Close kml file -# kml.close() - - - - #Export tfw-file - xScale = (mapRect.xMaximum() - mapRect.xMinimum()) / image.width() - yScale = (mapRect.yMaximum() - mapRect.yMinimum()) / image.height() - - - f = open(out_folder + "/" + nomePNG + ".pngw", 'w') - f.write(str(xScale) + '\n') - f.write(str(0) + '\n') - f.write(str(0) + '\n') - f.write('-' + str(yScale) + '\n') - f.write(str(mapRect.xMinimum()) + '\n') - f.write(str(mapRect.yMaximum()) + '\n') - f.write(str(mapRect.xMaximum()) + '\n') - f.write(str(mapRect.yMinimum())) - f.close() - - - nomeLay = "gearthview" # foo default name - - -# Adesso scrivo il vettoriale -# Prendo il sistema di riferimento del Layer selezionato ------------------ - - - layer = mapCanvas.currentLayer() - if layer: - if layer.type() == layer.VectorLayer: - -# nele = -1 - name = layer.source(); - nomeLayer = layer.name() - nomeLay = nomeLayer.replace(" ","_") - - kml.write(' \n') - stringazza = (' %s\n') % (nomeLay) - kml.write (stringazza) - - crsSrc = layer.crs(); - - crsDest = QgsCoordinateReferenceSystem(4326) # Wgs84LLH - xform = QgsCoordinateTransform(crsSrc, crsDest) - -#---------------------------------------------------------------------------- -# Trasformo la finestra video in coordinate layer, -# per estrarre solo gli elementi visibili -#---------------------------------------------------------------------------- -# mapCanvas = iface.mapCanvas() - boundBox = mapCanvas.extent() - - xMin = float(boundBox.xMinimum()) - yMin = float(boundBox.yMinimum()) - - xMax = float(boundBox.xMaximum()) - yMax = float(boundBox.yMaximum()) - - - crs2 = mapCanvas.mapRenderer().destinationCrs() - crsSrc2 = QgsCoordinateReferenceSystem(crs2.authid()) - crsDest2 = QgsCoordinateReferenceSystem(layer.crs()) - xform2 = QgsCoordinateTransform(crsSrc2, crsDest2) - - pt0 = xform2.transform(QgsPoint(xMin, yMin)) - pt1 = xform2.transform(QgsPoint(xMax, yMax)) - - rect = QgsRectangle(pt0, pt1) - -#---------------------------------------------------------------------------- - - - rq = QgsFeatureRequest(rect) - - iter = layer.getFeatures(rq) - for feat in iter: - -# nele = nele + 1 - nele = feat.id() - -# Prendo il contenuto dei campi ------------- -# fff = feat.fields() -# num = fff.count() -# for iii in range(num): -# print "%s " %(feat[iii]) -# ------------------------------------------- - -# NathanW example code----------------------------- -# for feature in layer.getFeatures(): -# for attr in feature: -# print attr -# -# for f in layer.pendingFields(): -# print f.name() -#------------------------------------------------- - - # fetch geometry - geom = feat.geometry() - # show some information about the feature - -# print ("GeomType: %d") %(geom.type()) - - if geom.type() == QGis.Point: - elem = geom.asPoint() - x1 = elem.x() - y1 = elem.y() - - pt1 = xform.transform(QgsPoint(x1, y1)) - - kml.write (' \n') - - stringazza = (' %s\n') % (nele) - kml.write (stringazza) - - kml.write (' #default0\n') - -# DESCRIPTION DATA----------- - kml.write (' \n') - kml.write (' \n') - kml.write ('\n') - - # Prendo il contenuto dei campi ------------- - fff = feat.fields() - num = fff.count() - iii = -1 - for f in layer.pendingFields(): - iii = iii + 1 - - stringazza = ('\n') %(f.name(),feat[iii]) - - kml.write (stringazza) - - kml.write ('
Field NameField Value
%s%s
\n') - kml.write (']]>
\n') - -# DESCRIPTION DATA----------- - -# EXTENDED DATA ------------- -# stringazza = (' \n') % (nomeLay) -# kml.write (stringazza) -# -## stringazza = (' %d\n') %(nele) -## kml.write (stringazza) -# -## Prendo il contenuto dei campi ------------- -# fff = feat.fields() -# num = fff.count() -# iii = -1 -# for f in layer.pendingFields(): -# iii = iii + 1 -# -# stringazza = (' %s\n') %(f.name(),feat[iii]) -# -# kml.write (stringazza) -# -# kml.write (' \n') -# EXTENDED DATA ------------- - - kml.write (' \n') - kml.write (' 1\n') - stringazza = (' %.9lf,%.9lf\n') % (pt1.x(), pt1.y()) - kml.write (stringazza) - kml.write (' \n') - kml.write ('
\n') - - - elif geom.type() == QGis.Line: - - kml.write (' \n') - - stringazza = (' %s\n') % (nele) - kml.write (stringazza) - -# DESCRIPTION DATA----------- - kml.write (' \n') - kml.write (' \n') - kml.write ('\n') - - # Prendo il contenuto dei campi ------------- - fff = feat.fields() - num = fff.count() - iii = -1 - for f in layer.pendingFields(): - iii = iii + 1 - - stringazza = ('\n') %(f.name(),feat[iii]) - - kml.write (stringazza) - - kml.write ('
Field NameField Value
%s%s
\n') - kml.write (']]>
\n') - -# DESCRIPTION DATA----------- - -# EXTENDED DATA ------------- -# stringazza = (' \n') % (nomeLay) -# kml.write (stringazza) -# -## stringazza = (' %d\n') %(nele) -## kml.write (stringazza) -# -## Prendo il contenuto dei campi ------------- -# fff = feat.fields() -# num = fff.count() -# iii = -1 -# for f in layer.pendingFields(): -# iii = iii + 1 -# -# stringazza = (' %s\n') %(f.name(),feat[iii]) -# -# kml.write (stringazza) -# -# kml.write (' \n') -# EXTENDED DATA ------------- - - kml.write (' \n') - kml.write (' 1\n') - kml.write (' \n') - - elem = geom.asPolyline() - - for p1 in elem: - x1,y1 = p1.x(),p1.y() - - pt1 = xform.transform(QgsPoint(x1, y1)) - - stringazza = ('%.9lf,%.9lf \n') % (pt1.x(), pt1.y()) - kml.write (stringazza) - - kml.write (' \n') - kml.write (' \n') - kml.write ('
\n') - - - elif geom.type() == QGis.Polygon: - - kml.write (' \n') - stringazza = (' %s\n') % (nele) - kml.write (stringazza) - kml.write (' #msn_ylw-pushpin\n') - -# DESCRIPTION DATA----------- - kml.write (' \n') - kml.write (' \n') - kml.write ('\n') - - # Prendo il contenuto dei campi ------------- - fff = feat.fields() - num = fff.count() - iii = -1 - for f in layer.pendingFields(): - iii = iii + 1 - - stringazza = ('\n') %(f.name(),feat[iii]) - - kml.write (stringazza) - - kml.write ('
Field NameField Value
%s%s
\n') - kml.write (']]>
\n') - -# DESCRIPTION DATA----------- - -# EXTENDED DATA ------------- -# stringazza = (' \n') % (nomeLay) -# kml.write (stringazza) -# -## stringazza = (' %d\n') %(nele) -## kml.write (stringazza) -# -## Prendo il contenuto dei campi ------------- -# fff = feat.fields() -# num = fff.count() -# iii = -1 -# for f in layer.pendingFields(): -# iii = iii + 1 -# -# stringazza = (' %s\n') %(f.name(),feat[iii]) -# -# kml.write (stringazza) -# -# kml.write (' \n') -# EXTENDED DATA ------------- - - kml.write (' \n') - kml.write (' 1\n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - - elem = geom.asPolygon() - -# h ttp://qgis.spatialthoughts.com/2012/11/tip-count-number-of-vertices-in-layer.html - if geom.isMultipart(): - print "MULTIPART !!!" - elem = geom.asMultiPolygon() - -# for polygon in elem: -# for ring in polygon: -# print ("Pezzo con %d vertici") %(len(ring)) - - - - for iii in range (len(elem)): - - if (iii == 1): - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - - if (iii > 1): - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - - for jjj in range (len(elem[iii])): - - x1,y1 = elem[iii][jjj][0], elem[iii][jjj][1] - - if geom.isMultipart(): - pt1 = xform.transform(x1) - else: - pt1 = xform.transform(QgsPoint(x1, y1)) - - stringazza = ('%.9lf,%.9lf,0 \n') % (pt1.x(), pt1.y()) - kml.write (stringazza) - - if (iii == 0): - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - - if (iii > 0): - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - kml.write (' \n') - - kml.write ('
\n') - - kml.write ('
\n') - - - kml.write ('\n') - - stringazza = ('\n') % (nomeLay, nomeLay) - kml.write (stringazza) - kml.write (' \n') - kml.write ('\n') - - kml.write ('\n') - kml.write ('\n') - kml.close() - - if platform.system() == "Windows": - os.startfile(out_folder + '/doc.kml') - - if platform.system() == "Darwin": - os.system("open " + str(out_folder + '/doc.kml')) - - if platform.system() == "Linux": - os.system("xdg-open " + str(out_folder + '/doc.kml')) + out_folder = tempdir + + kml = codecs.open(out_folder + '/doc.kml', 'w', encoding='utf-8') + # kml=open(out_folder + '/doc.kml', 'w') + # + + iface = qgis.utils.iface + if QGis.QGIS_VERSION_INT <= 120200: + 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 = ("QGisView_%lf_%lf_%s") % (xN, yN, adesso) + + input_file = out_folder + "/" + nomePNG + ".png" + + # Save the image + image.save(input_file, "png") + + else: # ovvero QGis.QGIS_VERSION_INT > 120200 + mapRenderer = mapCanvas.mapRenderer() + mapRect = mapRenderer.extent() + width = mapRenderer.width() + height = mapRenderer.height() + srs = mapRenderer.destinationCrs() + + xN = mapRect.xMinimum() + yN = mapRect.yMinimum() + + mapSettings = QgsMapSettings() + mapSettings.setMapUnits(0) + mapSettings.setExtent(mapRect) + DPI = 300 + mapSettings.setOutputDpi(DPI) + + mapSettings.setOutputSize(QSize(width, height)) + + lst = [] + layerTreeRoot = QgsProject.instance().layerTreeRoot() + for id in layerTreeRoot.findLayerIds(): + node = layerTreeRoot.findLayer(id) + lst.append(id) + + mapSettings.setLayers(lst) + + mapSettings.setFlags( + QgsMapSettings.Antialiasing | QgsMapSettings.UseAdvancedEffects + | QgsMapSettings.ForceVectorOutput | QgsMapSettings.DrawLabeling) + image = QImage(QSize(width, height), QImage.Format_RGB32) + + image.fill(0) + + image.setDotsPerMeterX(DPI / 25.4 * 1000) + image.setDotsPerMeterY(DPI / 25.4 * 1000) + p = QPainter() + p.begin(image) + mapRenderer = QgsMapRendererCustomPainterJob(mapSettings, p) + mapRenderer.start() + mapRenderer.waitForFinished() + p.end() + + nomePNG = ("QGisView_%lf_%lf_%s") % (xN, yN, adesso) + input_file = out_folder + "/" + nomePNG + ".png" + + # Save the image + image.save(input_file, "png") + # EndIf # QGis.QGIS_VERSION_INT > 120200 + + layer = mapCanvas.currentLayer() + crsSrc = srs # QgsCoordinateReferenceSystem(layer.crs()) # prendere + # quello attuale + crsDest = QgsCoordinateReferenceSystem(4326) # Wgs84LLH + xform = QgsCoordinateTransform(crsSrc, crsDest) + + x1 = mapRect.xMinimum() + y1 = mapRect.yMinimum() + + x2 = mapRect.xMaximum() + y2 = mapRect.yMinimum() + + x3 = mapRect.xMaximum() + y3 = mapRect.yMaximum() + + x4 = mapRect.xMinimum() + y4 = mapRect.yMaximum() + + xc = (x1 + x3) / 2. + yc = (y1 + y3) / 2. + + pt1 = xform.transform(QgsPoint(x1, y1)) + pt2 = xform.transform(QgsPoint(x2, y2)) + pt3 = xform.transform(QgsPoint(x3, y3)) + pt4 = xform.transform(QgsPoint(x4, y4)) + + pt5 = xform.transform(QgsPoint(xc, yc)) + + xc = pt5.x() + yc = pt5.y() + + x1 = pt1.x() + y1 = pt1.y() + + x2 = pt2.x() + y2 = pt2.y() + + x3 = pt3.x() + y3 = pt3.y() + + x4 = pt4.x() + y4 = pt4.y() + + # Write kml header + kml.write('\n') + kml.write( + '\n') + kml.write(' \n') + kml.write(' QGisView\n') + kml.write(' \n') + loc = ( + " \n") % ( + yc, xc) + + kml.write(loc) + # + # kml.write(' http://map.project-osrm.org + # /?hl=it&loc=45.989486,12.778154&loc=45.985624, + # 12.781076&z=16¢er=45.984058, + # 12.774417&alt=0&df=0&re=0&ly=-940622518\n') + + kml.write(' 1\n') + + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' normal\n') + kml.write(' #sn_ylw-pushpin\n') + kml.write(' \n') + kml.write(' \n') + kml.write(' highlight\n') + kml.write(' #sh_ylw-pushpin\n') + kml.write(' \n') + kml.write(' \n') + + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' normal\n') + kml.write(' #default\n') + kml.write(' \n') + kml.write(' \n') + kml.write(' highlight\n') + kml.write(' #hl\n') + kml.write(' \n') + kml.write(' \n') + + rotazio = 0.0 + if QGis.QGIS_VERSION_INT >= 20801: + rotazio = -(mapCanvas.rotation()) + + kml.write(' \n') + + xc = (x1 + x3) / 2. + yc = (y1 + y3) / 2. + dx = (x3 - x1) * 75000. # 100000. + + kml.write(' 1\n') + kml.write(' \n') + kml.write(' QGIS_link\n') + kml.write(' 1\n') + kml.write(' 1\n') + kml.write(' \n') + kml.write(' ../_WebServer/QGIS_link.kmz\n') + kml.write(' \n') + kml.write(' \n') + + kml.write(' \n') + stringazza = (" %lf\n") % (xc) + kml.write(stringazza) + stringazza = (" %lf\n") % (yc) + kml.write(stringazza) + kml.write(' 0\n') + + stringazza = (" %lf\n") % (rotazio) + kml.write(stringazza) + + kml.write(' 0\n') + stringazza = (" %lf\n") % (dx) + kml.write(stringazza) + kml.write( + ' relativeToGround\n') + kml.write(' \n') + + kml.write(' \n') + kml.write(' QGisView\n') + + kml.write(' \n') + + # nomePNG = ("QGisView_%lf_%lf_%s") % (xN, yN, adesso) + stringazza = (" %s.png\n") % (nomePNG) + kml.write(stringazza) + kml.write(' 1.0\n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + + stringazza = ( + "%.9lf,%.9lf,0 %.9lf,%.9lf,0 %.9lf,%.9lf,0 %.9lf,%.9lf," + "0\n") % ( + x1, y1, x2, y2, x3, y3, x4, y4) + kml.write(stringazza) + + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + + # #Write kml footer + # kml.write('\n') + # #Close kml file + # kml.close() + + # Export tfw-file + xScale = (mapRect.xMaximum() - mapRect.xMinimum()) / image.width() + yScale = (mapRect.yMaximum() - mapRect.yMinimum()) / image.height() + + f = open(out_folder + "/" + nomePNG + ".pngw", 'w') + f.write(str(xScale) + '\n') + f.write(str(0) + '\n') + f.write(str(0) + '\n') + f.write('-' + str(yScale) + '\n') + f.write(str(mapRect.xMinimum()) + '\n') + f.write(str(mapRect.yMaximum()) + '\n') + f.write(str(mapRect.xMaximum()) + '\n') + f.write(str(mapRect.yMinimum())) + f.close() + + nomeLay = "gearthview" # foo default name + + # Adesso scrivo il vettoriale + # Prendo il sistema di riferimento del Layer selezionato + # ------------------ + + layer = mapCanvas.currentLayer() + if layer: + if layer.type() == layer.VectorLayer: + + # nele = -1 + name = layer.source(); + nomeLayer = layer.name() + nomeLay = nomeLayer.replace(" ", "_") + + kml.write(' \n') + stringazza = (' %s\n') % (nomeLay) + kml.write(stringazza) + + crsSrc = layer.crs(); + + crsDest = QgsCoordinateReferenceSystem(4326) # Wgs84LLH + xform = QgsCoordinateTransform(crsSrc, crsDest) + + # ---------------------------------------------------------------------------- + # Trasformo la finestra video in coordinate layer, + # per estrarre solo gli elementi visibili + # ---------------------------------------------------------------------------- + # mapCanvas = iface.mapCanvas() + boundBox = mapCanvas.extent() + + xMin = float(boundBox.xMinimum()) + yMin = float(boundBox.yMinimum()) + + xMax = float(boundBox.xMaximum()) + yMax = float(boundBox.yMaximum()) + + crs2 = mapCanvas.mapRenderer().destinationCrs() + crsSrc2 = QgsCoordinateReferenceSystem(crs2.authid()) + crsDest2 = QgsCoordinateReferenceSystem(layer.crs()) + xform2 = QgsCoordinateTransform(crsSrc2, crsDest2) + + pt0 = xform2.transform(QgsPoint(xMin, yMin)) + pt1 = xform2.transform(QgsPoint(xMax, yMax)) + + rect = QgsRectangle(pt0, pt1) + + # ---------------------------------------------------------------------------- + + rq = QgsFeatureRequest(rect) + + iter = layer.getFeatures(rq) + for feat in iter: + + # nele = nele + 1 + nele = feat.id() + + # Prendo il contenuto dei campi ------------- + # fff = feat.fields() + # num = fff.count() + # for iii in range(num): + # print "%s " %(feat[iii]) + # ------------------------------------------- + + # NathanW example code----------------------------- + # for feature in layer.getFeatures(): + # for attr in feature: + # print attr + # + # for f in layer.pendingFields(): + # print f.name() + # ------------------------------------------------- + + # fetch geometry + geom = feat.geometry() + # show some information about the feature + + # print ("GeomType: %d") %(geom.type()) + + if geom.type() == QGis.Point: + elem = geom.asPoint() + x1 = elem.x() + y1 = elem.y() + + pt1 = xform.transform(QgsPoint(x1, y1)) + + kml.write(' \n') + + stringazza = (' %s\n') % (nele) + kml.write(stringazza) + + kml.write(' #default0\n') + + # DESCRIPTION DATA----------- + kml.write(' \n') + kml.write(' \n') + kml.write( + '\n') + + # Prendo il contenuto dei campi ------------- + fff = feat.fields() + num = fff.count() + iii = -1 + for f in layer.pendingFields(): + iii = iii + 1 + + stringazza = ('\n') % ( + f.name(), feat[iii]) + + kml.write(stringazza) + + kml.write('
Field NameField Value
%s%s
\n') + kml.write(']]>
\n') + + # DESCRIPTION DATA----------- + + # EXTENDED DATA ------------- + # stringazza = (' + # \n') % ( + # nomeLay) + # kml.write (stringazza) + + # + ## stringazza = (' + # %d\n') %(nele) + ## kml.write (stringazza) + # + ## Prendo il contenuto dei campi ------------- + # fff = feat.fields() + # num = fff.count() + # iii = -1 + # for f in layer.pendingFields(): + + # iii = iii + 1 + # + # stringazza = (' + # %s\n') %(f.name(), + # feat[iii]) + # + # kml.write (stringazza) + + # + # kml.write (' + # \n') + # EXTENDED DATA ------------- + + kml.write(' \n') + kml.write(' 1\n') + stringazza = ( + ' %.9lf,' + '%.9lf\n') % ( + pt1.x(), pt1.y()) + kml.write(stringazza) + kml.write(' \n') + kml.write('
\n') + + elif geom.type() == QGis.Line: + + kml.write(' \n') + + stringazza = (' %s\n') % (nele) + kml.write(stringazza) + + # DESCRIPTION DATA----------- + kml.write(' \n') + kml.write(' \n') + kml.write( + '\n') + + # Prendo il contenuto dei campi ------------- + fff = feat.fields() + num = fff.count() + iii = -1 + for f in layer.pendingFields(): + iii = iii + 1 + + stringazza = ('\n') % ( + f.name(), feat[iii]) + + kml.write(stringazza) + + kml.write('
Field NameField Value
%s%s
\n') + kml.write(']]>
\n') + + # DESCRIPTION DATA----------- + + # EXTENDED DATA ------------- + # stringazza = (' + # \n') % ( + # nomeLay) + # kml.write (stringazza) + + # + ## stringazza = (' + # %d\n') %(nele) + ## kml.write (stringazza) + # + ## Prendo il contenuto dei campi ------------- + # fff = feat.fields() + # num = fff.count() + # iii = -1 + # for f in layer.pendingFields(): + + # iii = iii + 1 + # + # stringazza = (' + # %s\n') %(f.name(), + # feat[iii]) + # + # kml.write (stringazza) + + # + # kml.write (' + # \n') + # EXTENDED DATA ------------- + + kml.write(' \n') + kml.write(' 1\n') + kml.write(' \n') + + elem = geom.asPolyline() + + for p1 in elem: + x1, y1 = p1.x(), p1.y() + + pt1 = xform.transform(QgsPoint(x1, y1)) + + stringazza = ('%.9lf,%.9lf \n') % (pt1.x(), pt1.y()) + kml.write(stringazza) + + kml.write(' \n') + kml.write(' \n') + kml.write('
\n') + + elif geom.type() == QGis.Polygon: + + kml.write(' \n') + stringazza = (' %s\n') % (nele) + kml.write(stringazza) + kml.write( + ' #msn_ylw-pushpin\n') + + # DESCRIPTION DATA----------- + kml.write(' \n') + kml.write(' \n') + kml.write( + '\n') + + # Prendo il contenuto dei campi ------------- + fff = feat.fields() + num = fff.count() + iii = -1 + for f in layer.pendingFields(): + iii = iii + 1 + + stringazza = ('\n') % ( + f.name(), feat[iii]) + + kml.write(stringazza) + + kml.write('
Field NameField Value
%s%s
\n') + kml.write(']]>
\n') + + # DESCRIPTION DATA----------- + + # EXTENDED DATA ------------- + # stringazza = (' + # \n') % ( + # nomeLay) + # kml.write (stringazza) + + # + ## stringazza = (' + # %d\n') %(nele) + ## kml.write (stringazza) + # + ## Prendo il contenuto dei campi ------------- + # fff = feat.fields() + # num = fff.count() + # iii = -1 + # for f in layer.pendingFields(): + + # iii = iii + 1 + # + # stringazza = (' + # %s\n') %(f.name(), + # feat[iii]) + # + # kml.write (stringazza) + + # + # kml.write (' + # \n') + # EXTENDED DATA ------------- + + kml.write(' \n') + kml.write(' 1\n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + + elem = geom.asPolygon() + + # h ttp://qgis.spatialthoughts.com/2012/11/tip-count + # -number-of-vertices-in-layer.html + if geom.isMultipart(): + print "MULTIPART !!!" + elem = geom.asMultiPolygon() + + # for polygon in elem: + # for ring in polygon: + # print ("Pezzo con %d + # vertici") %(len(ring)) + + for iii in range(len(elem)): + + if (iii == 1): + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + + if (iii > 1): + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + + for jjj in range(len(elem[iii])): + + x1, y1 = elem[iii][jjj][0], elem[iii][jjj][1] + + if geom.isMultipart(): + pt1 = xform.transform(x1) + else: + pt1 = xform.transform(QgsPoint(x1, y1)) + + stringazza = ('%.9lf,%.9lf,0 \n') % ( + pt1.x(), pt1.y()) + kml.write(stringazza) + + if (iii == 0): + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + + if (iii > 0): + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + kml.write(' \n') + + kml.write('
\n') + + kml.write('
\n') + + kml.write('\n') + + stringazza = ('\n') % (nomeLay, nomeLay) + kml.write(stringazza) + kml.write(' \n') + kml.write('\n') + + kml.write('\n') + kml.write('\n') + kml.close() + + if platform.system() == "Windows": + os.startfile(out_folder + '/doc.kml') + + if platform.system() == "Darwin": + os.system("open " + str(out_folder + '/doc.kml')) + + if platform.system() == "Linux": + os.system("xdg-open " + str(out_folder + '/doc.kml')) # GDX_Publisher2 -------------------------------------- def GDX_Publisher2(self): + mapCanvas = self.iface.mapCanvas() + + tempdir = unicode(QFileInfo( + QgsApplication.qgisUserDbFilePath()).path()) + \ + "/python/plugins/gearthview/temp" + adesso = str(datetime.datetime.now()) + adesso = adesso.replace(" ", "_") + adesso = adesso.replace(":", "_") + adesso = adesso.replace(".", "_") - mapCanvas = self.iface.mapCanvas() - - tempdir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()) + "/python/plugins/gearthview/temp" + text = mapCanvas.extent().toString() + text1 = text.replace(",", " ") + text2 = text1.replace(" : ", ",") - adesso = str(datetime.datetime.now()) - adesso = adesso.replace(" ","_") - adesso = adesso.replace(":","_") - adesso = adesso.replace(".","_") + # HERE IT DELETES THE OLD IMAGE ------------------------------------ + # (if you comment these, images still remain ... :) + for filename in glob.glob(str(tempdir + '/*.png')): + os.remove(str(filename)) + for filename in glob.glob(str(tempdir + '/*.pngw')): + os.remove(str(filename)) + # ------------------------------------------------------------------ + tname = 'ZIPPA' - text = mapCanvas.extent().toString() - text1 = text.replace("," , " ") - text2 = text1.replace(" : ", ",") - + out_folder = tempdir -# HERE IT DELETES THE OLD IMAGE ------------------------------------ -# (if you comment these, images still remain ... :) - for filename in glob.glob(str(tempdir + '/*.png')) : - os.remove( str(filename) ) - for filename in glob.glob(str(tempdir + '/*.pngw')) : - os.remove( str(filename) ) -# ------------------------------------------------------------------ + 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 = ("QGisView_%lf_%lf_%s") % (xN, yN, adesso) + + input_file = out_folder + "/" + nomePNG + ".png" + + # Save the image + image.save(input_file, "png") + + layer = mapCanvas.currentLayer() + crsSrc = srs # QgsCoordinateReferenceSystem(layer.crs()) # prendere + # quello attuale + crsDest = QgsCoordinateReferenceSystem(4326) # Wgs84LLH + xform = QgsCoordinateTransform(crsSrc, crsDest) + + x1 = mapRect.xMinimum() + y1 = mapRect.yMinimum() + + x2 = mapRect.xMaximum() + y2 = mapRect.yMinimum() + + x3 = mapRect.xMaximum() + y3 = mapRect.yMaximum() + + x4 = mapRect.xMinimum() + y4 = mapRect.yMaximum() + + xc = (x1 + x3) / 2. + yc = (y1 + y3) / 2. + + pt1 = xform.transform(QgsPoint(x1, y1)) + pt2 = xform.transform(QgsPoint(x2, y2)) + pt3 = xform.transform(QgsPoint(x3, y3)) + pt4 = xform.transform(QgsPoint(x4, y4)) + + pt5 = xform.transform(QgsPoint(xc, yc)) + + xc = pt5.x() + yc = pt5.y() + + x1 = pt1.x() + y1 = pt1.y() + + x2 = pt2.x() + y2 = pt2.y() + + x3 = pt3.x() + y3 = pt3.y() + + x4 = pt4.x() + y4 = pt4.y() + + kml = "" + + # Write kml header + + # kml = kml + ('\n') + # kml = kml + ('\n') + # kml = kml + (' \n') + # kml = kml + (' QGisView\n') + # kml = kml + (' \n') + # loc = (" \n") %(yc, xc) + # kml = kml + (loc) + # kml = kml + (' 0\n') + + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' normal\n') + # kml = kml + (' + # #sn_ylw-pushpin\n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' highlight\n') + # kml = kml + (' + # #sh_ylw-pushpin\n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # + # kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' normal\n') -# kml = kml + (' #sn_ylw-pushpin\n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' highlight\n') -# kml = kml + (' #sh_ylw-pushpin\n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' normal\n') -# kml = kml + (' #default\n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' highlight\n') -# kml = kml + (' #hl\n') -# kml = kml + (' \n') -# kml = kml + (' \n') - - -# kml = kml + (' \n') - - xc = (x1 + x3) / 2. - yc = (y1 + y3) / 2. - dx = (x3 - x1) * 75000. #100000. - -# kml = kml + (' \n') -# stringazza = (" %lf\n") %(xc) -# kml = kml + (stringazza) -# stringazza = (" %lf\n") %(yc) -# kml = kml + (stringazza) -# kml = kml + (' 0\n') -# kml = kml + (' 0.00\n') -# kml = kml + (' 0\n') -# stringazza = (" %lf\n") %(dx) -# kml = kml + (stringazza) -# kml = kml + (' relativeToGround\n') -# kml = kml + (' \n') - -# kml = kml + (' \n') -# kml = kml + (' QGisView\n') - -# kml = kml + (' \n') - -# stringazza = (" %s.png\n") % (nomePNG) -# kml = kml + (stringazza) -# kml = kml + (' 1.0\n') -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' \n') - -# stringazza = ("%.9lf,%.9lf,0 %.9lf,%.9lf,0 %.9lf,%.9lf,0 %.9lf,%.9lf,0\n") % (x1, y1, x2, y2, x3, y3, x4, y4) -# kml = kml + (stringazza) - -# kml = kml + (' \n') -# kml = kml + (' \n') -# kml = kml + (' \n') - -# #Write kml footer -# kml = kml + ('\n') -# #Close kml file -# kml.close() - - - - #Export tfw-file -# xScale = (mapRect.xMaximum() - mapRect.xMinimum()) / image.width() -# yScale = (mapRect.yMaximum() - mapRect.yMinimum()) / image.height() - - -# f = open(out_folder + "/" + nomePNG + ".pngw", 'w') -# f.write(str(xScale) + '\n') -# f.write(str(0) + '\n') -# f.write(str(0) + '\n') -# f.write('-' + str(yScale) + '\n') -# f.write(str(mapRect.xMinimum()) + '\n') -# f.write(str(mapRect.yMaximum()) + '\n') -# f.write(str(mapRect.xMaximum()) + '\n') -# f.write(str(mapRect.yMinimum())) -# f.close() - - - nomeLay = "gearthview" # foo default name - - -# Adesso scrivo il vettoriale -# Prendo il sistema di riferimento del Layer selezionato ------------------ - - - layer = mapCanvas.currentLayer() - if layer: - if layer.type() == layer.VectorLayer: + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' normal\n') + # kml = kml + (' + # #default\n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' highlight\n') + # kml = kml + (' + # #hl\n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + + xc = (x1 + x3) / 2. + yc = (y1 + y3) / 2. + dx = (x3 - x1) * 75000. # 100000. + + # kml = kml + (' \n') + # stringazza = (" %lf\n") + # %(xc) + # kml = kml + (stringazza) + # stringazza = (" %lf\n") + # %(yc) + # kml = kml + (stringazza) + # kml = kml + (' 0\n') + # kml = kml + (' 0.00\n') + # kml = kml + (' 0\n') + # stringazza = (" %lf\n") %(dx) + # kml = kml + (stringazza) + # kml = kml + (' + # relativeToGround\n') + # kml = kml + (' \n') + + # kml = kml + (' \n') + # kml = kml + (' QGisView\n') + + # kml = kml + (' \n') + + # stringazza = (" %s.png\n") % (nomePNG) + # kml = kml + (stringazza) + # kml = kml + (' + # 1.0\n') + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + + # stringazza = ("%.9lf,%.9lf,0 %.9lf,%.9lf,0 %.9lf, + # %.9lf,0 %.9lf,%.9lf,0\n") % (x1, y1, x2, y2, x3, y3, x4, y4) + # kml = kml + (stringazza) + + # kml = kml + (' \n') + # kml = kml + (' \n') + # kml = kml + (' \n') + + # #Write kml footer + # kml = kml + ('\n') + # #Close kml file + # kml.close() + + + + # Export tfw-file + # xScale = (mapRect.xMaximum() - mapRect.xMinimum()) / + # image.width() + # yScale = (mapRect.yMaximum() - mapRect.yMinimum()) / + # image.height() + + # f = open(out_folder + "/" + nomePNG + ".pngw", + # 'w') + # f.write(str(xScale) + '\n') + # f.write(str(0) + '\n') + # f.write(str(0) + '\n') + # f.write('-' + str(yScale) + '\n') + # f.write(str(mapRect.xMinimum()) + '\n') + # f.write(str(mapRect.yMaximum()) + '\n') + # f.write(str(mapRect.xMaximum()) + '\n') + # f.write(str(mapRect.yMinimum())) + # f.close() + + nomeLay = "gearthview" # foo default name + + # Adesso scrivo il vettoriale + # Prendo il sistema di riferimento del Layer selezionato + # ------------------ + + layer = mapCanvas.currentLayer() + if layer: + if layer.type() == layer.VectorLayer: + + name = layer.source(); + nomeLayer = layer.name() + nomeLay = nomeLayer.replace(" ", "_") + + kml = kml + (' \n') + stringazza = (' %s\n') % (nomeLay) + kml = kml + (stringazza) + + crsSrc = layer.crs(); + + crsDest = QgsCoordinateReferenceSystem(4326) # Wgs84LLH + xform = QgsCoordinateTransform(crsSrc, crsDest) + + boundBox = mapCanvas.extent() + + xMin = float(boundBox.xMinimum()) + yMin = float(boundBox.yMinimum()) + + xMax = float(boundBox.xMaximum()) + yMax = float(boundBox.yMaximum()) - name = layer.source(); - nomeLayer = layer.name() - nomeLay = nomeLayer.replace(" ","_") + crs2 = mapCanvas.mapRenderer().destinationCrs() + crsSrc2 = QgsCoordinateReferenceSystem(crs2.authid()) + crsDest2 = QgsCoordinateReferenceSystem(layer.crs()) + xform2 = QgsCoordinateTransform(crsSrc2, crsDest2) - kml = kml + (' \n') - stringazza = (' %s\n') % (nomeLay) - kml = kml + (stringazza) - - crsSrc = layer.crs(); + pt0 = xform2.transform(QgsPoint(xMin, yMin)) + pt1 = xform2.transform(QgsPoint(xMax, yMax)) - crsDest = QgsCoordinateReferenceSystem(4326) # Wgs84LLH - xform = QgsCoordinateTransform(crsSrc, crsDest) + rect = QgsRectangle(pt0, pt1) + rq = QgsFeatureRequest(rect) - boundBox = mapCanvas.extent() - - xMin = float(boundBox.xMinimum()) - yMin = float(boundBox.yMinimum()) - - xMax = float(boundBox.xMaximum()) - yMax = float(boundBox.yMaximum()) - - - crs2 = mapCanvas.mapRenderer().destinationCrs() - crsSrc2 = QgsCoordinateReferenceSystem(crs2.authid()) - crsDest2 = QgsCoordinateReferenceSystem(layer.crs()) - xform2 = QgsCoordinateTransform(crsSrc2, crsDest2) - - pt0 = xform2.transform(QgsPoint(xMin, yMin)) - pt1 = xform2.transform(QgsPoint(xMax, yMax)) - - rect = QgsRectangle(pt0, pt1) - - - - rq = QgsFeatureRequest(rect) - - iter = layer.getFeatures(rq) - for feat in iter: - - nele = feat.id() - - - # fetch geometry - geom = feat.geometry() - # show some information about the feature - -# print ("GeomType: %d") %(geom.type()) - - if geom.type() == QGis.Point: - elem = geom.asPoint() - x1 = elem.x() - y1 = elem.y() - - pt1 = xform.transform(QgsPoint(x1, y1)) - - kml = kml + (' \n') - - stringazza = (' %s\n') % (nele) - kml = kml + (stringazza) - - kml = kml + (' #default0\n') - -# DESCRIPTION DATA----------- - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + ('\n') - - # Prendo il contenuto dei campi ------------- - fff = feat.fields() - num = fff.count() - iii = -1 - for f in layer.pendingFields(): - iii = iii + 1 - - stringazza = ('\n') %(f.name(),feat[iii]) - - kml = kml + (stringazza) - - kml = kml + ('
Field NameField Value
%s%s
\n') - kml = kml + (']]>
\n') - -# DESCRIPTION DATA----------- - - - kml = kml + (' \n') - kml = kml + (' 1\n') - stringazza = (' %.9lf,%.9lf\n') % (pt1.x(), pt1.y()) - kml = kml + (stringazza) - kml = kml + (' \n') - kml = kml + ('
\n') - - - elif geom.type() == QGis.Line: - - kml = kml + (' \n') - - stringazza = (' %s\n') % (nele) - kml = kml + (stringazza) - -# DESCRIPTION DATA----------- - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + ('\n') - - # Prendo il contenuto dei campi ------------- - fff = feat.fields() - num = fff.count() - iii = -1 - for f in layer.pendingFields(): - iii = iii + 1 - - stringazza = ('\n') %(f.name(),feat[iii]) - - kml = kml + (stringazza) - - kml = kml + ('
Field NameField Value
%s%s
\n') - kml = kml + (']]>
\n') - - - kml = kml + (' \n') - kml = kml + (' 1\n') - kml = kml + (' \n') - - elem = geom.asPolyline() - - for p1 in elem: - x1,y1 = p1.x(),p1.y() - - pt1 = xform.transform(QgsPoint(x1, y1)) - - stringazza = ('%.9lf,%.9lf \n') % (pt1.x(), pt1.y()) - kml = kml + (stringazza) - - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + ('
\n') - - - elif geom.type() == QGis.Polygon: - - kml = kml + (' \n') - stringazza = (' %s\n') % (nele) - kml = kml + (stringazza) - kml = kml + (' #msn_ylw-pushpin\n') - -# DESCRIPTION DATA----------- - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + ('\n') - - # Prendo il contenuto dei campi ------------- - fff = feat.fields() - num = fff.count() - iii = -1 - for f in layer.pendingFields(): - iii = iii + 1 - - stringazza = ('\n') %(f.name(),feat[iii]) - - kml = kml + (stringazza) - - kml = kml + ('
Field NameField Value
%s%s
\n') - kml = kml + (']]>
\n') - -# DESCRIPTION DATA----------- - - - kml = kml + (' \n') - kml = kml + (' 1\n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - - elem = geom.asPolygon() - -# h ttp://qgis.spatialthoughts.com/2012/11/tip-count-number-of-vertices-in-layer.html - if geom.isMultipart(): - print "MULTIPART !!!" - elem = geom.asMultiPolygon() - - for polygon in elem: - for ring in polygon: - print ("Pezzo con %d vertici") %(len(ring)) - - - - for iii in range (len(elem)): - - if (iii == 1): - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - - if (iii > 1): - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - - for jjj in range (len(elem[iii])): - - x1,y1 = elem[iii][jjj][0], elem[iii][jjj][1] - - if geom.isMultipart(): - pt1 = xform.transform(x1) - else: - pt1 = xform.transform(QgsPoint(x1, y1)) - - stringazza = ('%.9lf,%.9lf,0 \n') % (pt1.x(), pt1.y()) - kml = kml + (stringazza) - - if (iii == 0): - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - - if (iii > 0): - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - kml = kml + (' \n') - - kml = kml + ('
\n') - - kml = kml + ('
\n') - - -# kml = kml + ('
\n') - -# stringazza = ('\n') % (nomeLay, nomeLay) -# kml = kml + (stringazza) -# kml = kml + (' \n') -# kml = kml + ('\n') - -# kml = kml + ('\n') -# kml = kml + ('\n') - - -# kmlFile = codecs.open(out_folder + '/doc.kml', 'w', encoding='utf-8') -# kmlFile.write(kml) -# kmlFile.close() - -# print 'Content-Type: application/vnd.google-earth.kml+xml\n' - return kml - + iter = layer.getFeatures(rq) + for feat in iter: -# ---------------------------------------------------- -class gearthview: + nele = feat.id() + + # fetch geometry + geom = feat.geometry() + # show some information about the feature + + # print ("GeomType: %d") %(geom.type()) + if geom.type() == QGis.Point: + elem = geom.asPoint() + x1 = elem.x() + y1 = elem.y() + pt1 = xform.transform(QgsPoint(x1, y1)) + + kml = kml + (' \n') + + stringazza = (' %s\n') % (nele) + kml = kml + (stringazza) + + kml = kml + (' #default0\n') + + # DESCRIPTION DATA----------- + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + ( + '\n') + + # Prendo il contenuto dei campi ------------- + fff = feat.fields() + num = fff.count() + iii = -1 + for f in layer.pendingFields(): + iii = iii + 1 + + stringazza = ('\n') % ( + f.name(), feat[iii]) + + kml = kml + (stringazza) + + kml = kml + ('
Field NameField Value
%s%s
\n') + kml = kml + (']]>
\n') + + # DESCRIPTION DATA----------- + + kml = kml + (' \n') + kml = kml + ( + ' 1\n') + stringazza = ( + ' %.9lf,' + '%.9lf\n') % ( + pt1.x(), pt1.y()) + kml = kml + (stringazza) + kml = kml + (' \n') + kml = kml + ('
\n') + + elif geom.type() == QGis.Line: + + kml = kml + (' \n') + + stringazza = (' %s\n') % (nele) + kml = kml + (stringazza) + + # DESCRIPTION DATA----------- + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + ( + '\n') + + # Prendo il contenuto dei campi ------------- + fff = feat.fields() + num = fff.count() + iii = -1 + for f in layer.pendingFields(): + iii = iii + 1 + + stringazza = ('\n') % ( + f.name(), feat[iii]) + + kml = kml + (stringazza) + + kml = kml + ('
Field NameField Value
%s%s
\n') + kml = kml + (']]>
\n') + + kml = kml + (' \n') + kml = kml + (' 1\n') + kml = kml + (' \n') + + elem = geom.asPolyline() + + for p1 in elem: + x1, y1 = p1.x(), p1.y() + + pt1 = xform.transform(QgsPoint(x1, y1)) + + stringazza = ('%.9lf,%.9lf \n') % (pt1.x(), pt1.y()) + kml = kml + (stringazza) + + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + ('
\n') + + elif geom.type() == QGis.Polygon: + + kml = kml + (' \n') + stringazza = (' %s\n') % (nele) + kml = kml + (stringazza) + kml = kml + ( + ' #msn_ylw-pushpin\n') + + # DESCRIPTION DATA----------- + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + ( + '\n') + + # Prendo il contenuto dei campi ------------- + fff = feat.fields() + num = fff.count() + iii = -1 + for f in layer.pendingFields(): + iii = iii + 1 + + stringazza = ('\n') % ( + f.name(), feat[iii]) + + kml = kml + (stringazza) + + kml = kml + ('
Field NameField Value
%s%s
\n') + kml = kml + (']]>
\n') + + # DESCRIPTION DATA----------- + + kml = kml + (' \n') + kml = kml + (' 1\n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + + elem = geom.asPolygon() + + # h ttp://qgis.spatialthoughts.com/2012/11/tip-count + # -number-of-vertices-in-layer.html + if geom.isMultipart(): + print "MULTIPART !!!" + elem = geom.asMultiPolygon() + + for polygon in elem: + for ring in polygon: + print ("Pezzo con %d vertici") % (len(ring)) + + for iii in range(len(elem)): + + if (iii == 1): + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + + if (iii > 1): + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + + for jjj in range(len(elem[iii])): + + x1, y1 = elem[iii][jjj][0], elem[iii][jjj][1] + + if geom.isMultipart(): + pt1 = xform.transform(x1) + else: + pt1 = xform.transform(QgsPoint(x1, y1)) + + stringazza = ('%.9lf,%.9lf,0 \n') % ( + pt1.x(), pt1.y()) + kml = kml + (stringazza) + + if (iii == 0): + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + + if (iii > 0): + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + kml = kml + (' \n') + + kml = kml + ('
\n') + + kml = kml + ('
\n') + + # kml = kml + ('\n') + + # stringazza = ('\n') % ( + # nomeLay, nomeLay) + # kml = kml + (stringazza) + # kml = kml + (' \n') + # kml = kml + ('\n') + + # kml = kml + ('\n') + # kml = kml + ('\n') + + # kmlFile = codecs.open(out_folder + '/doc.kml', 'w', + # encoding='utf-8') + # kmlFile.write(kml) + # kmlFile.close() + + # print 'Content-Type: + # application/vnd.google-earth.kml+xml\n' + return kml + + +# ---------------------------------------------------- +class gearthview: def __init__(self, iface): global serverStarted serverStarted = 0 - + global lat, lon - lat = 0.00 - lon = 0.00 + lat = 0.00 + lon = 0.00 # Save reference to the QGIS interface self.iface = iface # Create the dialog and keep reference self.dlg = gearthviewDialog() # initialize plugin directory - self.plugin_dir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/gearthview" + self.plugin_dir = QFileInfo( + QgsApplication.qgisUserDbFilePath()).path() + \ + "/python/plugins/gearthview" # initialize locale localePath = "" - if QGis.QGIS_VERSION_INT < 10900: - locale = QSettings().value("locale/userLocale").toString()[0:2] + if QGis.QGIS_VERSION_INT < 10900: + locale = QSettings().value("locale/userLocale").toString()[0:2] else: - locale = QSettings().value("locale/userLocale")[0:2] + locale = QSettings().value("locale/userLocale")[0:2] if QFileInfo(self.plugin_dir).exists(): localePath = self.plugin_dir + "/i18n/gearthview_" + locale + ".qm" @@ -1650,232 +1774,248 @@ def __init__(self, iface): if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) + # ---------------------------------------------------- + ###modified by Aldo Scorza (start) -# ---------------------------------------------------- -###modified by Aldo Scorza (start) def initGui(self): # Create action that will start plugin configuration - self.action = QAction(QIcon(self.plugin_dir + "/iconG.png"),QCoreApplication.translate(u"GEarthView", "GEarthView"), self.iface.mainWindow()) + self.action = QAction(QIcon(self.plugin_dir + "/iconG.png"), + QCoreApplication.translate(u"GEarthView", + "GEarthView"), + self.iface.mainWindow()) QObject.connect(self.action, SIGNAL("triggered()"), self.run) # connect the action to the run method - self.PasteFromGEaction = QAction(QIcon(self.plugin_dir + "/iconQG.png"),QCoreApplication.translate(u"GEarthView", "PasteFromGE"), self.iface.mainWindow()) - QObject.connect(self.PasteFromGEaction, SIGNAL("triggered()"), self.PasteFromGE) - - -# self.QRcodingAction= QAction(QIcon(self.plugin_dir + "/iconQR.png"), QCoreApplication.translate(u"&GEarthView", "GE_QRcoding"), self.iface.mainWindow()) -# QObject.connect(self.QRcodingAction, SIGNAL("triggered()"), self.startQrCoding) - -# self.QGEarthAction= QAction(QIcon(self.plugin_dir + "/iconQG.png"), QCoreApplication.translate(u"&GEarthView", "PointFromGE"), self.iface.mainWindow()) -# QObject.connect(self.QGEarthAction, SIGNAL("triggered()"), self.QGEarth) - - self.aboutAction= QAction(QIcon(self.plugin_dir + "/iconA.png"), QCoreApplication.translate(u"&GEarthView", "About"), self.iface.mainWindow()) + self.PasteFromGEaction = QAction( + QIcon(self.plugin_dir + "/iconQG.png"), + QCoreApplication.translate(u"GEarthView", "PasteFromGE"), + self.iface.mainWindow()) + QObject.connect(self.PasteFromGEaction, SIGNAL("triggered()"), + self.PasteFromGE) + + # self.QRcodingAction= QAction(QIcon(self.plugin_dir + + # "/iconQR.png"), QCoreApplication.translate(u"&GEarthView", + # "GE_QRcoding"), self.iface.mainWindow()) + # QObject.connect(self.QRcodingAction, SIGNAL("triggered()"), + # self.startQrCoding) + + # self.QGEarthAction= QAction(QIcon(self.plugin_dir + + # "/iconQG.png"), QCoreApplication.translate(u"&GEarthView", + # "PointFromGE"), self.iface.mainWindow()) + # QObject.connect(self.QGEarthAction, SIGNAL("triggered()"), + # self.QGEarth) + + self.aboutAction = QAction(QIcon(self.plugin_dir + "/iconA.png"), + QCoreApplication.translate(u"&GEarthView", + "About"), + self.iface.mainWindow()) QObject.connect(self.aboutAction, SIGNAL("triggered()"), self.about) - self.toolBar = self.iface.mainWindow().findChild(QObject, 'Geodrinx') - if not self.toolBar : - self.toolBar = self.iface.addToolBar("Geodrinx") - self.toolBar.setObjectName("Geodrinx") + if not self.toolBar: + self.toolBar = self.iface.addToolBar("Geodrinx") + self.toolBar.setObjectName("Geodrinx") self.GECombo = QMenu(self.iface.mainWindow()) self.GECombo.addAction(self.action) self.GECombo.addAction(self.PasteFromGEaction) -# self.GECombo.addAction(self.QRcodingAction) -# self.GECombo.addAction(self.QGEarthAction) + # self.GECombo.addAction(self.QRcodingAction) + # self.GECombo.addAction(self.QGEarthAction) self.GECombo.addAction(self.aboutAction) - + self.toolButton = QToolButton() - self.toolButton.setMenu( self.GECombo ) - self.toolButton.setDefaultAction( self.action ) - self.toolButton.setPopupMode( QToolButton.InstantPopup ) - + self.toolButton.setMenu(self.GECombo) + self.toolButton.setDefaultAction(self.action) + self.toolButton.setPopupMode(QToolButton.InstantPopup) + self.toolBar.addWidget(self.toolButton) - self.GECombo.setToolTip("GEarthView") - + self.GECombo.setToolTip("GEarthView") + # Add toolbar button and menu item self.iface.addPluginToWebMenu(u"&GEarthView", self.action) - + self.iface.addPluginToWebMenu(u"GEarthView", self.PasteFromGEaction) -# self.iface.addPluginToWebMenu(u"&GEarthView", self.QRcodingAction) + # self.iface.addPluginToWebMenu(u"&GEarthView", + # self.QRcodingAction) -# self.iface.addPluginToWebMenu(u"&GEarthView", self.QGEarthAction) - - self.iface.addPluginToWebMenu(u"&GEarthView", self.aboutAction) + # self.iface.addPluginToWebMenu(u"&GEarthView", + # self.QGEarthAction) + + self.iface.addPluginToWebMenu(u"&GEarthView", self.aboutAction) -# --------------------------------------------------------- + # --------------------------------------------------------- def unload(self): # Remove the plugin menu item and icon self.iface.removePluginWebMenu(u"&GEarthView", self.action) self.iface.removePluginWebMenu(u"&GEarthView", self.PasteFromGEaction) self.iface.removePluginWebMenu(u"&GEarthView", self.aboutAction) -# QObject.disconnect(self.action) -# QObject.disconnect(self.PasteFromGEaction) -# QObject.disconnect(self.aboutAction) -# self.toolBar.setVisible( false ) - #virtual void QgisInterface::removeToolBarIcon ( QAction * qAction ) - #self.toolBar.removeAction(self.action) - #self.toolBar.removeAction(self.PasteFromGEaction) - #self.toolBar.removeAction(self.aboutAction) - #del self.GECombo + # QObject.disconnect(self.action) + # QObject.disconnect(self.PasteFromGEaction) + # QObject.disconnect(self.aboutAction) + # self.toolBar.setVisible( false ) + # virtual void QgisInterface::removeToolBarIcon ( QAction * + # qAction ) + # self.toolBar.removeAction(self.action) + # self.toolBar.removeAction(self.PasteFromGEaction) + # self.toolBar.removeAction(self.aboutAction) + # del self.GECombo self.toolBar.removeAction(self.action) - if not self.toolBar.actions() : - del self.toolBar - #self.iface.removeToolBarIcon(self.action) + if not self.toolBar.actions(): + del self.toolBar + # self.iface.removeToolBarIcon(self.action) -###modified by Aldo Scorza (end)\ + ###modified by Aldo Scorza (end)\ + # ---------------------------------------------------- -# ---------------------------------------------------- def PasteFromGE(self): - mapCanvas = self.iface.mapCanvas() - - copyText = QApplication.clipboard().text() - tempdir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/gearthview/temp" + copyText = QApplication.clipboard().text() -# GEKml_Points.kml -# GEKml_Lines.kml -# GEKml_Polygons.kml + tempdir = QFileInfo( + QgsApplication.qgisUserDbFilePath()).path() + \ + "/python/plugins/gearthview/temp" + # GEKml_Points.kml + # GEKml_Lines.kml + # GEKml_Polygons.kml # Tolgo i livelli precedenti -# QgsMapLayerRegistry.instance().removeMapLayer("GEKml_Points") -# QgsMapLayerRegistry.instance().removeMapLayer("GEKml_Lines") -# QgsMapLayerRegistry.instance().removeMapLayer("GEKml_Polygons") + # QgsMapLayerRegistry.instance().removeMapLayer( + # "GEKml_Points") + # QgsMapLayerRegistry.instance().removeMapLayer( + # "GEKml_Lines") + # QgsMapLayerRegistry.instance().removeMapLayer( + # "GEKml_Polygons") for iLayer in range(mapCanvas.layerCount()): - layer = mapCanvas.layer(iLayer) - if (layer.name() == "GEKml_Points") or (layer.name() == "GEKml_Lines") or (layer.name() == "GEKml_Polygons"): - QgsMapLayerRegistry.instance().removeMapLayer(layer.id()) - - - GEKml_Points = copyText.find("") - GEKml_Lines = copyText.find("") - GEKml_Polygons = copyText.find("") - - - if (GEKml_Polygons > 0): - - salvalo2 = codecs.open(tempdir + "/GEKml_Polygons.kml", 'w', encoding='utf-8') - salvalo2.write (copyText) - - salvalo2.close() - - vlayer = QgsVectorLayer(tempdir + "/GEKml_Polygons.kml", "GEKml_Polygons", "ogr") - QgsMapLayerRegistry.instance().addMapLayer(vlayer) - - - if (GEKml_Lines > 0): - - salvalo2 = codecs.open(tempdir + "/GEKml_Lines.kml", 'w', encoding='utf-8') - salvalo2.write (copyText) + layer = mapCanvas.layer(iLayer) + if (layer.name() == "GEKml_Points") or ( + layer.name() == "GEKml_Lines") or ( + layer.name() == "GEKml_Polygons"): + QgsMapLayerRegistry.instance().removeMapLayer(layer.id()) + + GEKml_Points = copyText.find("") + GEKml_Lines = copyText.find("") + GEKml_Polygons = copyText.find("") + + if (GEKml_Polygons > 0): + salvalo2 = codecs.open(tempdir + "/GEKml_Polygons.kml", 'w', + encoding='utf-8') + salvalo2.write(copyText) + + salvalo2.close() + + vlayer = QgsVectorLayer(tempdir + "/GEKml_Polygons.kml", + "GEKml_Polygons", "ogr") + QgsMapLayerRegistry.instance().addMapLayer(vlayer) + + if (GEKml_Lines > 0): + salvalo2 = codecs.open(tempdir + "/GEKml_Lines.kml", 'w', + encoding='utf-8') + salvalo2.write(copyText) + + salvalo2.close() + + vlayer = QgsVectorLayer(tempdir + "/GEKml_Lines.kml", + "GEKml_Lines", "ogr") + QgsMapLayerRegistry.instance().addMapLayer(vlayer) + + if (GEKml_Points > 0): + salvalo2 = codecs.open(tempdir + "/GEKml_Points.kml", 'w', + encoding='utf-8') + salvalo2.write(copyText) + + salvalo2.close() + + vlayer = QgsVectorLayer(tempdir + "/GEKml_Points.kml", + "GEKml_Points", "ogr") + QgsMapLayerRegistry.instance().addMapLayer(vlayer) + + # ---------------------------------------------------- + # def startQrCoding(self): + # startGeoDrink_Server(self) + + # ------- OLD CODE ------------------------------------------------------ + # webServerDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()) + "python/plugins/gearthview/_WebServer/" + # f = open(webServerDir + 'QGEarth.log', 'r') + # strings = f.readlines() + # west = float(strings[0]) + # south = float(strings[1]) + # east = float(strings[2]) + # north = float(strings[3]) + # lon = float(strings[4]) + # lat = float(strings[5]) + ## qrCodeUrl = strings[6] + ## img = qrcode.make('Some data here') + ## print img + # canvas = self.iface.mapCanvas() + # mapRenderer = canvas.mapRenderer() + # srs = mapRenderer.destinationCrs() + # crsSrc = QgsCoordinateReferenceSystem(4326) + # crsDest = QgsCoordinateReferenceSystem(srs) + # xform = QgsCoordinateTransform(crsSrc, crsDest) + # pt1 = xform.transform(QgsPoint(west, south)) + # pt2 = xform.transform(QgsPoint(east, north)) + # box = QgsRectangle(pt1.x(), pt1.y(), pt2.x(), pt2.y()) + # self.iface.mapCanvas().setExtent(box) + # self.iface.mapCanvas().refresh() + # f.close() + # ------- OLD CODE ------------------------------------------------------ + # ---------------------------------------------------- - salvalo2.close() - - vlayer = QgsVectorLayer(tempdir + "/GEKml_Lines.kml", "GEKml_Lines", "ogr") - QgsMapLayerRegistry.instance().addMapLayer(vlayer) - - - if (GEKml_Points > 0): - - salvalo2 = codecs.open(tempdir + "/GEKml_Points.kml", 'w', encoding='utf-8') - salvalo2.write (copyText) - - salvalo2.close() - - vlayer = QgsVectorLayer(tempdir + "/GEKml_Points.kml", "GEKml_Points", "ogr") - QgsMapLayerRegistry.instance().addMapLayer(vlayer) - - - -# ---------------------------------------------------- -# def startQrCoding(self): -# startGeoDrink_Server(self) - - - -# ------- OLD CODE ------------------------------------------------------ -# webServerDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()) + "python/plugins/gearthview/_WebServer/" -# f = open(webServerDir + 'QGEarth.log', 'r') -# strings = f.readlines() -# west = float(strings[0]) -# south = float(strings[1]) -# east = float(strings[2]) -# north = float(strings[3]) -# lon = float(strings[4]) -# lat = float(strings[5]) -## qrCodeUrl = strings[6] -## img = qrcode.make('Some data here') -## print img -# canvas = self.iface.mapCanvas() -# mapRenderer = canvas.mapRenderer() -# srs = mapRenderer.destinationCrs() -# crsSrc = QgsCoordinateReferenceSystem(4326) -# crsDest = QgsCoordinateReferenceSystem(srs) -# xform = QgsCoordinateTransform(crsSrc, crsDest) -# pt1 = xform.transform(QgsPoint(west, south)) -# pt2 = xform.transform(QgsPoint(east, north)) -# box = QgsRectangle(pt1.x(), pt1.y(), pt2.x(), pt2.y()) -# self.iface.mapCanvas().setExtent(box) -# self.iface.mapCanvas().refresh() -# f.close() -# ------- OLD CODE ------------------------------------------------------ - - - -# ---------------------------------------------------- def about(self): - infoString = QCoreApplication.translate('GEarthView', "GEarthView Plugin
This plugin displays QGis view into Google Earth.
Author: Bob MaX (aka: geodrinx)
Mail: geodrinx@gmail.com
Web: exporttocanoma.blogspot.it
.") -# infoString = QCoreApplication.translate('GEarthView', "GEarthView Plugin
This plugin displays QGis view into Google Earth.
Author: Bob MaX (aka: geodrinx)
Mail: geodrinx@gmail.com
Web: exporttocanoma.blogspot.it
" + "Do yo like this plugin? Please consider donating.") -# infoString = "GEarthView plugin \n\ndisplays QGis view into Google Earth\n\ntested on Windows and MacOSX\n\ngeodrinx@gmail.com" - QMessageBox.information(self.iface.mainWindow(), "About GEarthView plugin",infoString) + infoString = QCoreApplication.translate('GEarthView', + "GEarthView Plugin
This plugin displays QGis view into Google Earth.
Author: Bob MaX (aka: geodrinx)
Mail: geodrinx@gmail.com
Web: exporttocanoma.blogspot.it
.") + # infoString = QCoreApplication.translate('GEarthView', "GEarthView Plugin
This plugin displays QGis view into Google Earth.
Author: Bob MaX (aka: geodrinx)
Mail: geodrinx@gmail.com
Web: exporttocanoma.blogspot.it
" + "Do yo like this plugin? Please consider donating.") + # infoString = "GEarthView plugin \n\ndisplays QGis view into Google Earth\n\ntested on Windows and MacOSX\n\ngeodrinx@gmail.com" + QMessageBox.information(self.iface.mainWindow(), + "About GEarthView plugin", infoString) # def unload(self): # # Remove the plugin menu item and icon # self.iface.removePluginWebMenu(u"&GEarthView", self.action) -## self.iface.removePluginMenu(u"&GEarthView", self.PasteFromGEaction) +# self.iface.removePluginMenu(u"&GEarthView", self.PasteFromGEaction) # self.iface.removeToolBarIcon(self.action) - def doPaste(self,text): + def doPaste(self, text): text = str(text) QApplication.clipboard().setText(text) - msg = "Copied text: "+text[:30] + msg = "Copied text: " + text[:30] if len(text) > 30: - msg = msg + "... ("+str(len(text))+" chars)" + msg = msg + "... (" + str(len(text)) + " chars)" self.iface.mainWindow().statusBar().showMessage(msg) -# ------------------------------------------------------------------ + # ------------------------------------------------------------------ def QGEarth(self): QGEarth_addPoint(self) -# ------------------------------------------------------------------ + # ------------------------------------------------------------------ # run method that performs all the real work def run(self): - webServerDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()) + "/python/plugins/gearthview/_WebServer/" + webServerDir = unicode(QFileInfo( + QgsApplication.qgisUserDbFilePath()).path()) + "/python/plugins/gearthview/_WebServer/" - if ( serverStarted == 0) : - startGeoDrink_Server(self) + if (serverStarted == 0): + startGeoDrink_Server(self) else: -# if platform.system() == "Windows": -# os.startfile(webServerDir + 'QGIS_link.kmz') -# -# if platform.system() == "Darwin": -# os.system("open " + str(webServerDir + 'QGIS_link.kmz')) -# -# if platform.system() == "Linux": -# os.system("xdg-open " + str(webServerDir + 'QGIS_link.kmz')) -# - GDX_Publisher(self) - - # EndIf - - + # if platform.system() == "Windows": + # os.startfile(webServerDir + 'QGIS_link.kmz') + # + # if platform.system() == "Darwin": + # os.system("open " + str(webServerDir + 'QGIS_link.kmz')) + # + # if platform.system() == "Linux": + # os.system("xdg-open " + str(webServerDir + 'QGIS_link.kmz')) + # + GDX_Publisher(self) + + # EndIf