I know how to make Hub Lines using the GUI, I want to know how to do the same using the Python Console, a tutorial would be great.
-
Could you add some more information please? We don't know if you are looking for a link or a tutorial or something entirely different. – Paul Jun 30 '14 at 16:52
-
I know how create the Hub Lines, I want to know how to do it using the python console. A tutorial would be great. Thank you. – amamdouh Jun 30 '14 at 17:06
-
@amamdouh, you've just restated your question almost verbatim. Could you please add more information as Paul suggested? What have you tried so far? Could you post any code you've written? – Fezter♦ Jun 30 '14 at 23:49
-
I asked a similar question and found this which may be of some use: gis.stackexchange.com/questions/11216/… – Joseph Jul 1 '14 at 9:49
-
it's what I am looking for, but I can't find the code for MMQGIS plugin anywhere. thanks. – amamdouh Jul 1 '14 at 11:54
When I don't know a Python module, I use the dir()
command or the see module to know what's inside.
(in the Python console)
from see import see
import mmqgis
dir(mmqgis)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'classFactory', 'mmqgis_dialogs', 'mmqgis_library', 'mmqgis_menu']
# or
see(mmqgis)
.classFactory() .mmqgis_dialogs .mmqgis_library .mmqgis_menu
classFactory()
, .mmqgis_dialogs()
or .mmqis_menu()
are clearly for the interface of the plugin, so the functions that you are looking for are in .mmqgis_library
.
You can try:
see(mmqgis.mmqgis_library)
(lot of items)
but it is more interesting here to find the original mmqgis_library
Python file:
import mmqgis.mmqgis_library
mmqgis.mmqgis_library.__file__
'/.../.qgis2/python/plugins/mmqgis/mmqgis_library.pyc'
The file concerned is mmqgis_library.py with (lines 3202 ...):
# --------------------------------------------------------
# mmqgis_hub_distance - Create shapefile of distances
# from points to nearest hub
# --------------------------------------------------------
class mmqgis_hub:
def __init__(self, point, newname):
self.point = point
self.name = newname
....
So:
from mmqgis.mmqgis_library import mmqgis_hub
Works, but after you need to understand the class to use it...