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

[processing] Fix and improve eliminate #4011

Closed
wants to merge 565 commits into from

Conversation

bstroebl
Copy link

Fix: Eliminate claimed to work with an existing selection, this was not the case any more
Improve: Any in-algorithm way to create a selection has been removed as there now is a algorithm dedicated for this. Thus Eliminate can now be used within a model.

@nyalldawson
Copy link
Collaborator

@bstroebl I'm just trying to understand the intended workflow with this algorithm. I gather you must first select the polygons you want to merge (eg by selecting those with an area < certain threshold), and then you run the algorithm?


def __init__(self):
GeoAlgorithm.__init__(self)
self.showInToolbox = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't needed - showing in toolbox/modeller is the default behaviour

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, copied that over from the deprecated algo

self.tr('%s: (No selection in input layer "%s")' % (self.commandLineName(), self.getParameterValue(self.INPUT))))

# Keep references to the features to eliminate
featToEliminate = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could simplify this block down to:

featToEliminate = inLayer.selectedFeatures()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson Correct, although in my experience situations are normally not that simple; usually there are more criteria involved than just the area (GRASS has rmarea in v.clean for that already). I normally use the area/perimeter ratio to identify "real" sliver polygons but sometimes in addition certain attribute combinations are of interest, too. To use an existing selection enables the user to use any tool in QGIS to create this selection (expression builder, manual selection....). On the other hand it does not make sense to apply the algorithm on all polygons.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson the above is the reply to your first question on the intended workflow

# select and delete the features in ProcessLayer that are selected in inLayer
idsToEliminate = []

for aFeat in featToEliminate:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right in that this whole block is designed to match the selection from the source layer to the copy?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I did not find another way to do this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn @wonder-sk Any ideas here? I can't think of anything currently in the api which would simplify this, but having to resort to this kind of process to match features is horrible....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson I am not happy with that piece of code either. I was thinking about inverting the inLayer's selection and save the then selected features as processLayer. This could be either a normal outputLayer (i.e. shape file) or a memory layer (by copying the code from vector.duplicateInMemory or better, enhancing vector.duplicateInMemory to optionally duplicate only selected features). What do you think about that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the memory layer not preserve feature ids?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would only use memory for the edited features and not the whole layer.

Copy link
Author

@bstroebl bstroebl Jan 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer would be created with startEditing/stopEditing, right? Sounds like a good compromise. How do I get the layer object if i use output.getVectorWriter to create the layer in the first place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer would be created with startEditing/stopEditing, right?

Yes, exactly

How do I get the layer object if i use output.getVectorWriter to create the layer in the first place?

I think you can do

wr = output.getVectorWriter()
# write...
output_layer = output.layer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn thanks, maybe I try it this weekend

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new commit to address this

borysiasty and others added 28 commits February 1, 2017 18:11
[FEATURE] allow installing plugins from local ZIP packages
[processing] rename execute sql output
I guess that the intention is parlty solved by the custom widgets
Avoid startup error when project template folder does not exist
Use native QGIS raster API instead of GDAL API in zonal statistics
[FEATURE][processing] removed otb and lidartools providers

Tagged as feature to not forget mention this in changelog and docs
In postgres provider, a query layer is detected as a table starting with `(` and ending with `)`.
…ry_layer

[BUGFIX][DB Manager] Detect query layer like providers do
Use weak layer pointers in labeling engine
(definitions are often accessed before a QgsSymboLayer/etc
is constructed)
…ls#77

Changed isDeleteStyleFromDBSupported to isDeleteStyleFromDbSupported
wonder-sk and others added 2 commits February 16, 2017 09:56
…yers

A new class QgsPathResolver is introduced for conversion between absolute
and relative paths when reading/writing XML.

Cleaned up code in layer definition file support (.qlr) to better handle
relative/absolute path conversion.
@m-kuhn
Copy link
Member

m-kuhn commented Feb 16, 2017

Thanks, any objections to merging this from you @nyalldawson ? It looks like all previous comments have been addressed.

@bstroebl can you

  • remove the old algorithm
  • rebase on master to make it mergable

Thanks a lot and sorry for the delay

@bstroebl
Copy link
Author

urrks rebasing added all the commits since when I created this branch :-( anyhow, I followed the instructions given in git push --help using

  1. git rebase master (and solving merge conflicts)
  2. git pull (and solving merge conflicts)
  3. git push

I could close this PR and make a new one based on current master if you like

@bstroebl
Copy link
Author

This PR is replaced by PR #4179. It is only left open to allow looking at the discussion and will be closed as soon as #4179 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet