I am making a web gis application (openlayers/geoserver) to display a layer of properties, I need to add a functionality of search in it based on the name of the owner.

A list of similar names owners with address should be displayed and when i click a particular item the map should be zoomed on the particular property location.

The problem is that i want this functionality using WMS. (I do not want it in WFS as the vector layer can be copied using QGIS or other tools, it is not secure). Please let me know how will this be possible using WMS.


Do you use Postgis? Try Ajax request. Send a name of the owner from input box to php script that return to you bounding box of the property. Than you can use that bbox in openlayers.

 // this function is written in old way - using jQuery recommended

function takePropertyGeomBasedOnName(name) {

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   xmlhttp.onreadystatechange=function() {
     if (xmlhttp.readyState==4 && xmlhttp.status==200)
//write response to 'geojson' variable
var geojson = xmlhttp.responseText;
//change json to  js variables
eval("var coord = ("+geojson+")");
var geometria = coord.geometria;

if (geometria == ''){
     alert("No properties");
} else {





Here you have php script getGeometry.php. Adjust that code for your needs. This is just quick solution.

$dbconn = pg_connect ("host=XXX port=5432 dbname=XXX user=XXX password=XXXX");
if (!$dbconn) {
    die("Error in connection: " . pg_last_error());

$query = "SELECT st_Extent(the_geom) FROM XXX WHERE \"ownerName\" = '".$name."'";
$result = pg_query($dbconn, $query);
if (!$result) {
    die("Error in SQL query: " . pg_last_error());
while ($row = pg_fetch_array($result)) {
    $geometria = $row[0] ;
echo "{ 'geometria':'$geometria'}";
  • yes i am using postgis, please send details about ajax
    – harpinder
    Aug 22 '12 at 6:59
  • Well... AJAX is the method that allows you to make bd query without reloading the whole page. Check code above to figure it out
    – Odoakr
    Aug 22 '12 at 7:52

You can add a custom param to your WMS layer called CQL_FILTER. It's a Geoserver extension to WMS which allows to specify a filter based on a SQL-like language called Common Query Language.

The documentation, along with examples and a sandbox is available at:


CQL_FILTER will work an any vector layer type supported by Geoserver (shapes, postgis, etc).

Please note that when you use a CQL_FILTER images will be generated on demand and GeoWebCache will not cache them, so performance might be impacted depending on the size of your dataset and complexity of the query.

  • Thanks for the answer, this option is fine for me as a programmer, but i am looking for a solution for a simple user, like searching for places in google earth.
    – harpinder
    Aug 22 '12 at 7:15
  • Functionality is there, the interface is up to you
    – unicoletti
    Aug 22 '12 at 9:26

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.