Skip to content

Commit

Permalink
updating to qgis 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lcoandrade committed Apr 5, 2018
1 parent 3ae371d commit 551ebd0
Show file tree
Hide file tree
Showing 17 changed files with 1,324 additions and 78 deletions.
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
from __future__ import absolute_import

def classFactory(iface):
# load AzimuthDistanceCalculator class from file AzimuthDistanceCalculator
from azimuthdistancecalculator import AzimuthDistanceCalculator
from .azimuthdistancecalculator import AzimuthDistanceCalculator
return AzimuthDistanceCalculator(iface)
27 changes: 27 additions & 0 deletions __init__.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
AzimuthDistanceCalculator
A QGIS plugin
Calculates azimuths and distances
-------------------
begin : 2014-09-24
copyright : (C) 2014 by Luiz Andrade
email : [email protected]
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""

def classFactory(iface):
# load AzimuthDistanceCalculator class from file AzimuthDistanceCalculator
from azimuthdistancecalculator import AzimuthDistanceCalculator
return AzimuthDistanceCalculator(iface)
15 changes: 9 additions & 6 deletions azimuthdistancecalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@
* *
***************************************************************************/
"""
from __future__ import absolute_import
from builtins import object
import os

from PyQt4.QtCore import QCoreApplication
from PyQt4.QtGui import QIcon, QAction
from PyQt4.QtCore import QSettings, QTranslator, qVersion
from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtCore import QSettings, QTranslator, qVersion

import resources_rc
from . import resources_rc

from azimuthdistancecalculatordialog import AzimuthDistanceCalculatorDialog
from .azimuthdistancecalculatordialog import AzimuthDistanceCalculatorDialog

try:
import ptvsd
ptvsd.enable_attach(secret='my_secret', address = ('localhost', 5679))
except:
pass

class AzimuthDistanceCalculator:
class AzimuthDistanceCalculator(object):
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
Expand Down
103 changes: 103 additions & 0 deletions azimuthdistancecalculator.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
AzimuthDistanceCalculator
A QGIS plugin
Calculates azimuths and distances
-------------------
begin : 2014-09-24
copyright : (C) 2014 by Luiz Andrade
email : [email protected]
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os

from PyQt4.QtCore import QCoreApplication
from PyQt4.QtGui import QIcon, QAction
from PyQt4.QtCore import QSettings, QTranslator, qVersion

import resources_rc

from azimuthdistancecalculatordialog import AzimuthDistanceCalculatorDialog

try:
import ptvsd
ptvsd.enable_attach(secret='my_secret', address = ('localhost', 5679))
except:
pass

class AzimuthDistanceCalculator:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value("locale/userLocale")[0:2]
localePath = os.path.join(self.plugin_dir, 'i18n', 'azimuthdistancecalculator_{}.qm'.format(locale))

if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)

if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)

# Create the dialog (after translation) and keep reference
self.dlg = AzimuthDistanceCalculatorDialog(self.iface)

# Obtaining the map canvas
self.canvas = iface.mapCanvas()

# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.

We implement this ourselves since we do not inherit QObject.

:param message: String for translation.
:type message: str, QString

:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('azimuthdistancecalculator', message)

def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(
QIcon(":/plugins/azimuthdistancecalculator/north.png"),
self.tr("Calculator"), self.iface.mainWindow())
# connect the action to the run method
self.action.triggered.connect(self.run)

# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(self.tr("Azimuth and Distance Calculator"), self.action)

def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu(self.tr("Azimuth and Distance Calculator"), self.action)
self.iface.removeToolBarIcon(self.action)

# run method that performs all the real work
def run(self):
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result == 1:
# do something useful (delete the line containing pass and
# substitute with your code)
pass
9 changes: 5 additions & 4 deletions azimuthdistancecalculatordialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
* *
***************************************************************************/
"""
from __future__ import absolute_import
import os

from PyQt4 import uic
from PyQt4.QtGui import QMessageBox, QDialog
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QMessageBox, QDialog

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'ui_azimuthdistancecalculator.ui'))

# Import specific modules
from AzimuthDistanceCalculator.kappaAndConvergence.calculateKappaAndConvergence import CalculateKappaAndConvergenceDialog
from AzimuthDistanceCalculator.azimuthsAndDistances.azimuthsAndDistances import AzimuthsAndDistancesDialog
from .kappaAndConvergence.calculateKappaAndConvergence import CalculateKappaAndConvergenceDialog
from .azimuthsAndDistances.azimuthsAndDistances import AzimuthsAndDistancesDialog

class AzimuthDistanceCalculatorDialog(QDialog, FORM_CLASS):
def __init__(self, iface):
Expand Down
71 changes: 71 additions & 0 deletions azimuthdistancecalculatordialog.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
AzimuthDistanceCalculatorDialog
A QGIS plugin
Calculates azimuths and distances
-------------------
begin : 2014-09-24
copyright : (C) 2014 by Luiz Andrade
email : [email protected]
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os

from PyQt4 import uic
from PyQt4.QtGui import QMessageBox, QDialog

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'ui_azimuthdistancecalculator.ui'))

# Import specific modules
from AzimuthDistanceCalculator.kappaAndConvergence.calculateKappaAndConvergence import CalculateKappaAndConvergenceDialog
from AzimuthDistanceCalculator.azimuthsAndDistances.azimuthsAndDistances import AzimuthsAndDistancesDialog

class AzimuthDistanceCalculatorDialog(QDialog, FORM_CLASS):
def __init__(self, iface):
QDialog.__init__(self)
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)

self.iface = iface

# Connecting SIGNAL/SLOTS for the Output button
self.kappaAndConvergenceButton.clicked.connect(self.calculateKappa)

# Connecting SIGNAL/SLOTS for the Output button
self.azimuthsAndDistancesButton.clicked.connect(self.calculateAzimuths)

def calculateKappa(self):
currentLayer = self.iface.mapCanvas().currentLayer()
if currentLayer:
d = CalculateKappaAndConvergenceDialog(self.iface)
d.exec_()
else:
QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("Please, open a layer and select a line or polygon feature."))

def calculateAzimuths(self):
currentLayer = self.iface.mapCanvas().currentLayer()
if currentLayer:
selectedFeatures = len(currentLayer.selectedFeatures())
if selectedFeatures == 1:
selectedFeature = currentLayer.selectedFeatures()[0]
d = AzimuthsAndDistancesDialog(self.iface, selectedFeature.geometry())
d.exec_()
else:
QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("One and only one feature must be selected to perform the calculations."))
else:
QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("Please, open a layer and select a line or polygon feature."))
24 changes: 13 additions & 11 deletions azimuthsAndDistances/azimuthsAndDistances.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
* *
***************************************************************************/
"""
from builtins import str
from builtins import range
import os
from PyQt4 import uic
from PyQt4.QtGui import QDialog, QTableWidgetItem, QMessageBox
from qgis.core import QGis, QgsGeometry
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QDialog, QTableWidgetItem, QMessageBox
from qgis.core import QgsWkbTypes, QgsGeometry

import math
from decimal import Decimal

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'ui_azimuthsAndDistances.ui'))

from AzimuthDistanceCalculator.azimuthsAndDistances.memorialGenerator import MemorialGenerator
from AzimuthDistanceCalculator.kappaAndConvergence.calculateKappaAndConvergence import CalculateKappaAndConvergenceDialog
from .memorialGenerator import MemorialGenerator
from ..kappaAndConvergence.calculateKappaAndConvergence import CalculateKappaAndConvergenceDialog

class AzimuthsAndDistancesDialog(QDialog, FORM_CLASS):
"""Class that calculates azimuths and distances among vertexes in a linestring.
Expand Down Expand Up @@ -75,7 +77,7 @@ def calculateConvergence(self):

def setClockWiseRotation(self, points):
sum = 0
for i in xrange(len(points) - 1):
for i in range(len(points) - 1):
sum += (points[i+1].x() - points[i].x())*(points[i+1].y() + points[i].y())

if sum > 0:
Expand All @@ -101,7 +103,7 @@ def saveFiles(self):
QMessageBox.information(self.iface.mainWindow(), self.tr("Warning!"), self.tr("Click on calculate button first to generate the needed data."))
else:
confrontingList = list()
for i in xrange(self.tableWidget.rowCount()):
for i in range(self.tableWidget.rowCount()):
item = self.tableWidget.item(i, 7)
confrontingList.append(item.text())

Expand All @@ -115,12 +117,12 @@ def isValidType(self):
QMessageBox.information(self.iface.mainWindow(), self.tr("Warning!"), self.tr("The limit of a patrimonial area must be a single part geometry."))
return False

if self.geom.type() == QGis.Line:
if self.geom.type() == QgsWkbTypes.LineGeometry:
self.points = self.geom.asPolyline()
if self.points[0].y() < self.points[-1].y():
self.points = self.points[::-1]
return True
elif self.geom.type() == QGis.Polygon:
elif self.geom.type() == QgsWkbTypes.PolygonGeometry:
points = self.setClockWiseRotation(self.geom.asPolygon()[0])
yMax = self.geom.boundingBox().yMaximum()
self.points = self.setFirstPointToNorth(points, yMax)
Expand All @@ -134,7 +136,7 @@ def calculate(self):
"""
self.perimeter = 0
self.distancesAndAzimuths = list()
for i in xrange(0,len(self.points)-1):
for i in range(0,len(self.points)-1):
before = self.points[i]
after = self.points[i+1]
distance = math.sqrt(before.sqrDist(after))
Expand Down Expand Up @@ -168,7 +170,7 @@ def fillTable(self):

self.tableWidget.setRowCount(len(distancesAndAzimuths))

for i in xrange(0,len(distancesAndAzimuths)):
for i in range(0,len(distancesAndAzimuths)):
azimuth = self.dd2dms(distancesAndAzimuths[i][1])
realAzimuth = self.dd2dms(distancesAndAzimuths[i][1] + convergence)

Expand Down
Loading

0 comments on commit 551ebd0

Please sign in to comment.