1

I have basic point data and I want to count the number of points in the data. I am displaying the data using WFST-Leaflet since I need to also apply filters and this plugin seems like the cleanest method.

const wfstPointOptions = {
    crs: L.CRS.EPSG4326,
    showExisting: true,
    geometryField: 'geom',
    url: 'http://localhost:8080/geoserver/HEC/wfs',
    typeNS: 'HEC',
    typeName: 'Universities',
    maxFeatures: 100,
    opacity: 1,
    style: function(layer) {
        return {
            color: 'purple',
            weight: 1
        }
    },
};

const wfstPoint = new L.WFST(wfstPointOptions, new L.Format.GeoJSON({
    crs: L.CRS.EPSG4326,
    pointToLayer(geoJsonPoint, latlng) {
        const layer = new L.CircleMarker(latlng, {
            radius: 5,
        });
        
    return layer;
    },
}));

wfstPoint.addTo(map);

How do I count the number of features in this layer?

4
  • 1
    Change the request type to hits and make sure you are using wfs2.0
    – Ian Turton
    May 11 at 18:40
  • Can you explain please? What do you mean by request type to hits?
    – Aneeqa
    May 12 at 3:41
  • Instead of request=GetFeature use request=hits
    – Ian Turton
    May 12 at 7:56
  • You need to generate a request like: http://localhost:8080/geoserver/HEC/wfs?service=WFS&version=2.0.0&request=GetFeature&typenames=Universities&resulttype=hits
    – nmtoken
    May 12 at 11:56

1 Answer 1

1

L.WFST layer fires load event when all features are loaded, so you just have to catch the event and get number of layers from event object (assuming all features are points):

wfstPoint.on('load', function(evt) {
  console.log('Points: ', evt.layers.length);
});

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.