I try to use coords from two points collected in a JS file in order to send them to a WFS Geoserver request, connected to a SQL view which will create a buffer around the line composed of those two points.

My SQL view works fine with the default values in GeoServer, but I can't manage to have a request (with the exact same parameters values) working from the JS file.

Here is my JS code :

url1 = 'http://localhost:8080/geoserver/projetgeonum/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=projetgeonum%3A'
url2 = '&maxFeatures=50&outputFormat=application%2Fjson'
var dep_long = "7.14518"
var dep_lat = "43.99156"
var arr_long = "7.342542"
var arr_lat = "43.808902"
params = '&viewparams=dep_long:' + dep_long + ';dep_lat:' + dep_lat + ';arr_long:' + arr_long + ';arr_lat:' + arr_lat

Url building function for WFS request:

   function url_fun(type) {
        if (type == 'saison') {
            url = url1 + type + url2 + params
            return url
        } else if (type == 'milieu') {
            url = url1 + type + url2 + params + ';saison_code:' + user_saison
            return url
        } else if (type == 'sport') {
            url = url1 + type + url2 + params + ';saison_code:' + user_saison + ';milieu_code:' + user_milieu
            return url

Here is my SQL view:

SELECT DISTINCT saison, saison_code from sport_06
WHERE ST_Intersects(geom,
ST_Buffer(ST_Envelope(ST_GeomFromText('LINESTRING(%dep_long% %dep_lat%, %arr_long% %arr_lat%)', 4326)),0.01))

And here is the result of the preview in GeoServer, which is totally what I want: GeoJSON obtained

Here is the url I build in the JS, with the parameters at the end:


And here is the error I get when trying to access this url (which syntax seems totally right for me):

<ServiceExceptionReport version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">
java.lang.RuntimeException: java.io.IOException java.io.IOExceptionInvalid value for parameter arr_long

I tried first to use only one parameter in my SQL view, as ('LINESTRING(%coords%)', 4326), where I built the coords parameter such as 'float number float number, float number float number', but I let down this option as I didn't succeed to make GeoServer accept the comma in the middle, despite a backlash.

Any ideas?

1 Answer 1


Ok i eventually succeeded, the problem with the four parameters was the default regex expression of GeoServer : ^[\w\d\s]+$ This regex wasn't recognizing the dots in the coords numbers, so I changed it to ^[.\w\d\s]+$ ant it was all sorted!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.