Skip to content

Commit 5681a56

Browse files
committed
updating to QGIS3
1 parent 44a75de commit 5681a56

21 files changed

+255
-81
lines changed

.vscode/launch.json

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Current File",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${file}"
12+
},
13+
{
14+
"name": "Python: Attach",
15+
"type": "python",
16+
"request": "attach",
17+
"localRoot": "${workspaceFolder}",
18+
"remoteRoot": "${workspaceFolder}",
19+
"port": 5679,
20+
"secret": "my_secret",
21+
"host": "localhost"
22+
},
23+
{
24+
"name": "Python: Terminal (integrated)",
25+
"type": "python",
26+
"request": "launch",
27+
"program": "${file}",
28+
"console": "integratedTerminal"
29+
},
30+
{
31+
"name": "Python: Terminal (external)",
32+
"type": "python",
33+
"request": "launch",
34+
"program": "${file}",
35+
"console": "externalTerminal"
36+
},
37+
{
38+
"name": "Python: Django",
39+
"type": "python",
40+
"request": "launch",
41+
"program": "${workspaceFolder}/manage.py",
42+
"args": [
43+
"runserver",
44+
"--noreload",
45+
"--nothreading"
46+
],
47+
"debugOptions": [
48+
"RedirectOutput",
49+
"Django"
50+
]
51+
},
52+
{
53+
"name": "Python: Flask (0.11.x or later)",
54+
"type": "python",
55+
"request": "launch",
56+
"module": "flask",
57+
"env": {
58+
"FLASK_APP": "${workspaceFolder}/app.py"
59+
},
60+
"args": [
61+
"run",
62+
"--no-debugger",
63+
"--no-reload"
64+
]
65+
},
66+
{
67+
"name": "Python: Module",
68+
"type": "python",
69+
"request": "launch",
70+
"module": "module.name"
71+
},
72+
{
73+
"name": "Python: Pyramid",
74+
"type": "python",
75+
"request": "launch",
76+
"args": [
77+
"${workspaceFolder}/development.ini"
78+
],
79+
"debugOptions": [
80+
"RedirectOutput",
81+
"Pyramid"
82+
]
83+
},
84+
{
85+
"name": "Python: Watson",
86+
"type": "python",
87+
"request": "launch",
88+
"program": "${workspaceFolder}/console.py",
89+
"args": [
90+
"dev",
91+
"runserver",
92+
"--noreload=True"
93+
]
94+
},
95+
{
96+
"name": "Python: All debug Options",
97+
"type": "python",
98+
"request": "launch",
99+
"pythonPath": "${config:python.pythonPath}",
100+
"program": "${file}",
101+
"module": "module.name",
102+
"env": {
103+
"VAR1": "1",
104+
"VAR2": "2"
105+
},
106+
"envFile": "${workspaceFolder}/.env",
107+
"args": [
108+
"arg1",
109+
"arg2"
110+
],
111+
"debugOptions": [
112+
"RedirectOutput"
113+
]
114+
}
115+
]
116+
}

__pycache__/__init__.cpython-36.pyc

1.68 KB
Binary file not shown.
6.66 KB
Binary file not shown.
5.37 KB
Binary file not shown.
5.71 KB
Binary file not shown.
4.19 KB
Binary file not shown.
5.85 KB
Binary file not shown.

metadata.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
[general]
1010
name=OSMDownloader
11-
qgisMinimumVersion=2.0
11+
qgisMinimumVersion=3.0
1212
description=Plugin to download OSM data by area, using a selection by rectangle. The plugin can also automatically load the osm file into QGIS in a transparent way.
13-
version=0.5
13+
version=1.0
1414
author=Luiz Andrade
1515
email=lcoandrade@gmail.com
1616

osmDownloader.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@
2020
* *
2121
***************************************************************************/
2222
"""
23-
from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication
24-
from PyQt4.QtGui import QAction, QIcon
23+
from __future__ import absolute_import
24+
from builtins import object
25+
from qgis.PyQt.QtCore import QSettings, QTranslator, qVersion, QCoreApplication
26+
from qgis.PyQt.QtWidgets import QAction
27+
from qgis.PyQt.QtGui import QIcon
2528
# Initialize Qt resources from file resources.py
26-
import resources_rc
29+
from . import resources_rc
2730
# Import the code for the dialog
28-
from osmDownloader_dialog import OSMDownloaderDialog
31+
from .osmDownloader_dialog import OSMDownloaderDialog
2932
import os.path
3033

31-
from rectangleAreaTool import RectangleAreaTool
34+
from .rectangleAreaTool import RectangleAreaTool
3235

36+
try:
37+
import ptvsd
38+
ptvsd.enable_attach(secret='my_secret', address = ('localhost', 5679))
39+
except:
40+
pass
3341

34-
class OSMDownloader:
42+
class OSMDownloader(object):
3543
"""QGIS Plugin Implementation."""
3644

3745
def __init__(self, iface):

osmDownloader_dialog.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,22 @@
2020
* *
2121
***************************************************************************/
2222
"""
23+
from __future__ import absolute_import
2324

25+
from builtins import str
2426
import os
2527

26-
from PyQt4 import QtGui, uic
27-
from PyQt4.QtCore import pyqtSlot, QThreadPool, Qt
28+
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QProgressBar
29+
from qgis.PyQt import uic
30+
from qgis.PyQt.QtCore import pyqtSlot, QThreadPool, Qt
31+
from qgis.core import Qgis
2832

2933
FORM_CLASS, _ = uic.loadUiType(os.path.join(
3034
os.path.dirname(__file__), 'osmDownloader_dialog_base.ui'))
3135

32-
from osm_downloader import OSMRequest
36+
from .osm_downloader import OSMRequest
3337

34-
35-
class OSMDownloaderDialog(QtGui.QDialog, FORM_CLASS):
38+
class OSMDownloaderDialog(QDialog, FORM_CLASS):
3639
def __init__(self, iface, startX, startY, endX, endY, parent=None):
3740
"""Constructor."""
3841
super(OSMDownloaderDialog, self).__init__(parent)
@@ -73,7 +76,8 @@ def setCoordinates(self, startX, startY, endX, endY):
7376

7477
@pyqtSlot()
7578
def on_saveButton_clicked(self):
76-
fileName = QtGui.QFileDialog.getSaveFileName(parent=None, caption='Define file name and location', filter='OSM Files(*.osm)')
79+
ret = QFileDialog.getSaveFileName(parent=None, caption='Define file name and location', filter='OSM Files(*.osm)')
80+
fileName = ret[0]
7781

7882
split = fileName.split('.')
7983
if len(split)>0 and split[-1] == 'osm':
@@ -86,7 +90,7 @@ def on_saveButton_clicked(self):
8690
@pyqtSlot()
8791
def on_button_box_accepted(self):
8892
if self.filenameEdit.text() == '':
89-
QtGui.QMessageBox.warning(self, self.tr("Warning!"), self.tr("Please, select a location to save the file."))
93+
QMessageBox.warning(self, self.tr("Warning!"), self.tr("Please, select a location to save the file."))
9094
return
9195

9296
# Initiating processing
@@ -100,10 +104,10 @@ def on_button_box_accepted(self):
100104
osmRequest.signals.userCanceled.connect(self.userCanceled)
101105
# Setting the progress bar
102106
self.progressMessageBar = self.iface.messageBar().createMessage('Downloading data...')
103-
self.progressBar = QtGui.QProgressBar()
107+
self.progressBar = QProgressBar()
104108
self.progressBar.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)
105109
self.progressMessageBar.layout().addWidget(self.progressBar)
106-
self.iface.messageBar().pushWidget(self.progressMessageBar, self.iface.messageBar().INFO)
110+
self.iface.messageBar().pushWidget(self.progressMessageBar, Qgis.Info)
107111
self.progressBar.setRange(0, 0)
108112
self.progressMessageBar.destroyed.connect(osmRequest.signals.cancel)
109113
# Starting process
@@ -115,12 +119,12 @@ def proxy(self, proxy):
115119

116120
@pyqtSlot(str)
117121
def errorOccurred(self, message):
118-
QtGui.QMessageBox.warning(self, 'Fatal!', message)
122+
QMessageBox.warning(self, 'Fatal!', message)
119123
self.close()
120124

121125
@pyqtSlot()
122126
def userCanceled(self):
123-
QtGui.QMessageBox.warning(self, 'Info!', 'Process canceled by user!')
127+
QMessageBox.warning(self, 'Info!', 'Process canceled by user!')
124128
self.close()
125129

126130
@pyqtSlot(float)
@@ -133,7 +137,7 @@ def processFinished(self, message):
133137
self.progressBar.setRange(0, 100)
134138
self.progressBar.setValue(100)
135139
self.progressMessageBar.setText('Downloaded '+"{0:.2f}".format(self.size)+' megabytes in total from OSM servers')
136-
QtGui.QMessageBox.warning(self, 'Info!', message)
140+
QMessageBox.warning(self, 'Info!', message)
137141

138142
if self.checkBox.isChecked():
139143
self.iface.addVectorLayer(self.filenameEdit.text(), 'osm_data', 'ogr')

osm_downloader.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
"""
2323

2424
#Another way to do the Job with OVERPASS
25-
import urllib2
26-
from PyQt4.QtCore import QRunnable, QObject, pyqtSignal, QSettings, pyqtSlot
27-
from PyQt4.Qt import QThreadPool, QApplication
25+
from future import standard_library
26+
standard_library.install_aliases()
27+
from builtins import str
28+
import urllib.request, urllib.error, urllib.parse
29+
from qgis.PyQt.QtCore import QObject, pyqtSignal, QSettings, pyqtSlot, QThreadPool, QRunnable
2830
import time
2931
import sys
3032

@@ -82,11 +84,12 @@ def setUrllibProxy(self):
8284
return
8385

8486
proxyStr = 'http://'+user+':'+password+'@'+host+':'+port
87+
print(proxyStr)
8588
self.signals.proxyOpened.emit(host+'| Port: '+port)
8689

87-
proxy = urllib2.ProxyHandler({'http': proxyStr})
88-
opener = urllib2.build_opener(proxy, urllib2.HTTPHandler)
89-
urllib2.install_opener(opener)
90+
proxy = urllib.request.ProxyHandler({'http': proxyStr})
91+
opener = urllib.request.build_opener(proxy, urllib.request.HTTPHandler)
92+
urllib.request.install_opener(opener)
9093

9194
def setParameters(self, minLong, minLat, maxLong, maxLat):
9295
self.minLong = minLong
@@ -99,12 +102,13 @@ def makePostFile(self):
99102
xmlData = xmlData.replace('maxlat', str(self.maxLat))
100103
xmlData = xmlData.replace('minlong', str(self.minLong))
101104
xmlData = xmlData.replace('minlat', str(self.minLat))
105+
xmlData = xmlData.encode('utf-8')
102106
return xmlData
103107

104108
def makeRequest(self):
105109
osmUrl = 'http://overpass-api.de/api/interpreter'
106110
postFile = self.makePostFile()
107-
req = urllib2.Request(url=osmUrl, data=postFile, headers={'Content-Type': 'application/xml'})
111+
req = urllib.request.Request(url=osmUrl, data=postFile, headers={'Content-Type': 'application/xml'})
108112
return req
109113

110114
def run(self):
@@ -113,11 +117,11 @@ def run(self):
113117
req = self.makeRequest()
114118

115119
try:
116-
response = urllib2.urlopen(req)
117-
except urllib2.URLError, e:
120+
response = urllib.request.urlopen(req)
121+
except urllib.error.URLError as e:
118122
self.signals.errorOccurred.emit('Error occurred: '+str(e.args) + '\nReason: '+str(e.reason))
119123
return
120-
except urllib2.HTTPError, e:
124+
except urllib.error.HTTPError as e:
121125
self.signals.errorOccurred.emit('Error occurred: '+str(e.code) + '\nReason: '+str(e.msg))
122126
return
123127

plugin_upload.py

+36-19
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
Authors: A. Pasotti, V. Picavet
55
git sha : $TemplateVCSFormat
66
"""
7+
from __future__ import print_function
78

9+
from future import standard_library
10+
standard_library.install_aliases()
11+
from builtins import input
812
import sys
913
import getpass
10-
import xmlrpclib
14+
import xmlrpc.client
1115
from optparse import OptionParser
1216

1317
# Configuration
@@ -31,25 +35,36 @@ def main(parameters, arguments):
3135
parameters.server,
3236
parameters.port,
3337
ENDPOINT)
34-
print "Connecting to: %s" % hide_password(address)
38+
# fix_print_with_import
39+
print("Connecting to: %s" % hide_password(address))
3540

36-
server = xmlrpclib.ServerProxy(address, verbose=VERBOSE)
41+
server = xmlrpc.client.ServerProxy(address, verbose=VERBOSE)
3742

3843
try:
3944
plugin_id, version_id = server.plugin.upload(
40-
xmlrpclib.Binary(open(arguments[0]).read()))
41-
print "Plugin ID: %s" % plugin_id
42-
print "Version ID: %s" % version_id
43-
except xmlrpclib.ProtocolError, err:
44-
print "A protocol error occurred"
45-
print "URL: %s" % hide_password(err.url, 0)
46-
print "HTTP/HTTPS headers: %s" % err.headers
47-
print "Error code: %d" % err.errcode
48-
print "Error message: %s" % err.errmsg
49-
except xmlrpclib.Fault, err:
50-
print "A fault occurred"
51-
print "Fault code: %d" % err.faultCode
52-
print "Fault string: %s" % err.faultString
45+
xmlrpc.client.Binary(open(arguments[0]).read()))
46+
# fix_print_with_import
47+
print("Plugin ID: %s" % plugin_id)
48+
# fix_print_with_import
49+
print("Version ID: %s" % version_id)
50+
except xmlrpc.client.ProtocolError as err:
51+
# fix_print_with_import
52+
print("A protocol error occurred")
53+
# fix_print_with_import
54+
print("URL: %s" % hide_password(err.url, 0))
55+
# fix_print_with_import
56+
print("HTTP/HTTPS headers: %s" % err.headers)
57+
# fix_print_with_import
58+
print("Error code: %d" % err.errcode)
59+
# fix_print_with_import
60+
print("Error message: %s" % err.errmsg)
61+
except xmlrpc.client.Fault as err:
62+
# fix_print_with_import
63+
print("A fault occurred")
64+
# fix_print_with_import
65+
print("Fault code: %d" % err.faultCode)
66+
# fix_print_with_import
67+
print("Fault string: %s" % err.faultString)
5368

5469

5570
def hide_password(url, start=6):
@@ -85,7 +100,8 @@ def hide_password(url, start=6):
85100
help="Specify server name", metavar="plugins.qgis.org")
86101
options, args = parser.parse_args()
87102
if len(args) != 1:
88-
print "Please specify zip file.\n"
103+
# fix_print_with_import
104+
print("Please specify zip file.\n")
89105
parser.print_help()
90106
sys.exit(1)
91107
if not options.server:
@@ -95,8 +111,9 @@ def hide_password(url, start=6):
95111
if not options.username:
96112
# interactive mode
97113
username = getpass.getuser()
98-
print "Please enter user name [%s] :" % username,
99-
res = raw_input()
114+
# fix_print_with_import
115+
print("Please enter user name [%s] :" % username, end=' ')
116+
res = input()
100117
if res != "":
101118
options.username = res
102119
else:

0 commit comments

Comments
 (0)