Tuesday, September 7, 2010

WMS GetFeatureInfo Request Rewrite with Apache mod_rewrite (ArcGIS Server, Performance)

We had an interesting issue to deal with with regard to a WMS getFeatureInfo request with a particular WMS webmap service using ArcGIS server.  This issue had to due with performance.  The map service was of the Geologic Map of North America which contained very complicated geometries, cartography, etc so you can image the performance of dynamically generating images for WMS getMap requests from this bad boy.
View of Geologic Map of North America WMS Service in GAIA 3.4

We could have done a whole bunch of data processing such as scale dependent rendering, generalizing layers, etc (which would have been the right thing to do) but didn't really have the time or resources to do so.  Another solution you may be thinking was to cache the service but I am not convinced that ArcGIS Server caches work for WMS getMap requests given the bounding box geometry for the getMap requests are dynamic and may not match the scale and dimensions of the cache but that should be left to an entirely different discussion.

The next best thing was to rasterize the data and basically serve getMap requests based on a rasterized version of the data (in the map document itself).  This helped with performance dramatically but introduced a new issue.  Given that is was based on rasterized data, attribute data was now absent eliminating the ability to serve getFeatureInfo requests.  Our solution for this was to simply serve getFeatureInfo requests with a different service than that which serviced getMap requests.  Two services responding to different requests.  The WMS getCapabilities spec implements this capability by allowing you to simply specify an alternative OnlineResource xlink:type="" value for getFeatureInfo requests.  This works great for most clients but some don't adhere to this so we were forced to forward getFeatureInfo requests made to the original WMS service (containing the rasterized version of the data) to the new service.  Given this scenario, the base URI's for each service were:

http://certmapper.cr.usgs.gov/arcgis/rest/services/one_geology_wms/USGS_Geologic_Map_of_North_America/MapServer -- raster one

http://certmapper.cr.usgs.gov/arcgis/rest/services/one_geology_wms/USGS_Geologic_Map_of_North_America_GFI/MapServer -- vector one for getFeatureInfo requests only

To do this, we used apache mod_rewrite.  Now apache mod_rewrite is not for the faint of heart.  It is powerful but takes some time to work through.  Oh, and get your favorite regular expression cheatsheet ready because you will need it.

Anyway, here is the syntax we used to solve our problem:
The RewriteCond statement sets the stage.  In limits the scope of the following RewriteRule.  In this case, it looks for a query string variable that contains a value of "GetFeatureInfo" (we had to do some pattern matching stuff to account for caps or nocaps and to make is more explicit but that is too much for this post).  The RewriteRule then matches the first statement and replaces it with the second.  In our case, it tries to match:

/arcgis/services/one_geology_wms/USGS_Geologic_Map_of_North_America/MapServer/WMSServer 

and replace it with

http://certmapper.cr.usgs.gov/arcgis/services/one_geology_wms/USGS_Geologic_Map_of_North_America_GFI/MapServer/WMSServer. 

We actually used regular expression stuff to match it but this does the same thing and is easier to understand.  The final thing you will notice is the [P] modifier.  The replacement statement is actually mapped to a local file system location.  In our case, we needed to forward explicitly to a reverse proxy server so a fully qualified URI with the [P] does this.

Thanks to @GISBrett and @jasonbirch for suggestions and moral support on coming up with this solution :-)

5 comments:

Unknown said...

Dear Gregory,
Thanks for posting this information. In our organisation we are running ArcGIS server 9.3.1 and we experience the same problems or challenges i.e.how to create and style a getfeatureinfo window in our web application.
Short about our system and aplication:

-Arcgis server 9.3.1.
-SDE-DB on top of an MS sql-server
Our web application is based on the popular javascript API.

Currently, we use SOAP webservices to request information about object. It works ok but, requires a quite annoying configuration process every time a new service is intoduced (web.config file+ c# +css+ asmx files).

http://www.miljostatus.no/kart/
I would appreciate if you can drop few words more about: how you did it. It looks just great in One Geology portal
Best regards
Xenon/Norway

Map Vibe (Gregory L. Gunther) said...

Hello Geoendemics.

We are using simply WMS through ArcGIS Server 10 REST API. In AGS 10, you are able to adjust the style of your getFeatureInfo response fairly easily but we haven't gotten around to doing it yet. Thanks for the comment.

Karl said...

I really like how that application works. It can definitely help me in a lot of ways.

virtual office

vé máy bay từ nga về việt nam said...

Mua vé tại đại lý vé máy bay Aivivu, tham khảo

vé máy bay đi Mỹ giá rẻ

vé máy bay từ mỹ về việt nam mùa dịch

khi nào có chuyến bay từ canada về việt nam

mua vé máy bay từ nhật bản về việt nam

khi nào mở lại đường bay hàn quốc

Vé máy bay từ Đài Loan về Việt Nam

Chuyến bay cho chuyên gia nước ngoài

Unknown said...

Vint Ceramic Art | TITNIA & TECHNOLOGY
Explore febcasino.com an 메이피로출장마사지 all new “Vint Ceramic titanium ring Art” 1xbet app project wooricasinos.info on TITNIA & TECHNOLOGY. Our team of sculptors and artists have created new and