Several WMS layers with polygon features.


Draw a polygon with OpenLayers and allow it only if doesn't not cut any features in WMS layer. It can contain the features as a whole though.

Possible solutions:

1) Send drawn geometry server side via AJAX and return a validation response.

select count(id) FROM wms_layer_1_table,
    where ST_Intersects(<drawn geom>,the_geom)
    and ST_Contains(<drawn geom>,the_geom)=false;

if above count is zero then the drawn polygon is valid.

2) I intend to send geometries of all WMS features as text(ie,. POLYGON((x y,x1 y1)) etc) to the client side when the application loads in the browser and on addition of new ones.

With this in mind, I would like to know if and how I could validate the drawn polygon with these geometries just with OpenLayers/Javascript alone?


1 Answer 1


There are two ways to do this:

  1. on the client - in which case switch to WFS instead of WMS. You will then have the geometries in the client app and can check for intersection before you send the new polygon off tot he server.

  2. on the server - in which case you can send the polygon off to the server (as all the client has is a picture of the map). I would use WFS and/or WPS to handle the transfer and validation.

Which will work better is scenario dependent (i.e. how many features are visible on the map, how complex a polygon the user will draw etc.)

  • 1. In my case, switching to WFS would take quite a bit work.
    – Siva
    Commented Feb 11, 2013 at 5:24
  • So looking at the other option, could you elaborate on what you meant by 'using WFS and/or WPS to handle transfer and validation'? As you can see currently I run PostGIS queries (in PHP) to validate the polygon. Secondly, for client side validation (maybe a bit hackish) assuming I have the coordinates for all the WMS features could you suggest me a OpenLayers/JavaScript only way? say.. something like construct all the features(objects) from the coordinates using OpenLayers and use appropriate functions to find the intersection of the polygon.
    – Siva
    Commented Feb 11, 2013 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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