Import qgis.core into PyWPS process

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Import qgis.core into PyWPS process

Eduardo Silverio da Silva
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.

How can I allow these imports inside PyWPS?

Thanks,

_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Salvatore Larosa-2
Hi,

On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <[hidden email]> 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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Jachym Cepicky
Hi,

as Salvatore is writing, check your error.log file, there should be more

and maybe you will have to either fix PYTHONPATH, as Salvatore is
pointing out, or add

```
import sys
sys.path.append('/path/to/your/qgis/libs')
```

at beginning of the script

J

Dne 2.1.2017 v 20:31 Salvatore Larosa napsal(a):

> Hi,
>
> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
> [hidden email]> 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
>
>
>
>
> _______________________________________________
> pywps-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/pywps-dev
>

--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc
_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Eduardo Silverio da Silva
In reply to this post by Salvatore Larosa-2
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 <[hidden email]>:
Hi,

On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <[hidden email]> 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



--
Eduardo Silverio da Silva
Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
Engenheiro Cartógrafo e Agrimensor
+55 41 99873-6274

_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev

GetCapabilities.png (17K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Jachym Cepicky
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 <[hidden email]>:
>
>> Hi,
>>
>> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
>> [hidden email]> 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
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/pywps-dev
>

--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc
_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Eduardo Silverio da Silva
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ý <[hidden email]>:
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 <[hidden email]>:

Hi,

On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
[hidden email]> 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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev


--
Jachym Cepicky
e-mail: [hidden email]
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

_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Jachym Cepicky
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ý <[hidden email]>:
>
>> 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 <[hidden email]>:
>>>
>>> Hi,
>>>>
>>>> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
>>>> [hidden email]> 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
>>> [hidden email]
>>> http://lists.osgeo.org/mailman/listinfo/pywps-dev
>>>
>>>
>> --
>> Jachym Cepicky
>> e-mail: [hidden email]
>> twitter: @jachymc
>>
>
>
>

--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc
_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Eduardo Silverio da Silva
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?

Thanks

2017-01-02 19:54 GMT-02:00 Eduardo Silverio da Silva <[hidden email]>:
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ý <[hidden email]>:
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ý <[hidden email]>:

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 <[hidden email]>:

Hi,

On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
[hidden email]> 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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev


--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc





--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc


<img width="0" height="0" class="m_8307618649413817814mailtrack-img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">

--
Eduardo Silverio da Silva
Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
Engenheiro Cartógrafo e Agrimensor
<a href="tel:+55%2041%2099873-6274" value="+5541998736274" target="_blank">+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

_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Jachym Cepicky
Hi,

I'm afraid, I do not know much about QGIS. I have no clue about how it's
processing module is organized.

What about using shapely or fiona for this task?

J

Dne 5.1.2017 v 14:40 Eduardo Silverio da Silva napsal(a):

> 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?
>
> Thanks
>
> 2017-01-02 19:54 GMT-02:00 Eduardo Silverio da Silva <
> [hidden email]>:
>
>> 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ý <[hidden email]>:
>>
>>> 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ý <[hidden email]>:
>>>>
>>>> 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 <[hidden email]>:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>>>
>>>>>>> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
>>>>>>> [hidden email]> 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
>>>>>> [hidden email]
>>>>>> http://lists.osgeo.org/mailman/listinfo/pywps-dev
>>>>>>
>>>>>>
>>>>>> --
>>>>> Jachym Cepicky
>>>>> e-mail: [hidden email]
>>>>> twitter: @jachymc
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>> --
>>> Jachym Cepicky
>>> e-mail: [hidden email]
>>> 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 <+55%2041%2099873-6274>
>>
>
>
>

--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc
_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Eduardo Silverio da Silva
The reason in using processing.runalg() is to integrate processing workflows from qgis (that can be exported in Python) and try to publish via PyWPS.
So the "extract nodes" is only an example for check that this could be done in WPS.

2017-01-05 11:54 GMT-02:00 Jáchym Čepický <[hidden email]>:
Hi,

I'm afraid, I do not know much about QGIS. I have no clue about how it's processing module is organized.

What about using shapely or fiona for this task?

J

Dne 5.1.2017 v 14:40 Eduardo Silverio da Silva napsal(a):
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?

Thanks

2017-01-02 19:54 GMT-02:00 Eduardo Silverio da Silva <
[hidden email]>:

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ý <[hidden email]>:

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ý <[hidden email]>:

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 <[hidden email]>:

Hi,


On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
[hidden email]> 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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev


--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc





--
Jachym Cepicky
e-mail: [hidden email]
twitter: @jachymc




--
Eduardo Silverio da Silva
Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
Engenheiro Cartógrafo e Agrimensor
<a href="tel:%2B55%2041%2099873-6274" value="+5541998736274" target="_blank">+55 41 99873-6274 <+55%2041%2099873-6274>





--
Jachym Cepicky
e-mail: [hidden email]
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

_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Salvatore Larosa-2
In reply to this post by Eduardo Silverio da Silva
Hi Eduardo,

On Thu, Jan 5, 2017 at 2:40 PM, Eduardo Silverio da Silva
<[hidden email]> 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 <[hidden email]>:
>>
>> 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ý <[hidden email]>:
>>>
>>> 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ý <[hidden email]>:
>>>>
>>>>> 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 <[hidden email]>:
>>>>>>
>>>>>> Hi,
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
>>>>>>> [hidden email]> 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
>>>>>> [hidden email]
>>>>>> http://lists.osgeo.org/mailman/listinfo/pywps-dev
>>>>>>
>>>>>>
>>>>> --
>>>>> Jachym Cepicky
>>>>> e-mail: [hidden email]
>>>>> twitter: @jachymc
>>>>>
>>>>
>>>>
>>>>
>>>
>>> --
>>> Jachym Cepicky
>>> e-mail: [hidden email]
>>> 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
_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev
Reply | Threaded
Open this post in threaded view
|

Re: Import qgis.core into PyWPS process

Eduardo Silverio da Silva
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.

Thanks by the help!

Regards,

2017-01-05 14:41 GMT-02:00 Salvatore Larosa <[hidden email]>:
Hi Eduardo,

On Thu, Jan 5, 2017 at 2:40 PM, Eduardo Silverio da Silva
<[hidden email]> 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 <[hidden email]>:
>>
>> 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ý <[hidden email]>:
>>>
>>> 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ý <[hidden email]>:
>>>>
>>>>> 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 <[hidden email]>:
>>>>>>
>>>>>> Hi,
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
>>>>>>> [hidden email]> 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
>>>>>> [hidden email]
>>>>>> http://lists.osgeo.org/mailman/listinfo/pywps-dev
>>>>>>
>>>>>>
>>>>> --
>>>>> Jachym Cepicky
>>>>> e-mail: [hidden email]
>>>>> twitter: @jachymc
>>>>>
>>>>
>>>>
>>>>
>>>
>>> --
>>> Jachym Cepicky
>>> e-mail: [hidden email]
>>> twitter: @jachymc
>>
>>
>>
>>
>> --
>> Eduardo Silverio da Silva
>> Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
>> Engenheiro Cartógrafo e Agrimensor
>> <a href="tel:%2B55%2041%2099873-6274" value="+5541998736274">+55 41 99873-6274
>
>
>
>
> --
> Eduardo Silverio da Silva
> Mestrando em Ciências Geodésicas na Universidade Federal do Paraná
> Engenheiro Cartógrafo e Agrimensor
> <a href="tel:%2B55%2041%2099873-6274" value="+5541998736274">+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

_______________________________________________
pywps-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/pywps-dev