ccrook / QGIS-Contour-Plugin

Contour plugin for QGIS - uses python matplotlib to generate contours of data on vector point data.
44 stars 13 forks source link

Calling contour from other modules #17

Closed ccrook closed 2 years ago

ccrook commented 8 years ago

A user is asking how to call the contour plugin from other plugins. The current design is not well suited for this as it does not separate user interface from processing functionality.

It is proposed that it be refactored to do this. It may be possible to incorporate this into the QGIS processing framework at the same time.

ftharyanto commented 6 years ago

So if someone modified the script to separate UI and processing functionality, people could call the Contour modules from their plugins (or stand-alone app)?

ccrook commented 6 years ago

Yes .. that is the thought. I started looking at it but currently don't have time :-(

ftharyanto commented 6 years ago

I hope someone would done it

ftharyanto commented 6 years ago

If I inherit the ContourDialog Class, give it a name like contour2 and then override all essential variables (for example: input layer name, data field, number level, min, max, and output layer name). Could I import that child class from my own plugin and use that to interpolate data point?

ccrook commented 6 years ago

Hi Fajar

You could do that, though it may make sense to just use the matplotlib functions that the contour plugin is calling https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.tricontour.html or https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html for gridded data. You could pull out the code from the contour plugin to build geometries from the matplotlib results.

Cheers Chris


From: Fajar Tri Haryanto [notifications@github.com] Sent: 15 March 2018 22:24 To: ccrook/QGIS-Contour-Plugin Cc: Chris Crook; Author Subject: Re: [ccrook/QGIS-Contour-Plugin] Calling contour from other modules (#17)

If I inherit the ContourDialog Class, give it a name like contour2 and then override all essential variables (for example: input layer name, data field, number level, min, max, and output layer name). Could I import that child class from my own plugin and use that to interpolate data point?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ccrook/QGIS-Contour-Plugin/issues/17#issuecomment-373312192, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAmhEpNY6fxagMT9l_YSAIy2k0-JmKbhks5tejNIgaJpZM4KMG2S.


This message contains information, which may be in confidence and may be subject to legal privilege. If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info@linz.govt.nz) and destroy the original message. LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ. Thank You.

ftharyanto commented 6 years ago

Thank you Mr. Crook. That would more convenient and faster I guess. Alright, I'm going to use matplotlib.pyplot.contour. I think this the part where the plugin uses it: cs = plt.contour(gx, gy, gz, levels, extend=extend)

How to access value of layer's attribute? And when I tried to import the contour module (import matplotlib.pyplot.contour) it says the module doesn't exist

ccrook commented 6 years ago

For getting the data and getting contours see

https://github.com/ccrook/QGIS-Contour-Plugin/blob/12ee636ae59555756ba0ab50df844500708343c4/contour/contour.py#L812

For creating the vector layer from them see

https://github.com/ccrook/QGIS-Contour-Plugin/blob/12ee636ae59555756ba0ab50df844500708343c4/contour/contour.py#L929

ftharyanto commented 6 years ago

Thank you for your helpful reply, I'm still working on it

btw, there is a double declaration of self._zfield in here: https://github.com/ccrook/QGIS-Contour-Plugin/blob/276048aea356806b7b7a7873e30637633daef942/contour/contour.py#L138

and here is the second declaration: https://github.com/ccrook/QGIS-Contour-Plugin/blob/276048aea356806b7b7a7873e30637633daef942/contour/contour.py#L145

As far as I know, Python treat single and double quotes exactly the same.

ccrook commented 6 years ago

Thanks @gaaraxpo - just an oversight.

ftharyanto commented 6 years ago

Do you plan to make the plugin callable in the near future? Because I'm very confused right now :(

ccrook commented 6 years ago

@gaaraxpo Plans I've had for a long time - Time to do it ... not yet. But it's great you have commented on this as it does give me more motivation to do it!

ftharyanto commented 6 years ago

I'm happy hearing that you just get more motivation from me :D

ccrook commented 2 years ago

Closing stale issue - contouring now also implemented as processing algorithm that can be called from code