240 likes | 633 Views
WMS / WFS How To. University of Minnesota Mapserver WMS/WFS Documentation with Examples. Gayathri Swaminathan University of Oklahoma gayathri@ou.edu. Table of Contents. Introduction Web Map Server (WMS) Setting up a WMS Server WMS Client Implementations Web Feature Server (WFS)
E N D
WMS / WFS How To University of Minnesota Mapserver WMS/WFS Documentation with Examples Gayathri Swaminathan University of Oklahoma gayathri@ou.edu
Table of Contents. • Introduction • Web Map Server (WMS) • Setting up a WMS Server • WMS Client Implementations • Web Feature Server (WFS) • WFS Client Implementations • Appendix
1.Introduction Client 1 WMS* Mapserver web Application Implementation (Server) The Internet Client 2 WFS** Client n Mapserver Web Application with WMS and WFS service * Web map service ** Web feature service
1.1 Terminologies • WMS – Web map service / server • WFS – Web Feature service / server • OGC – Open GIS Consortium • Mapserver – University of Minnesota’s Internet Mapping Software • GML – Geographic markup language
1.2 Standards 1) Who sets the WMS/ WFS standards? OpenGIS Consortium (OGC) – This organization is analogous to the IEEE or ANSI in organizing and coordinating the various GIS specific application development. 2) Where can I find WMS/WFS related information? • WMS 1.0.0 specification: http://www.opengis.org/docs/00-028.pdf • WMS 1.1.0 specification: http://www.opengis.org/docs/01-047r2.pdf • WMS 1.1.1 specification: http://www.opengis.org/docs/01-068r2.pdf • WMS-Dev mailing list and archive: http://www.intl-interfaces.net/mailman/listinfo/wms-dev • WMS FAQ: http://www.intl-interfaces.net/cookbook/WMS/faq/faqw.py?req=home • WMS XML Capabilities validator: http://www.digitalearth.gov/wmt/xml/validator.html • WMS Cookbook: http://www.intl-interfaces.net/cookbook/WMS/ • WFS specification: http://www.opengis.org/techno/specs/02-058.pdf • GML specification: http://www.opengis.net/gml/02-069/GML2-12.html
2. Web map server According to the Mapserver WMS How to document, “A WMS (or Web Map Server) allows for use of data from several different servers, and enables for the creation of a network of Map Servers from which clients can build customized maps.” GetCapabilities WMS CGI Implementation Request Types GetMap GetFeatureInfo DescribeLayer Mandatory requests supported per OGC recommendations Optional requests of some implementations Client’s Computer Per Mapserver’s website, Mapserver supports the following WMS versions: 1.0.0, 1.0.7, 1.1.0 (a.k.a. 1.0.8), and 1.1.1
2.1 Request Types GetCapabilities XML document with metadata of the WMS Client GetMap Client GetFeatureInfo Client Text/ Plain attribute information Clicks on map Send request Text/ Plain using Mapserver query templates set in wms_feature_info_mime_type GML features XML description of One or more layers (currently supported Only in SLD servers) DescribeLayer* Client * NOT SUPPORTED IN MAPSERVER
3. Setting up a WMS Server All WMS requests are handled by the mapserver CGI. 1. Compilation settings: In unix, mapserver should have been compiled with the “with_wms” option. In windows, the nmake.opt file should have the WMS settings uncommented and then compiled. As a result, when you do a mapserv –v the SUPPORTS should include WMS_SERVER Example 1. On Unix: $ ./mapserv -v MapServer version 4.2-beta1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=PDF OUTPUT=SWF SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE Example 2. On Windows: C:\apache\cgi-bin> mapserv -v MapServer version 4.2-beta1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=PDF OUTPUT=SWF SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS-WFS_SERVER SUPPORTS=WFS_CLIENT INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
3. Setting up WMS Continued., 2. Set up map file - Mapserver For a WMS server implementation it is required to add metadata information for each layer that is to be advertised by the server. As recommended by WMS Mapserver How to documentation (http://mapserver.gis.umn.edu/doc/wms-server-howto.html), At the map level: Map NAME Map PROJECTION Map Metadata (in the WEB Object): • wms_title • wms_onlineresource • wms_srs (unless PROJECTION object is defined using "init=epsg:...") And for each layer: Layer NAME Layer PROJECTION Layer Metadata • wms_title • wms_srs (optional since the layers inherit the map's SRS value) For a detailed description of each of the parameters mentioned above, visit the “Mapserver WMS How to” web page.
3.1 Test WMS Server Test recommendations from the Mapserver How to: 1. GetCapabilities: In a web browser, type in the URL, http://my.host.com/cgi-bin/mapserv?map=mywms.map&REQUEST=GetCapabilities Substitute my.host.com with your website and mywms.map with the absolute path to the map file in your web server Result: This request should return an XML document and prompt to save file. Save the file and open it in a XML Editor or text editors like notepad, EMacs etc., 2. GetMap In a web browser, type in the URL, http://my.host.com/cgi-bin/mapserv?map=mywms.map&VERSION=1.1.1 &REQUEST=GetMap&layers=state,province Result: If map layers state and province STATUS ON or DEFAULT then an image of the map with the layers is displayed in the Browser A complete GetMap request example: http://my.host.com/cgi-bin/mapserv?map=mywms.map&VERSION=1.1.1&REQUEST=GetMap&LAYERS=prov_bound&STYLES=&SRS=EPSG:4326&BBOX= -173.537,35.8775,-11.9603,83.8009&WIDTH=400&HEIGHT=300&FORMAT=image/png
3.2 GetMap Parameters VERSION REQUEST LAYERS STYLE SRS BBOX WIDTH HEIGHT FORMAT http://myhost/cgi-bin/mapserv?map=wms.map&VERSION=1.1.1&REQUEST=GetMap&LAYERS=prov&STYLES=&SRS=EPSG:4326&BBOX=xmin,xmax,ymin,ymax&WIDTH=400&HEIGHT=300&FORMAT=image/png WMS Server (mapserver cgi location) WMS request version Spatial reference system from EPSG file Width of returned map image Format of returned map image Map layers Map file Bounding box corners (lower left, upper right) in SRS units Request-GetMap Rendering Style for SLD support. Mapserver currently does not support this, leave empty Height of returned map image
3.3 WMS Samples Sample Map file: 1. MAP PARAMETERS – NAME TAMILNADU ….. WEB EMPTY “norecords.htm" TEMPLATE “tamilnadumap.htm" IMAGEPATH “/tmp/" IMAGEURL "/tmp/" METADATA "wms_title“ “TamilNadu WMS Server" "wms_abstract" “Tamilnadu" "wms_extent" "-633771.227805 1060738.573036 152927.340425 1689379.870746" "wms_accesscontraints" "none" "wms_contactperson" “Mahalakshmi" "wms_contactorganization" “Tamil Nadu" "wms_contactposition" "Software Engineer" "wms_fees" "none" "wms_onlineresource" "http://localhost/cgi-bin/mapserv.cgi?map=tnmap.map&" "wms_srs" "EPSG:99999" END 2. LAYER PARAMETERS – LAYER NAME state TYPE POLYGON STATUS DEFAULT DATA county PROJECTION #GEOGRAPHIC NAD83 proj=longlat ellps=GRS80 no_defs END CLASS COLOR 255 255 255 END METADATA "wms_title" "State" "wms_srs" "EPSG:4019" END END
4. WMS Client Implementations Browser WMS Server Mapserver WMS Client Arc Explorer
4.1 Connect from a browser Form URL(s) and make request to WMS Server 1. GetCapabilities Example: http://mymapserv/cgi-bin/mapserv?map=Tamilnadu.map&request=capabilities – Will get a XML document with Metadata information of the WMS Server. 2. GetMap Example: Get me a map of Tamilnadu state with rivers layer of size 500x700 http://tnmapserver/cgi-bin/mapserv?map=tnmap.map&VERSION=1.1.1&layers=state,rivers&Height=500&width=700&request=GetMap – Will get a map of tamil nadu state with the rivers layer per definition in tnmap.map Things to consider: • Do a GetCapabilities and see the advertised SRS codes. For example, Lat/Lon projection, State Plane etc., • When forming requests build from bare bones! Start with the mandatory required parameters and then add on • Image formats available for example, jpeg, png etc., can also be found in the GetCapabilities • NO STYLES SUPPORTED! MapServer currently does not support SLD based rendering stlyes • Some WMS servers charge a fee, which is again mentioned in the GetCapabilities returned XML document
4.2 Connect from Mapserver WMS Client When there is a mapserver web application that requires connect to another server for obtaining certain layers and features, Mapserver WMS Client can be used. What is needed? • Mapserver CGI compiled with WMS_CLIENT SUPPORT. When run in prompt, • mapserver cgi should respond with a “Supports=WMS_CLIENT”. • Mapfile,Templates definition similar to any other mapserver implementation. • WMS Client Layer Definition ### RIVERS FROM TAMILNADU WMS SERVER###LAYERNAME riversclTYPE POLYGON STATUS ON CONNECTIONTYPE WMS CONNECTION "http://tnmapserver/cgi- bin/mapserv?map=tnmap.map&VERSION=1.1.1&layers=rivers&TRANSPARENT=TRUE"METADATA "wms_title" “Rivers" "wms_name" “riverscl" "wms_server_version" "1.1.1" "wms_format" "image/jpeg" "wms_srs" "EPSG: 4326"ENDEND The layer definition above makes a WMS request to the TNMAPSERVER with a TNMAP.MAP for a rivers layer in Lat/Lon projection (EPSG code: 4326)
4.3 Connect from Arc Explorer Here is a good documentation on the ArcExplorer connection, http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?WMSMapserverArcExplorer What steps are needed? The following steps are a synopsis of the documentation URL above: • Get Capabilities - http://myserver.mydomain/cgi-bin/mapserv?map=/path/on/server/to/mymap.map&request=GetCapabilties • Use PHP to fake WMS 1.1.1 compatibility (visit http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?WMSMapserverArcExplorer and follow instructions under Using PHP to fake WMS 1.1.1 compliance) • Download ArcExplorer - Java Edition 4.0.1 from ESRI’s website • Download the ArcExplorer Interoperability Extension for ArcExplorer • Install ArcExplorer and then the extension in your computer • Open ArcExplorer, and click on Interoperability->Connect to WMS • Enter the URL to PHP file created in step 2, click ‘OK’ • This should connect to the WMS Server and bring in all layers advertised by the WMS Server • Just click on the checkbox next to a layer, to view layer
5. Web Feature Server (WFS) According to Mapserver’s web site Web Feature Service or WFS is, “A WFS ( Web Feature Service ) publishes feature-level geospatial data to the web. This means that instead of returning an image, as MapServer has traditionally done, the client now obtains fine-grained information about specific geospatial features of the underlying data, at both the geometry AND attribute levels.” What is required? • Mapserver compiled with PROJ 4.4.3 or greater and GDAL 1.1.8 or greater • WFS parameters are also configured in the metadata information, follow instructions here, http://mapserver.gis.umn.edu/doc42/wfs-server-howto.html on how to set up MAP metadata and LAYER metadata. • The WFS does not allow a layer to be advertised in more than one SRS. • Mapserver implictly uses the top-level SRS for all the layers defined, or if the top-level is not present (like a map projection), then the individual layer SRSs’ are used. • As indicated in the WFS Server How to, “As a rule of thumb, simply set the wfs_srs at the map level (in web metadata) and never set the wfs_srs metadata at the layer level and things will work fine for most cases”
6.WFS Client Implementation A WFS client call can be made from a mapserver web application through a layer definition in the map file. What is needed? Mapserver compiled with WFS_CLIENT support , PROJ 4.4.3 or higher, GDAL 1.1.8 or higher libCurl 7.10 or higher Sample Layer Definition: LAYER NAME "mylayer" TYPE POINT CONNECTIONTYPE WFS CONNECTION "http://tnmapserver/cgi-bin/mapserv?map=tnmap.map&SERVICE=WFS&VERSION=1.0.0&TYPENAME=mypoints PROJECTION "init=epsg:4326" METADATA "wfs_connectiontimeout" "60" # Default is 30 seconds "wfs_latlonboundingbox" "-75 45 -70 50" # Area covered by this layer END CLASS SYMBOL 'triangle' COLOR 255 0 0 END END
7. Appendix Some useful URL(s) • WMS Cookbook - http://www.intl-interfaces.net/cookbook/WMS/ • WMS How To - http://mapserver.gis.umn.edu/doc42/wms-server-howto.html • WMS Wiki - http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?WMSMapServer • WFS - http://mapserver.gis.umn.edu/doc42/wfs-server-howto.html • WFS Client How to - http://mapserver.gis.umn.edu/doc/wfs-client-howto.html ACKNOWLEDGEMENTS: University of Minnesota – Mapserver Team, Developers and Users community that ever remain proactive in getting OpenGIS solutions work for community benefits.