The biggest thing to note is that the scripting community module uses
Jython, not CPython. So, if you installed requests with pip, it's not
actually available in your Jython path. You'll have to install it
separately (which I haven't done).

-Brian

On Fri, Sep 1, 2017 at 1:56 AM, Alex Chen via Geoserver-users <
geoserver-users@lists.sourceforge.net> wrote:

> I need to create a Web Processing service on GeoServer (2.11.2) that
> triggers a back-end Python script. This script should be able to utilize
> requests and other packages necessary to do the job.
>
> I have got the wps extension and all necessary GeoScript plugins installed
> with GeoServer.
>
> I followed an example as below to create a custom script that can be
> called from the Admin Web Console WPS Request Builder.
>
> http://suite.opengeo.org/opengeo-docs/processing/
> scripting/processcreate.html
>
> import math, sysfrom geoserver.wps import processfrom geoscript.geom import 
> Pointfrom geoscript.feature import Featurefrom geoscript.layer import Layer
> @process(
>   title = 'Distance and Bearing',
>   description = 'Computes Cartesian distance and bearing from features to an 
> origin.' + str(sys.executable),
>   inputs = {
>     'origin': (Point, 'Origin from which to calculate distance and bearing.'),
>     'features': (Layer, 'Features to which distance and bearing should be 
> calculated.')
>   },
>   outputs = {
>     'result': (Layer, 'Features with calculated distance and bearing 
> attributes.')
>   })def run(origin, features):
>
>   for f in features.features():
>     p = f.geom.centroid
>     d = p.distance(origin)
>     b = 90 - math.degrees(math.atan2(p.y - origin.y, p.x - origin.x))
>
>     yield Feature({'point': p, 'distance': d, 'bearing': b})
>
> I tried to use Python's sys library and print out sys.executable as a
> testing process, but the output was NoneType.
>
> I also tried to import requests but the GeoServer logs showed requests
> cannot be found.
>
> I am wondering whether arbitrary Python packages e.g. Requests can be used
> in a script as such supported by GeoServer WPS. Are there any limitations
> for Python scripts that can be triggered as Web Processing Service by
> GeoServer?
> Thanks!
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Geoserver-users mailing list
>
> Please make sure you read the following two resources before posting to
> this list:
> - Earning your support instead of buying it, but Ian Turton:
> http://www.ianturton.com/talks/foss4g.html#/
> - The GeoServer user list posting guidelines: http://geoserver.org/comm/
> userlist-guidelines.html
>
> Geoserver-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geoserver-users
>
>


-- 
Brian Farrell
Project Associate
Center for Geospatial Information Technology
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this 
list:
- Earning your support instead of buying it, but Ian Turton: 
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: 
http://geoserver.org/comm/userlist-guidelines.html

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Reply via email to