Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use postgis, geoserver and openlayers for gis development.

I simply reach from goeserver to postgis table or view and show it with openlayers. but I need some filtering operation on my spatial data. For example I have historical spatial data and filter them to start_date and finish_date like

select ....... from ...... where date between :start_date and :finish_date

the problem is start_date and finish_date are dynamic. User change them from web my open layer web project. How can I do it? from geoserver?from postgis or openlayers?


share|improve this question

You could use either CQL filter query or Parametric SQL Views of Geoserver.

With Geoserver SQL Views you can define parameters like:

select gid, geom, col1, col2 from table1 where date between %start_date% and %finish_date%

And with OpenLayers you query these with

var wms = new OpenLayers.Layer.WMS('name of layer',
                                    {layers: 'NameOfTheViewLayer',
                                     viewparams: 'start_date:2013-1-15;finish_date:2013-1-18'

When these have to updated dynamically

wms.mergeNewParams({viewparams: 'start_date:2013-2-5;finish_date:2013-3-12'});
share|improve this answer
marvelous answers, i try and share result thank you very much – JavaMAN Mar 20 '13 at 11:43

You can use the CQL feature that is available in Geoserver to specify dynamic filters on your layers.

In your case you would have to get the dates as specified by the user in the UI and then through some javascript modify the layer parameters by appending a properly built CQL filter. The OpenLayer API call is like the following:

wms_layer.mergeNewParams({'CQL_FILTER': "your filter here"});
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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