0

I am trying to get the JSON feature data which I have filtered using cql_filter.

<script>
      var wmsSource = new ol.source.TileWMS({
        url: 'http://localhost:9090/geoserver/ilfs/wms',
        params: {'LAYERS': 'ilfs:dharani_samplevillage', 
            'TILED': true, 'format': 'image/png', 
            'VERSION': '1.1.1', 'SRS':'EPSG:4326',          
                "TRANSPARENT": true,
                "ISBASELAYER": true,
                "RATIO": 1,
                "TILED": true,
                "CQL_FILTER": "bhucode=11223344444555 and kid=243" 
                //kid = 237, 236, 78, 241, 243
        },
        serverType: 'geoserver',
        transition: 0
        //crossOrigin: 'anonymous'      
      });

      var wmsLayer = new ol.layer.Tile({
          source: wmsSource,
          opacity: 0.7,
          visible: true          
      });

      var view = new ol.View({
          projection: 'EPSG:4326',
          //Longiture first, then latitude
          //center: ol.proj.transform([76.63612, 16.94924], 'EPSG:4326', 'EPSG:3857'),
          //center: [76.63612,16.94924],
          center: [0, 0],
          zoom: 18            
      });

      var map = new ol.Map({
          layers: [wmsLayer],
          target: 'map',
          view: view,
          renderer: 'canvas'
      });<script>

With the above code displaying the filtered map, but I need to retrieve feature data with the format of JSON, and that should be in load into browser console.

1
  • 1
    WFS service is for vector data.
    – user30184
    May 25 '18 at 6:02
3

Whilst you may be able to get some sort of JSON from a WMS GetFeatureInfo request for a point location in a map provided by a WMS (not all WMS providers have this configured), you should be mindful that the purpose of a WMS is give you map images.

A WMS does not expose the input data (or features) it gives an image representation of the features.

If you want to access features using OpenLayers through an OGC service then you'll be needing a WFS.

1

Generate a WFS url based on the CQL Filter and then you can get json data from url.

Example URL:

http://localhost:9090/geoserver/ilfs/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ilfs:dharani_samplevillage&CQL_FILTER=(bhucode=11223344444555 AND kid=243)&outputFormat=application/json

A get request on the url should give you json output.

Check GeoServer WFS Vendor Parameters for more information

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.