5

The size of an URL is limited. Therefore I'm not able to request a WFS with a complex geometry. I read (Geoserver POST filter to WMS layer) that is possible to do in a WMS, but I didn't get it to work.

I'm using Postman to POST to my geoserver and add raw body data like this:

CQL_FILTER=INTERSECTS(geometry, POLYGON ((0 0, 1 1....))

I also tried it in key-value form type. I also tried url-encoding it first.

Does anyone know how to query with large geometries? (WKT in my case).

3 Answers 3

4

Complete post request would be

var url = 'http://localhost/geoserver/ows?service=WFS&version=1.0.0&outputFormat=application%2Fjson&request=GetFeature&typeName=topp:states',
    wktRepresentation = 'POLYGON((579832.0820867891 165971.37415659515,579946.6092781681 165790.03943691167,580180.4356272336 165914.11056090562,580149.4178462351 166047.7256175145,579832.0820867891 165971.37415659515))';

$.post(url, { cql_filter: 'INTERSECTS(geom, ' + wktRepresenation + ')' }, function(data, textStatus, xhr) {
    console.log(data);
});

Coordinates are in different projection for my example but just change them with coordinate system which you are using.

1
  • 1
    Thank you for taking the time to post this back for others to use. It saved me. Commented Jun 10, 2019 at 21:06
1

I already found an answer myself: I had to use x-www-form-urlencoded key-value data.

1
  • 4
    Could you add one complete request as an example? That could help other users in the future.
    – user30184
    Commented May 25, 2016 at 15:37
1

The body of an http request can be coded in three ways :

  • Can be one of form (application/x-www-form-urlencoded) ;
  • multipart :multipart/form-data) ;
  • or json (application/json).

For long cql_filter in geoserver, form body is used. An example below for R users with IGN WFS geoserver

library(httr2) # perform http request
library(sf) # work with spatial features

apikey <- "administratif"
layer_name <- "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune"

# Param for creating url
params <- list(
   service = "WFS",
   version = "2.0.0",
   request = "GetFeature",
   outputFormat = "json",
   srsName = "EPSG:4326",
   typeName = layer_name
)

filter <- "INTERSECTS(the_geom, POLYGON ((47.94371 -4.315395, 47.80732 -4.309902, 47.8774 -4.103909, 47.94739 -3.939114, 48.18246 -3.9501, 48.01729 -4.27969, 47.94371 -4.315395)))"

# construct request
request <- request("https://wxs.ign.fr") |>
   req_url_path_append(apikey) |>
   req_url_path_append("geoportail/wfs") |>
   req_url_query(!!!params) |> 
   req_body_form(cql_filter=filter)

# perform request
resp <- req_perform(request) |>
   resp_body_string()

# read features
features <- read_sf(resp)

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.