[Pywps-dev] Import qgis.core into PyWPS process

Eduardo Silverio da Silva eduardosilverio1990 at gmail.com
Thu Jan 5 18:21:15 PST 2017


I changed the GUIEnabled to False and processing.runalg() to
general.runalg(). But even in that way I couldn't get my resulting
shapefile.

The problem is that the program doesn't give me any log message, because
when it tries to execute "Processing.initialize()" it just let me waiting.
I have tried to execute another function like "Processing.providers" and it
returned normally (with value [] because Processing was not initialized).

In the PyWPS log I get only that my algorithm started. And after some time
I need to kill the process and QGIS closes with a minidump.

It seems like Processing.initialize() is restarting the shell and then the
program loses the variables of everything.

This problems is the same as trying to print something (print "some
message"): the program keeps processing until I close the window.

Here is the code that I am trying to publish: http://pastebin.com/gQyF4kWF

I am really stuck in this part. I am going to take a look again in the
PyWPS-QGIS-Processing <https://github.com/rldhont/PyWPS-QGIS-Processing>.

Thanks by the help!

Regards,

2017-01-05 14:41 GMT-02:00 Salvatore Larosa <lrssvtml at gmail.com>:

> Hi Eduardo,
>
> On Thu, Jan 5, 2017 at 2:40 PM, Eduardo Silverio da Silva
> <eduardosilverio1990 at gmail.com> wrote:
> >
> > Problem solved!
> >
> > The problem is that each time that I change the PATHs, the Apache need
> to be restarted to update the environment variables.
> > Also I realized that only the PYTHONPATH in Windows is not recognized in
> the way that I have done before (Control Panel>Advanced system
> settings>Environment Variables), so I needed to put the paths in a archive
> that my Python could read "C:\Pytho27\paths.pth".
> > Now I can import qgis.core and even the plugin "processing" from qgis.
> >
> > But here is another question: How to run the algorithm Extract Nodes on
> a local Shapefile?
> >
> > # In my IDLE Python, I do this by typing:
> > from qgis.core import QgsApplication
> > from processing.core.Processing import Processing
> > import processing
> > qgis = QgsApplication([], True)
> > qgis.setPrefixPath('C:/Program Files/QGIS 2.18/apps/qgis', True)
> > qgis.initQgis()
> > Processing.initialize()
> > processing.runalg('qgis:extractnodes', 'C:\river.shp', 'C:\result.shp')
> >
> > # But when I try in PyWPS, the program stops in
> "Processing.initialize()", then I need to kill the process.
> >
> > Any suggestions?
>
> I don't know if that work (but it should), if not you should get some
> log message.
> Also, it is not necessary to set GUIEnabled argument to True (the
> second argument of QgsApplication).
>
> One more hint could be using the general module to execute an algorithm:
>
> from processing.tools import general
> general.runalg(...)
>
> Anyway, you should see some log message from processing if you run the
> pywps process from shell.
>
> Also, take a look at this project
> https://github.com/rldhont/PyWPS-QGIS-Processing
>
> Regards,
> -SL
>
> >
> >
> > Thanks
> >
> > 2017-01-02 19:54 GMT-02:00 Eduardo Silverio da Silva <
> eduardosilverio1990 at gmail.com>:
> >>
> >> Hi,
> >>
> >> The way I configured the path was by accessing: Control Panel > System
> and Security > System > Advanced system settings > Environment Variables...
> (Image attached)
> >>
> >> I also have tested with the following code just at the begining of the
> code:
> >>
> >> import sys
> >> sys.path.append("C:\Program Files (x86)\QGIS 2.18\bin")
> >> sys.path.append("C:\Program Files (x86)\QGIS 2.18\apps\qgis\bin")
> >> sys.path.append("C:\Program Files (x86)\QGIS 2.18\apps\qgis\python")
> >> sys.path.append("C:\Program Files (x86)\QGIS
> 2.18\apps\Python27\Lib\site-packages")
> >> sys.path.append("C:\Program Files (x86)\QGIS
> 2.18\apps\qgis\python\plugins")
> >>
> >> and I got the same error: "No module named qgis.core".
> >>
> >> Well, thanks by the help!
> >>
> >> Eduardo
> >>
> >> 2017-01-02 18:56 GMT-02:00 Jáchym Čepický <jachym.cepicky at gmail.com>:
> >>>
> >>> Well,
> >>>
> >>> I have no idea, how you confiured the PYTHONPATH
> >>>
> >>> but try (already proposed)
> >>>
> >>> import sys
> >>> sys.path.append("/path/to/qgis/")
> >>>
> >>> J
> >>>
> >>> Dne 2.1.2017 v 21:54 Eduardo Silverio da Silva napsal(a):
> >>>>
> >>>> I have checked the GetCapabilities by accessing:
> >>>> http://localhost:8080/cgi-bin/pywps.cgi?service=wps&request=
> GetCapabilities&version=1.0.0
> >>>> and it is okay. I can even execute the example process "inputs_added".
> >>>>
> >>>> Then a have checked the log messages and the result is:
> >>>>
> >>>> PyWPS [2017-01-02 18:49:34,355] INFO: Setting PYWPS_PROCESSES from
> >>>> configuration file to c:/pywps/pywps_processes
> >>>> PyWPS [2017-01-02 18:49:34,388] WARNING: Could not import processes
> from
> >>>> 'pywps_processes': ImportError('No module named qgis.core',)
> >>>> PyWPS [2017-01-02 18:49:34,424] INFO: Following processes are
> imported:
> >>>> ['inputs_added']
> >>>> Traceback (most recent call last):
> >>>>   File "C:/pywps\pywps\Wps\__init__.py", line 174, in
> _init_from_directory
> >>>>     [processSources.__name__])
> >>>>   File "c:/pywps/pywps_processes\processing.py", line 2, in <module>
> >>>>     from qgis.core import *
> >>>> ImportError: No module named qgis.core
> >>>>
> >>>> As we can see, the only process imported was the "input_added", while
> my
> >>>> other algorithm "processing" gave an ImportError.
> >>>>
> >>>> Eduardo,
> >>>>
> >>>> 2017-01-02 18:42 GMT-02:00 Jáchym Čepický <jachym.cepicky at gmail.com>:
> >>>>
> >>>>> Hi,
> >>>>>
> >>>>> first check, if your GetCapabilities response is ok (
> >>>>> http://server/wps?service=wps&request=getcapabilities) - maybe the
> plugin
> >>>>> is corrupted (it's not the stablest piece of software).
> >>>>>
> >>>>> Then please one more time: check the error.log of your web server,
> there
> >>>>> should be written more - you can pass any exception or error message
> either
> >>>>> to the mailing list or share it via pastebin.net or similar service
> >>>>>
> >>>>> J
> >>>>>
> >>>>> Dne 2.1.2017 v 21:38 Eduardo Silverio da Silva napsal(a):
> >>>>>
> >>>>>> In my case I am using QGIS 2.18 (x32) and Python 2.7.13 (x32) on
> Windows
> >>>>>> 10, and I have already added the following environment variables:
> >>>>>>
> >>>>>> PYTHONPATH:
> >>>>>> C:\Program Files (x86)\QGIS 2.18\apps\qgis\python
> >>>>>> C:\Program Files (x86)\QGIS 2.18\apps\qgis\python\plugins
> >>>>>> C:\Program Files (x86)\QGIS 2.18\apps\Python27\Lib\site-packages
> >>>>>>
> >>>>>> PATH:
> >>>>>> C:\Program Files (x86)\QGIS 2.18\bin
> >>>>>> C:\Program Files (x86)\QGIS 2.18\apps\qgis\bin
> >>>>>> C:\Python27
> >>>>>> C:\Python27\Scripts
> >>>>>>
> >>>>>> Here is the code where I want to import the classes:
> >>>>>>
> >>>>>> #I would like to use these classes:
> >>>>>> # from qgis.core import *
> >>>>>> # from qgis.gui import *
> >>>>>> # from processing.core.Processing import Processing
> >>>>>> # import processing
> >>>>>>
> >>>>>> from pywps.Process import WPSProcess
> >>>>>> from types import FloatType
> >>>>>>
> >>>>>> class Process(WPSProcess):
> >>>>>>      def __init__(self):
> >>>>>>          WPSProcess.__init__(self,
> >>>>>>               identifier       = "processar",
> >>>>>>               title            = "Title",
> >>>>>>               version          = "1",
> >>>>>>               storeSupported   = "false",
> >>>>>>               statusSupported  = "false",
> >>>>>>               abstract         = "Abstract")
> >>>>>>
> >>>>>>          self.value1 = self.addLiteralInput(identifier = "value1",
> title
> >>>>>> =
> >>>>>> "Input 1", type = FloatType)
> >>>>>>          self.value2 = self.addLiteralInput(identifier = "value2",
> title
> >>>>>> =
> >>>>>> "Input 2", type = FloatType)
> >>>>>>          self.result = self.addLiteralOutput(identifier = "result",
> >>>>>> title =
> >>>>>> "Result", type = FloatType)
> >>>>>>
> >>>>>>      def execute(self):
> >>>>>>     # Here I would like to write the necessary code to execute the
> >>>>>> qgis:extractnodes algorithm:
> >>>>>>     # processing.runalg('qgis:extractnodes', 'river.shp',
> 'output.shp')
> >>>>>>
> >>>>>> v1 = self.value1.getValue()
> >>>>>>          v2 = self.value2.getValue()
> >>>>>>          self.result.setValue(v1 + v2)
> >>>>>>          return
> >>>>>> --------------------------------------
> >>>>>>
> >>>>>> But even with those PATH variables configured I could not access the
> >>>>>> algorithm via WPS-client plugin.
> >>>>>>
> >>>>>> Regards,
> >>>>>>
> >>>>>>
> >>>>>> 2017-01-02 17:31 GMT-02:00 Salvatore Larosa <lrssvtml at gmail.com>:
> >>>>>>
> >>>>>> Hi,
> >>>>>>>
> >>>>>>>
> >>>>>>> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
> >>>>>>> eduardosilverio1990 at gmail.com> wrote:
> >>>>>>>
> >>>>>>> Hello people,
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> I have a python script that uses some classes from qgis and it
> runs
> >>>>>>>> correctly in my standalone app (IDLE Python). But when I try to
> publish
> >>>>>>>> the
> >>>>>>>> script through PyWPS (3.2.5), the process does not apear in the
> list of
> >>>>>>>> GetCapabilities. I think the problem is with the following
> imports:
> >>>>>>>>
> >>>>>>>> from qgis.core import *
> >>>>>>>> from qgis.gui import *
> >>>>>>>> from processing.core.Processing import Processing
> >>>>>>>>
> >>>>>>>> When I comment these lines the algorithm is showed.
> >>>>>>>>
> >>>>>>>>
> >>>>>>> I guess the problem is with your environment variable, you should
> add the
> >>>>>>> QGIS python and plugins paths to PYTHONPATH and probably the QGIS
> lib
> >>>>>>> path
> >>>>>>> to LD_LIBRARY.
> >>>>>>>
> >>>>>>> Also, any error message could be useful in order to get some help
> from
> >>>>>>> the
> >>>>>>> community. :)
> >>>>>>>
> >>>>>>> Regards,
> >>>>>>> -SL
> >>>>>>>
> >>>>>>>
> >>>>>>> --
> >>>>>>> Salvatore Larosa
> >>>>>>> linkedIn: http://linkedin.com/in/larosasalvatore
> >>>>>>> twitter: @lrssvt
> >>>>>>> skype: s.larosa
> >>>>>>> IRC: lrssvt on freenode
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> _______________________________________________
> >>>>>> pywps-dev mailing list
> >>>>>> pywps-dev at lists.osgeo.org
> >>>>>> http://lists.osgeo.org/mailman/listinfo/pywps-dev
> >>>>>>
> >>>>>>
> >>>>> --
> >>>>> Jachym Cepicky
> >>>>> e-mail: jachym.cepicky at gmail.com
> >>>>> twitter: @jachymc
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>> --
> >>> Jachym Cepicky
> >>> e-mail: jachym.cepicky at gmail.com
> >>> twitter: @jachymc
> >>
> >>
> >>
> >>
> >> --
> >> Eduardo Silverio da Silva
> >> Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
> >> Engenheiro Cartógrafo e Agrimensor
> >> +55 41 99873-6274
> >
> >
> >
> >
> > --
> > Eduardo Silverio da Silva
> > Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
> > Engenheiro Cartógrafo e Agrimensor
> > +55 41 99873-6274
>
>
>
>
> --
> Salvatore Larosa
> linkedIn: http://linkedin.com/in/larosasalvatore
> twitter: @lrssvt
> skype: s.larosa
> IRC: lrssvt on freenode
>



-- 
Eduardo Silverio da Silva
Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
Engenheiro Cartógrafo e Agrimensor
+55 41 99873-6274
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pywps-dev/attachments/20170106/a6d50955/attachment-0001.html>


More information about the pywps-dev mailing list