Tuesday, 1 March 2016

wms - Use GetFeatureInfo with OpenLayers and a Bounding Polygon


I want to be able to draw a bounding polygon and have my MapServer WMS layer return every feature within that bounding box. I have it working for a single point, but I would like for the query to return every single feature within a polygon. Is that possible with WMS GetFeatureInfo? I am using OpenLayers in Java with GWT. There is a bridge between Java and the OpenLayers JS.



Answer



You cannot get information for features within a bbox using a WMS getFeatureInfo. Please have a look at the WMS reference for getFeatureInfo.


You will see that according to the standards, you can only pass in points, not a bbox.


Instead, you could use a getFeature Operation on the WFS service.




The BBOX parameter allows you to search for features that are contained (or partially contained) inside a box of user-defined coordinates. The format of the BBOX parameter is bbox=a1,b1,a2,b2wherea1, b1, a2, and b2 represent the coordinate values.



An example request involving returning features based on bounding box would be in the following format:


http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeName=namespace:featuretype&
srsName=CRS
bbox=a1,b1,a2,b2


(Please note, that I have linked to the geoserver site, instead of the actual OGC standards, as the Geoserver website is far more readable than the OGC standards.)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...