0

I try get number of features through WFS request:

    $.ajax('http://x.x.x.x/geoserver/wfs',{
            type: 'GET',
            data: {
                service: 'WFS',
                version: '1.1.0',
                request: 'GetFeature',
                typeName: 'workspace:layer',
                outputFormat: 'text/javascript',
                srsname: 'EPSG:4326',
                resultType: 'hits',
                bbox: extent.join(',') + ',EPSG:4326'
                },
            dataType: 'jsonp',
            jsonpCallback:'parseResponse',
            jsonp:'format_options'
    }).then(function(response) {
    var result = parserJSON.readFeatures(response);
    });

But I get Uncaught SyntaxError. Response is not JSONP.

response:

<wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:sf="http://www.openplans.org/spearfish"
    xmlns:wfs="http://www.opengis.net/wfs"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:ows="http://www.opengis.net/ows"
    xmlns:tiger="http://www.census.gov" xmlns:topp="http://www.openplans.org/topp"
    xmlns:baikalgeol="http://www.geol.irk.ru/baikalgeol"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="35"
    timeStamp="2016-10-07T02:38:43.015Z"
    xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>

As see server return numberOfFeatures="35".

I changed outputFormat on 'GML3' and parseGML3 (openlayers format). But it did not help.

How wrap response in json or read this xml without rest?

  • GeoServer is indeed returning the requests with &resulltype=hits as GML even if some other outputformat is defined demo.opengeo.org/geoserver/…. Perhaps that's because all outputformats, like zipped shapefile, can't present the result of such query. The GML output contains the information that you need, is your problem in parsing? – user30184 Oct 7 '16 at 6:11
  • Problem in reciving xml. I can not even bring it to the console. – pirr Oct 7 '16 at 6:37
  • Ajax error: AJAX: [object Object] | parsererror | Error: parseResponse was not called NaN – pirr Oct 7 '16 at 7:28
2

From the look of HitsOutputFormat GeoServer only returns hits in text/xml format.

If you would like to modify this code and submit a pull request I'm sure the developers would review it favourably. Please also read the note on resourcing feature requests and enhancements.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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