-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[processing] port heatmap algorithm #4843
Conversation
BTW, I noticed that after executing any already available QGIS algorithm there is an error like this
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I'm really keen for feedback on how you found the porting process & the new API. Any suggestions for improvement?
def displayName(self): | ||
return self.tr('Heatmap (Kernel Density Estimation)') | ||
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT_LAYER, self.tr('Heatmap'))) | ||
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT_LAYER, self.tr('Heatmap'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer required - since 058271b the output will automatically be created
radius = self.getParameterValue(self.RADIUS) | ||
kernel_shape = self.getParameterValue(self.KERNEL) | ||
radius = self.parameterAsDouble(parameters, self.RADIUS, context) | ||
kernel_shape = self.parameterAsEnums(parameters, self.KERNEL, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be parameterAsEnum - parameterAsEnums will return a list and is for multiple value parameters only
output_values = self.getParameterValue(self.OUTPUT_VALUE) | ||
output = self.getOutputValue(self.OUTPUT_LAYER) | ||
decay = self.parameterAsDouble(parameters, self.DECAY, context) | ||
output_values = self.parameterAsEnums(parameters, self.OUTPUT_VALUE, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -170,7 +204,7 @@ def processAlgorithm(self, parameters, context, feedback): | |||
kde = QgsKernelDensityEstimation(kde_params, output, output_format) | |||
|
|||
if kde.prepare() != QgsKernelDensityEstimation.Success: | |||
raise GeoAlgorithmExecutionException( | |||
raise QgsProcessingException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be fine to keep throwing GeoAlgorithmExecutionException - there's code which handles this and maps it automatically to the c++ exception. I guess there's no harm either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it is better to use GeoAlgorithmExecutionException
or switch to QgsProcessingException
to reduce (a little) code to maintain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you're right. Let's reduce the workload and switch everything over.
@@ -78,6 +78,7 @@ | |||
from .VectorSplit import VectorSplit | |||
from .VoronoiPolygons import VoronoiPolygons | |||
from .ZonalStatistics import ZonalStatistics | |||
from .Heatmap import Heatmap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind keeping the alphabetical sorting that's been started here? (and below)
(sorry, pedantic I know!)
It's on my list - there's some weird issue going on buried within the hidden depths of sip. I'll find it.... |
@@ -179,10 +213,12 @@ def processAlgorithm(self, parameters, context, feedback): | |||
total = 100.0 / layer.featureCount() if layer.featureCount() else 0 | |||
for current, f in enumerate(features): | |||
if kde.addFeature(f) != QgsKernelDensityEstimation.Success: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also - better add a check for feedback.isCanceled() here too and break out of the loop
Also added test (failing for now). Trying to debug what is wrong, probably I did something wrong when porting. |
Does the test pass locally? For me none of the raster hash test values match locally vs Travis (likely the library version differences). I just (make sure the algorithm works) then set them to Travis, and suffer the local failures. Maybe we should make the hash values a list of acceptable values instead? |
No test does not pass locally. Seems there is something wrong with algorithm (my port) itself |
@nyalldawson hopefully test and algorithm now fixed. I will add comments to the documentation PR |
What was the issue? |
Initial output raster declaration
was wrong and even removing it and using automatically generated output does not helped (probably I just don't know how to use them correctly). It worked after declaring output raster explicitly similarly to the Aspect algorithm
|
Ok - I definitely need to add a lot of detail about that to the porting guide :) |
Description
Restore Heatmap algorithm (no tests yet)
Checklist
fixes #11111
in the commit message next to the description[FEATURE]
in the commit message[needs-docs]
in the commit message and containt sufficient information in the commit message to be documentedscripts/prepare-commit.sh
script before each commit