0

I have a multipolygon layer in GeoServer. The layer represents states within a country. I want to enable a user to search for a specific state, and then only the selected state to be displayed on the base map.

The problem is two-fold: First, how to retrieve the names of polygons in the layer to enable a user to select, and second, how to display only the selected polygon on the base map.

I'm using OpenLayers for presentation. In addition, I'm using GeoServer and PostGIS. Any pointers on how to proceed?

EDIT: From some research, I'm guessing I'll have to use GeoServer filters (CQL and ECQL) as outlined here. However, I'm still a newbie at this, and any advice will be appreciated.

1

In order to get the list of possible values using WFS the only way is to make a GetFeature request that asks for only the name in the propertyName parameter (it's a comma separated list of values).

This should work fine as long as all the features have unique values anyways, if you are looking to extract the list of unique values out of a dataset that has duplicates WFS is not the answer, it cannot perform aggregations, you should look in WPS instead, it has a gs:Aggregate process that can perform the aggregations for you.

0

I've found a solution to the second bit of this question. The answer lies in using CQL/ECQL filters.

To display only a specific polygon, for instance, I would have the following code:

           var wms_layer = new OpenLayers.Layer.WMS(
            "Sample WMS Layer",
            "http://192.168.1.41:8081/geoserver/wms",
            {layers: "layer_name", transparent: true},
            {isBaseLayer: false, visibility: false}
        );
        wms_layer.mergeNewParams({'CQL_FILTER': "attr_name = 'value' AND ..."})

And you can put as many filter conditions as is needed.

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.