1

I need to know how many features are displayed on my screen (depending on the BBOX). I read that you can do it with a WFS request and resulttype=hits but my number of features still stay the same, whatever I put in the BBOX. Here's my code :

map.on('moveend', function(evt) {
            var extent = map.getView().calculateExtent(map.getSize());
            console.log(extent);
            var url = 'http://localhost:8080/geoserver/wfs?service=wfs&version=1.1.0&request=getfeature&typename=aisdata:ais_vessels& outputFormat=json&format_options=callback:getJson&resulttype=hits&bbox=' + extent.join(',');
            $.ajax({
                url: url,
                success: function(response) {
                    debugger;
                }
            });
        });

And on the following picture you can see that my BBOX is changing : enter image description here

3
  • what projection is your data in?
    – Ian Turton
    Commented Nov 7, 2016 at 9:39
  • This gives bigger number http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.1.0&request=GetFeature&typename=topp:states&bbox=20,-100,40,-80&resulttype=hits than this http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.1.0&request=GetFeature&typename=topp:states&bbox=20,-100,30,-80&resulttype=hits Try to find what is different in your system.
    – user30184
    Commented Nov 7, 2016 at 9:46
  • @iant thanks for your help, it was indeed a projection issue
    – So4ne
    Commented Nov 7, 2016 at 10:02

1 Answer 1

4

It is best to add at the end of the BBOX the SRS of it, as it might not be the same as your data (and WFS defaults to use the SRS of the data if you don't say otherwise). E.g.:

BBOX=-2000000,-2000000,2000000,2000000,EPSG:3857

1
  • Hey, this is working ! I suspected it was a projection issue but I tried to add the SRS parameter instead of adding the projection like you do. Thanks !
    – So4ne
    Commented Nov 7, 2016 at 9:59

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.