Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set minimum distance for euclidean distance #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions core/uis/Geoprocessing_ui/EuclideanDistance.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>400</height>
<width>580</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -95,9 +95,6 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLineEdit" name="inputFeatureLineEdit"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="inputFeatureDatasetLabel">
<property name="text">
Expand All @@ -119,6 +116,9 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QLineEdit" name="inputFeatureLineEdit"/>
</item>
</layout>
</item>
</layout>
Expand All @@ -139,34 +139,48 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="optionalSettingsGroupBoxGridLayout">
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="fixedBufferValueLabel">
<property name="text">
<string>Fixed buffer value</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="minimumDistanceLabel">
<property name="text">
<string>Minimum distance</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="maximumDistanceLabel">
<property name="text">
<string>Maximum distance</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLineEdit" name="maximumDistanceLineEdit">
<property name="toolTip">
<string>The maximum distance to be generated. The nodata value will be used for pixels beyond this distance. </string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0">
<widget class="QLineEdit" name="fixedBufferValueLineEdit">
<property name="toolTip">
<string>Specify a value to be applied to all pixels that are within the -maxdist of target pixels (including the target pixels) instead of a distance value</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="minimumDistanceLineEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand All @@ -181,8 +195,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>18</height>
<width>580</width>
<height>21</height>
</rect>
</property>
</widget>
Expand Down
31 changes: 20 additions & 11 deletions core/uis/Geoprocessing_ui/EuclideanDistance_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# Form implementation generated from reading ui file '.\EuclideanDistance.ui'
#
# Created by: PyQt5 UI code generator 5.14.2
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING! All changes made in this file will be lost!
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
Expand All @@ -13,7 +14,7 @@
class Ui_EuclideanDistanceForm(object):
def setupUi(self, EuclideanDistanceForm):
EuclideanDistanceForm.setObjectName("EuclideanDistanceForm")
EuclideanDistanceForm.resize(540, 400)
EuclideanDistanceForm.resize(580, 450)
self.centralwidget = QtWidgets.QWidget(EuclideanDistanceForm)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
Expand Down Expand Up @@ -56,9 +57,6 @@ def setupUi(self, EuclideanDistanceForm):
self.maskRasterToolButton.setEnabled(False)
self.maskRasterToolButton.setObjectName("maskRasterToolButton")
self.inputDataGroupBoxGridLayout.addWidget(self.maskRasterToolButton, 4, 3, 1, 1)
self.inputFeatureLineEdit = QtWidgets.QLineEdit(self.inputDataGroupBox)
self.inputFeatureLineEdit.setObjectName("inputFeatureLineEdit")
self.inputDataGroupBoxGridLayout.addWidget(self.inputFeatureLineEdit, 1, 0, 1, 2)
self.inputFeatureDatasetLabel = QtWidgets.QLabel(self.inputDataGroupBox)
self.inputFeatureDatasetLabel.setObjectName("inputFeatureDatasetLabel")
self.inputDataGroupBoxGridLayout.addWidget(self.inputFeatureDatasetLabel, 0, 0, 1, 1)
Expand All @@ -69,6 +67,9 @@ def setupUi(self, EuclideanDistanceForm):
self.maskRasterLineEdit.setEnabled(False)
self.maskRasterLineEdit.setObjectName("maskRasterLineEdit")
self.inputDataGroupBoxGridLayout.addWidget(self.maskRasterLineEdit, 4, 0, 1, 3)
self.inputFeatureLineEdit = QtWidgets.QLineEdit(self.inputDataGroupBox)
self.inputFeatureLineEdit.setObjectName("inputFeatureLineEdit")
self.inputDataGroupBoxGridLayout.addWidget(self.inputFeatureLineEdit, 1, 0, 1, 3)
self.horizontalLayout.addLayout(self.inputDataGroupBoxGridLayout)
self.mainGridLayout.addWidget(self.inputDataGroupBox, 0, 0, 1, 2)
self.applyPushButton = QtWidgets.QPushButton(self.centralwidget)
Expand All @@ -82,22 +83,29 @@ def setupUi(self, EuclideanDistanceForm):
self.optionalSettingsGroupBoxGridLayout.setObjectName("optionalSettingsGroupBoxGridLayout")
self.fixedBufferValueLabel = QtWidgets.QLabel(self.optionalSettingsGroupBox)
self.fixedBufferValueLabel.setObjectName("fixedBufferValueLabel")
self.optionalSettingsGroupBoxGridLayout.addWidget(self.fixedBufferValueLabel, 2, 0, 1, 1)
self.optionalSettingsGroupBoxGridLayout.addWidget(self.fixedBufferValueLabel, 4, 0, 1, 1)
self.minimumDistanceLabel = QtWidgets.QLabel(self.optionalSettingsGroupBox)
self.minimumDistanceLabel.setObjectName("minimumDistanceLabel")
self.optionalSettingsGroupBoxGridLayout.addWidget(self.minimumDistanceLabel, 0, 0, 1, 1)
self.maximumDistanceLabel = QtWidgets.QLabel(self.optionalSettingsGroupBox)
self.maximumDistanceLabel.setObjectName("maximumDistanceLabel")
self.optionalSettingsGroupBoxGridLayout.addWidget(self.maximumDistanceLabel, 0, 0, 1, 1)
self.optionalSettingsGroupBoxGridLayout.addWidget(self.maximumDistanceLabel, 2, 0, 1, 1)
self.maximumDistanceLineEdit = QtWidgets.QLineEdit(self.optionalSettingsGroupBox)
self.maximumDistanceLineEdit.setObjectName("maximumDistanceLineEdit")
self.optionalSettingsGroupBoxGridLayout.addWidget(self.maximumDistanceLineEdit, 1, 0, 1, 1)
self.optionalSettingsGroupBoxGridLayout.addWidget(self.maximumDistanceLineEdit, 3, 0, 1, 1)
self.fixedBufferValueLineEdit = QtWidgets.QLineEdit(self.optionalSettingsGroupBox)
self.fixedBufferValueLineEdit.setObjectName("fixedBufferValueLineEdit")
self.optionalSettingsGroupBoxGridLayout.addWidget(self.fixedBufferValueLineEdit, 3, 0, 1, 1)
self.optionalSettingsGroupBoxGridLayout.addWidget(self.fixedBufferValueLineEdit, 5, 0, 1, 1)
self.minimumDistanceLineEdit = QtWidgets.QLineEdit(self.optionalSettingsGroupBox)
self.minimumDistanceLineEdit.setText("")
self.minimumDistanceLineEdit.setObjectName("minimumDistanceLineEdit")
self.optionalSettingsGroupBoxGridLayout.addWidget(self.minimumDistanceLineEdit, 1, 0, 1, 1)
self.verticalLayout_2.addLayout(self.optionalSettingsGroupBoxGridLayout)
self.mainGridLayout.addWidget(self.optionalSettingsGroupBox, 1, 0, 1, 2)
self.verticalLayout.addLayout(self.mainGridLayout)
EuclideanDistanceForm.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(EuclideanDistanceForm)
self.menubar.setGeometry(QtCore.QRect(0, 0, 540, 18))
self.menubar.setGeometry(QtCore.QRect(0, 0, 580, 21))
self.menubar.setObjectName("menubar")
EuclideanDistanceForm.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(EuclideanDistanceForm)
Expand Down Expand Up @@ -131,6 +139,7 @@ def retranslateUi(self, EuclideanDistanceForm):
self.applyPushButton.setText(_translate("EuclideanDistanceForm", "Apply"))
self.optionalSettingsGroupBox.setTitle(_translate("EuclideanDistanceForm", "Optional settings"))
self.fixedBufferValueLabel.setText(_translate("EuclideanDistanceForm", "Fixed buffer value"))
self.minimumDistanceLabel.setText(_translate("EuclideanDistanceForm", "Minimum distance"))
self.maximumDistanceLabel.setText(_translate("EuclideanDistanceForm", "Maximum distance"))
self.maximumDistanceLineEdit.setToolTip(_translate("EuclideanDistanceForm", "The maximum distance to be generated. The nodata value will be used for pixels beyond this distance. "))
self.fixedBufferValueLineEdit.setToolTip(_translate("EuclideanDistanceForm", "Specify a value to be applied to all pixels that are within the -maxdist of target pixels (including the target pixels) instead of a distance value"))
14 changes: 12 additions & 2 deletions core/widgets/EuclideanDistance/euclideanDistance_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ def on_applyPushButton_clicked(self):
self.featurePath = self.ui.inputFeatureLineEdit.text()
self.outRasterPath = self.ui.outRasterLineEdit.text()
self.maskRasterPath = self.ui.maskRasterLineEdit.text()
if self.ui.minimumDistanceLineEdit.text():
self.minDistance = float(self.ui.minimumDistanceLineEdit.text())
else:
self.minDistance = None
args = (
self.featurePath,
self.outRasterPath,
self.maskRasterPath,
self.projectLocation,
options,
self.ui.ignoreOutsideCheckBox.isChecked())
self.ui.ignoreOutsideCheckBox.isChecked(),
self.minDistance)
self.calcEuclideanDistance = EuclideanDistanceAnalysis(args)
self.thread = QThread()
self.calcEuclideanDistance.moveToThread(self.thread)
Expand All @@ -128,7 +133,7 @@ class EuclideanDistanceAnalysis(QObject):

def __init__(self, args):
QObject.__init__(self)
self.featurePath, self.outRasterPath, self.maskRasterPath, self.projectLocation, self.options, self.ignoreOutsideMask = args
self.featurePath, self.outRasterPath, self.maskRasterPath, self.projectLocation, self.options, self.ignoreOutsideMask, self.minDistance = args

def calcDistance(self):
"""
Expand Down Expand Up @@ -177,6 +182,11 @@ def calcDistance(self):
euclideanBand = euclidean.GetRasterBand(1)
euclideanBand.SetNoDataValue(noDataValue)
gdal.ComputeProximity(featRasterBand, euclideanBand, self.options, callback=None)
if self.minDistance != None:
euclideanArray = euclideanBand.ReadAsArray()
euclideanArray[(euclideanArray < self.minDistance) & (euclideanArray != noDataValue)] = self.minDistance
euclideanBand.WriteArray(euclideanArray)
self.updateLoggerSignal.emit(self.tr("Distance values under {} set to {}.").format(self.minDistance, self.minDistance))
euclideanBand.ComputeStatistics(False)
featRaster = None
euclidean = None
Expand Down
39 changes: 20 additions & 19 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
branca==0.5.0
branca==0.6.0
certifi==2022.12.7
charset-normalizer==2.1.0
charset-normalizer==3.1.0
contourpy==1.0.7
cycler==0.11.0
et-xmlfile==1.1.0
folium==0.12.1.post1
fonttools==4.33.3
idna==3.3
folium==0.14.0
fonttools==4.39.2
idna==3.4
Jinja2==3.1.2
joblib==1.2.0
kiwisolver==1.4.3
lxml==4.9.1
MarkupSafe==2.1.1
matplotlib==3.5.2
numpy==1.23.0
openpyxl==3.0.10
packaging==21.3
Pillow==9.3.0
kiwisolver==1.4.4
lxml==4.9.2
MarkupSafe==2.1.2
matplotlib==3.7.1
numpy==1.24.2
openpyxl==3.1.2
packaging==23.0
Pillow==9.4.0
pyparsing==3.0.9
PyQt5==5.15.7
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.11.0
PyQt5-sip==12.11.1
python-dateutil==2.8.2
python-docx==0.8.11
requests==2.28.1
scikit-learn==1.1.1
scipy==1.8.1
requests==2.28.2
scikit-learn==1.2.2
scipy==1.10.1
six==1.16.0
threadpoolctl==3.1.0
urllib3==1.26.9
urllib3==1.26.15