Skip to content

Commit

Permalink
Merge pull request #7 from pedrocamargo/python3
Browse files Browse the repository at this point in the history
Migration to QGIS 3.x
  • Loading branch information
pedrocamargo committed Oct 1, 2019
2 parents 643a527 + 98ed388 commit a7b5fea
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 223 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 120
max-complexity = 20
select = B,C,E,F,W,T4,B9
exclude = .idea,.git,__pycache__,sphinx,.venv,
75 changes: 75 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

# Created by https://www.gitignore.io/api/jetbrains

### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
.idea/rasterstats.iml
.idea/misc.xml
.idea/modules.xml
.idea/vcs.xml


# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Ruby plugin and RubyMine
/.rakeTasks

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### JetBrains Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint


# End of https://www.gitignore.io/api/jetbrains
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.7
args: [--line-length=120]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: flake8
12 changes: 8 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
/***************************************************************************
RasterStats for QGIS
Name: QGIS plgin iniitalizer
Name: QGIS plgin iniitalizer
-------------------
begin : 2014-03-19
copyright : Pedro Camargo
begin : 2014-03-19
edited : 2019-10-01
copyright : Pedro Camargo
Original Author: Pedro Camargo pedro@xl-optim.com
Contributors:
Licence: See LICENSE.TXT
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
import sys

sys.dont_write_bytecode = True


def classFactory(iface):
from rasterstats_menu import rasterstats_menu
from .rasterstats_menu import rasterstats_menu

return rasterstats_menu(iface)
2 changes: 0 additions & 2 deletions compile.bat

This file was deleted.

21 changes: 3 additions & 18 deletions metadata.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
; This file contains metadata for your plugin. Beginning
; with version 1.8 this is the preferred way to supply information about a
; plugin. The current method of embedding metadata in __init__.py will
; be supported until version 2.0

; This file should be included when you package your plugin.

; Mandatory items:


[general]
name=RasterStats
email=pedro@xl-optim.com
author=Pedro Camargo
qgisMinimumVersion=2.14
qgisMinimumVersion=2.99
qgisMaximumVersion=3.99
description=Raster Statistics toolbox for QGIS
about=This plugin is designed to return basic raster statistics regarding raster files for polygons in a given layer.
In addition to the tools that already exist in QGIS for computing raster statistics, this plugin allows for the computation of histograms for zones and provides a wider range of summary statistics (Average,Mean,Median,Standard deviation,Variance,Minimum and Maximum)
version=0.4.2
version=0.4.3
tracker=https://github.com/pedrocamargo/rasterstats/issues
repository=https://github.com/pedrocamargo/rasterstats
; end of mandatory metadata

; Optional items:

; Uncomment the following line and add your changelog entries:
; changelog=

; tags are comma separated with spaces allowed
tags=raster, statistics
Expand Down
96 changes: 0 additions & 96 deletions plugin_upload.py

This file was deleted.

57 changes: 35 additions & 22 deletions rasterstats_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Name: QGIS plgin iniitalizer
-------------------
Begin : 2014-03-19
Edit : 2018-02-11
Edit : 2019-10-01
Copyright : Pedro Camargo
Original Author: Pedro Camargo pedro@xl-optim.com
Contributors:
Expand All @@ -14,25 +14,29 @@
"""

import sys, os
from qgis.core import *
import qgis
from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.PyQt import QtWidgets, QtCore, QtGui, uic
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import QFileDialog

from .run_raster_statistics import RunMyRasterStatistics

from run_raster_statistics import RunMyRasterStatistics
from qgis.gui import QgsMapLayerProxyModel
# from qgis.gui import QgsMapLayerProxyModel

Qt = QtCore.Qt

sys.modules['qgsfieldcombobox'] = qgis.gui
sys.modules['qgsmaplayercombobox'] = qgis.gui
FORM_CLASS, _ = uic.loadUiType(os.path.join(os.path.dirname(__file__), 'ui_rasterstats_visualizer.ui'))
sys.modules["qgsfieldcombobox"] = qgis.gui
sys.modules["qgsmaplayercombobox"] = qgis.gui
FORM_CLASS, _ = uic.loadUiType(
os.path.join(os.path.dirname(__file__), "ui_rasterstats_visualizer.ui")
)


class open_rasterstats_class(QtGui.QDialog, FORM_CLASS):
class rasterstatsDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, iface):
QtGui.QDialog.__init__(self)
QtWidgets.QDialog.__init__(self)
self.iface = iface
self.setupUi(self)
self.decimals = 0
Expand All @@ -50,18 +54,21 @@ def __init__(self, iface):
self.but_close.clicked.connect(self.closewidget)

def browse_outputfile(self):
newname = QFileDialog.getSaveFileName(None, 'Output file', self.output_file.text(),
"Comma-separated file(*.csv)")
newname = QFileDialog.getSaveFileName(
self, "Output file", self.output_file.text(), "Comma-separated file(*.csv)"
)
if newname is None:
self.output_file.setText('')
self.output_file.setText("")
else:
self.output_file.setText(newname)
self.output_file.setText(newname[0])

def closewidget(self):
self.close()

def update_decimals(self):
self.label_decimals.setText('Histogram decimal places: ' + str(self.slider_decimals.value()))
self.label_decimals.setText(
"Histogram decimal places: " + str(self.slider_decimals.value())
)
self.decimals = self.slider_decimals.value()

def sets_histogram(self):
Expand All @@ -76,8 +83,8 @@ def ProgressValueFromThread(self, val):
self.progressbar.setValue(val)

def runThread(self):
QObject.connect(self.workerThread, SIGNAL("ProgressValue( PyQt_PyObject )"), self.ProgressValueFromThread)
QObject.connect(self.workerThread, SIGNAL("FinishedThreadedProcedure( PyQt_PyObject )"), self.closewidget)
self.workerThread.ProgressValue.connect(self.ProgressValueFromThread)
self.workerThread.finished_threaded_procedure.connect(self.closewidget)

self.workerThread.start()
self.exec_()
Expand All @@ -87,7 +94,13 @@ def run_stats(self):
if self.histogram.isChecked():
histogram = True

self.workerThread = RunMyRasterStatistics(qgis.utils.iface.mainWindow(), self.cob_polygon.currentLayer(),
self.cob_id.currentText(), self.cob_raster.currentLayer(),
self.output_file.text(), self.decimals, histogram)
self.workerThread = RunMyRasterStatistics(
qgis.utils.iface.mainWindow(),
self.cob_polygon.currentLayer(),
self.cob_id.currentText(),
self.cob_raster.currentLayer(),
self.output_file.text(),
self.decimals,
histogram,
)
self.runThread()
Loading

0 comments on commit a7b5fea

Please sign in to comment.