Skip to content

Commit

Permalink
vers. 1.3 for QGIS 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroalberti committed Jul 20, 2018
1 parent 1839553 commit 115bdf2
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 33 deletions.
25 changes: 16 additions & 9 deletions DirectionalSlope.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-------------------
begin : 2011-10-25
version : 2017-06-18 (1.2.1), QGIS 2.0 compatible
copyright : (C) 2011-2017 by Mauro Alberti - www.malg.eu
copyright : (C) 2011-2018 by Mauro Alberti
email : [email protected]
***************************************************************************/
Expand All @@ -20,18 +20,25 @@
***************************************************************************/
"""

from __future__ import absolute_import


from builtins import str
from builtins import object

from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *

import resources
from . import resources

from .DirectionalSlope_dialog import DirectionalSlopeDialog
from .DirectionalSlope_classes import *


class DirectionalSlope:
class DirectionalSlope(object):


def __init__(self, iface):
Expand Down Expand Up @@ -73,9 +80,9 @@ def run(self):

# append loaded raster layers to combo boxes

self.layermap = QgsMapLayerRegistry.instance().mapLayers()
self.layermap = QgsProject.instance().mapLayers()

for (name,layer) in self.layermap.iteritems():
for (name,layer) in list(self.layermap.items()):
if layer.type() == QgsMapLayer.RasterLayer:
dlg.InputDem_combobox.addItem(layer.name())
dlg.VariableOrientations_raster_cb.addItem(layer.name())
Expand Down Expand Up @@ -150,7 +157,7 @@ def run(self):
# define Input DEM file

dem_layer = None
for (name,layer) in self.layermap.iteritems():
for (name,layer) in list(self.layermap.items()):
if layer.name() == dem_name:
dem_layer = layer
break
Expand Down Expand Up @@ -215,7 +222,7 @@ def run(self):
"Variable directional analysis",
"No raster provided")
return
for (name,layer) in self.layermap.iteritems():
for (name,layer) in list(self.layermap.items()):
if layer.name() == vardirectgrid_name:
vardirectgrid_layer = layer
break
Expand Down
18 changes: 11 additions & 7 deletions DirectionalSlope_classes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@


from builtins import str
from builtins import range
from builtins import object

import os
from math import *
import numpy as np
Expand All @@ -8,7 +12,7 @@


# 2D Array coordinates
class ArrCoord:
class ArrCoord(object):

def __init__(self, ival, jval):
self.i = ival
Expand All @@ -25,7 +29,7 @@ def get_j(self):
return self.j


class Point:
class Point(object):
"""3D point class"""

def __init__(self, x, y, z=0.0):
Expand All @@ -44,7 +48,7 @@ def movedby(self, sx, sy):
return Point( self.x + sx , self.y + sy)


class GDALParameters:
class GDALParameters(object):
"""GDAL raster parameters"""

def __init__(self):
Expand Down Expand Up @@ -218,7 +222,7 @@ class SlopeErrors(Exception):
pass


class SpatialDomain:
class SpatialDomain(object):
"""Rectangular spatial domain class"""

def __init__(self, pt_init, pt_end):
Expand Down Expand Up @@ -257,7 +261,7 @@ def get_horiz_area(self):
return self.get_xrange()*self.get_yrange()


class Grid:
class Grid(object):

def __init__(self):

Expand Down Expand Up @@ -604,8 +608,8 @@ def calculate_paired_values(dem_grid, vardir_grid):

paired_values = np.zeros((dem_grid.get_ylines_num()-2, dem_grid.get_xlines_num()-2))*np.NaN

for i in xrange(paired_values.shape[0]):
for j in xrange(paired_values.shape[1]):
for i in range(paired_values.shape[0]):
for j in range(paired_values.shape[1]):

# offset between grid dem cell corner and paired_values cell center, in grid coordinates
offset_dem_array = 1.5
Expand Down
7 changes: 4 additions & 3 deletions DirectionalSlope_dialog.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-


from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *


class DirectionalSlopeDialog(QDialog):
Expand Down Expand Up @@ -254,7 +255,7 @@ def setupAboutTab(self):
"</style></head><body style=\" font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Directional Slope </span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span> Vers. 1.2.0 - October, 24, 2013.</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span> Vers. 1.3 - July, 20, 2018.</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span> Created by Mauro Alberti - </span><a href=\"mailto:[email protected]\"><span style=\" text-decoration: underline; color:#0000ff;\">[email protected]</span></a></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span> License: GPL vers. 3.</span></p>\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p>\n"
Expand Down
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

from DirectionalSlope import DirectionalSlope
from .DirectionalSlope import DirectionalSlope


def classFactory(iface):
Expand Down
1 change: 1 addition & 0 deletions gitignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ ENV/
*/.directory
*.pyc
.idea/
*.bak
File renamed without changes
7 changes: 4 additions & 3 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name=DirectionalSlope
description=Calculates directional slope along given and variable orientations
about=This plugin allows to calculate directional slope along uniform or spatially-variable orientations, from a source DEM
category=Plugins
version=1.2.1
version=1.3
experimental=False
qgisMinimumVersion=2.0
qgisMinimumVersion=3.0
author=Mauro Alberti
[email protected]
icon=./icon.png
Expand All @@ -16,7 +16,8 @@ repository=https://github.com/mauroalberti/directionalslope
changelog=
1.2.0: version compatible with QGis 2.0
1.2.1: corrected erroneous concept in Help; minor code reformatting

1.3 : ported to QGIS3

; tags are in comma separated value format, spaces are allowed
tags=directional slope,dem,geomorphology

43 changes: 34 additions & 9 deletions resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

# Resource object code
#
# Created: Tue Sep 4 09:16:59 2012
# by: The Resource Compiler for PyQt (Qt v4.8.1)
# Created by: The Resource Compiler for PyQt5 (Qt v5.9.3)
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore
from PyQt5 import QtCore

qt_resource_data = "\
qt_resource_data = b"\
\x00\x00\x05\x18\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
Expand Down Expand Up @@ -96,7 +95,7 @@
\x45\x4e\x44\xae\x42\x60\x82\
"

qt_resource_name = "\
qt_resource_name = b"\
\x00\x07\
\x07\x3b\xe0\xb3\
\x00\x70\
Expand All @@ -105,23 +104,49 @@
\x03\x61\x78\xc5\
\x00\x44\
\x00\x69\x00\x72\x00\x65\x00\x63\x00\x74\x00\x69\x00\x6f\x00\x6e\x00\x61\x00\x6c\x00\x53\x00\x6c\x00\x6f\x00\x70\x00\x65\
\x00\x05\
\x00\x6f\xa6\x53\
\x00\x69\
\x00\x63\x00\x6f\x00\x6e\x00\x73\
\x00\x08\
\x0a\x61\x5a\xa7\
\x00\x69\
\x00\x63\x00\x6f\x00\x6e\x00\x2e\x00\x70\x00\x6e\x00\x67\
"

qt_resource_struct = "\
qt_resource_struct_v1 = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
\x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\
\x00\x00\x00\x3a\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x00\x3a\x00\x02\x00\x00\x00\x01\x00\x00\x00\x04\
\x00\x00\x00\x4a\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
"

qt_resource_struct_v2 = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x3a\x00\x02\x00\x00\x00\x01\x00\x00\x00\x04\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x4a\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x64\xa4\x7f\x54\xb7\
"

qt_version = QtCore.qVersion().split('.')
if qt_version < ['5', '8', '0']:
rcc_version = 1
qt_resource_struct = qt_resource_struct_v1
else:
rcc_version = 2
qt_resource_struct = qt_resource_struct_v2

def qInitResources():
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)

def qCleanupResources():
QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)

qInitResources()
2 changes: 1 addition & 1 deletion resources.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/plugins/DirectionalSlope" >
<file>icon.png</file>
<file>icons/icon.png</file>
</qresource>
</RCC>

0 comments on commit 115bdf2

Please sign in to comment.