目录
一、WFS的简单介绍
二、WFS请求与响应的格式
三、WFS服务器与客户端
WebGIS服务器除了能返回一张地图图像之外,也可以返回绘制该地图图像所使用的真实地理数据。用户利用这些数据可以创建他们自己的地图与应用、数据格式转换以及底层的地理操作。这类返回地理要素数据的规范称为WFS(Web Feature Service——Web要素服务)。
只要服务器和客户端遵循统一规范,那么服务器与客户端传送的数据可以是任意格式的。为了规范通过Web服务发送矢量数据的过程,OGC制定了WFS规范。
那么WMS与WFS有什么区别呢?
WMS是由服务器将一地图图像发送给客户端,而WFS是服务器将矢量数据发送给客户端,也就是在使用WMS时地图由服务器绘制,在使用WFS时地图由客户端绘制。
与WMS类似,WFS也支持直接在URL地址中加参数方式的操作,这些操作包括:
下面是在WFS中GetFeatures操作的例子,该请求用于获取本地计算机GeoServer自带数据的topp:states图层的要素数据:
http://localhost:8084/geoserver/topp/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=topp:states&featureid=states.12
在上述请求中:
WFS使用地理标记语言(Geography Markup Language,GML)返回数据。GML可以同时包含图形与属性信息。由于GML是基于XML的,因此比GeoJSON要冗长得多。
上述请求返回的结果为:
34.92905 -94.439102 34.735504 -94.44574 34.508327 -94.452408 34.196655 -94.461479 33.939198 -94.468376 33.631966 -94.476486 33.623047 -94.50061 33.63081 -94.510559 33.621021 -94.525055 33.643009 -94.51799 33.632694 -94.550194 33.635536 -94.562149 33.64283 -94.562195 33.648247 -94.541931 33.661621 -94.545418 33.652157 -94.576462 33.655449 -94.588387 33.662132 -94.585159 33.663013 -94.565208 33.671913 -94.560722 33.670471 -94.578506 33.678982 -94.585106 33.665607 -94.600945 33.683899 -94.631737 33.670105 -94.638763 33.663738 -94.658539 33.666061 -94.669426 33.671459 -94.667953 33.67765 -94.644325 33.692291 -94.655479 33.696537 -94.668457 33.690289 -94.690987 33.701267 -94.741653 33.707771 -94.754478 33.719048 -94.742111 33.716797 -94.762718 33.736706 -94.749771 33.733665 -94.783157 33.742268 -94.782028 33.752842 -94.764175 33.753262 -94.783508 33.739582 -94.803223 33.749405 -94.81916 33.749321 -94.85788 33.774963 -94.881638 33.789597 -94.913879 33.803478 -94.908546 33.816196 -94.918236 33.815807 -94.940399 33.840824 -94.939888 33.848076 -94.959908 33.866215 -94.968704 33.856182 -94.989281 33.869946 -95.012772 33.866451 -95.037361 33.884445 -95.042862 33.896694 -95.063141 33.917648 -95.063477 33.888462 -95.083603 33.896915 -95.089714 33.918453 -95.082268 33.921738 -95.09536 33.912281 -95.119225 33.917145 -95.126678 33.940868 -95.127968 33.943546 -95.148315 33.964863 -95.234039 33.936443 -95.251289 33.905022 -95.250992 33.8978 -95.263618 33.917938 -95.277351 33.886902 -95.28643 33.886623 -95.301956 33.897114 -95.336227 33.870918 -95.33004 33.865753 -95.451607 33.886433 -95.468124 33.881718 -95.498856 33.897736 -95.512886 33.885742 -95.544037 33.893158 -95.547493 33.897816 -95.526733 33.906643 -95.519577 33.904034 -95.546318 33.936073 -95.562775 33.944553 -95.606071 33.936691 -95.61483 33.920238 -95.612984 33.920105 -95.633492 33.894825 -95.699707 33.903397 -95.746864 33.89344 -95.760696 33.879005 -95.764252 33.851402 -95.768517 33.864674 -95.795479 33.843025 -95.825974 33.841038 -95.846558 33.89053 -95.933075 33.889973 -95.943069 33.86504 -95.958763 33.857952 -95.977394 33.875378 -95.994209 33.87339 -96.002617 33.856979 -96.001793 33.844208 -96.014069 33.856022 -96.026749 33.841278 -96.047974 33.844578 -96.091522 33.829258 -96.109444 33.83559 -96.148964 33.828983 -96.169205 33.815792 -96.183128 33.808434 -96.180725 33.823944 -96.154518 33.82032 -96.141418 33.798229 -96.161316 33.769356 -96.168816 33.758583 -96.187027 33.756691 -96.212547 33.773388 -96.278076 33.761932 -96.28968 33.71405 -96.300789 33.701801 -96.316277 33.705528 -96.347588 33.740395 -96.370819 33.788326 -96.419464 33.77813 -96.487373 33.78809 -96.500748 33.815685 -96.510574 33.82542 -96.562134 33.842957 -96.601196 33.8629 -96.614166 33.896145 -96.584488 33.913544 -96.666237 33.904324 -96.677704 33.847904 -96.693382 33.83387 -96.711678 33.831738 -96.748825 33.869949 -96.797592 33.871769 -96.814117 33.858032 -96.844009 33.861679 -96.861015 33.884003 -96.878937 33.924591 -96.882851 33.950027 -96.898453 33.961773 -96.929565 33.947849 -96.936203 33.937321 -96.968185 33.944202 -96.987862 33.876423 -96.987709 33.850513 -97.005852 33.840561 -97.025597 33.856728 -97.0709 33.851101 -97.082176 33.837811 -97.078247 33.823448 -97.050026 33.807571 -97.087669 33.742413 -97.083466 33.73167 -97.0905 33.725933 -97.115562 33.728668 -97.152473 33.752769 -97.189163 33.819649 -97.208321 33.836159 -97.195015 33.847794 -97.168594 33.863148 -97.164169 33.899204 -97.187767 33.905689 -97.211334 33.894238 -97.246063 33.872971 -97.250687 33.85873 -97.263908 33.872574 -97.272278 33.89584 -97.314087 33.870392 -97.314957 33.861916 -97.341805 33.831024 -97.363319 33.820709 -97.410118 33.836212 -97.452736 33.89043 -97.457062 33.902382 -97.462761 33.907707 -97.477531 33.916771 -97.518204 33.903904 -97.554588 33.902531 -97.575668 33.917885 -97.592354 33.969437 -97.600182 33.988613 -97.671066 33.971546 -97.704262 33.939293 -97.729019 33.932098 -97.756363 33.890457 -97.790207 33.857071 -97.852547 33.855114 -97.869751 33.874023 -97.909065 33.88348 -97.954735 33.902504 -97.976379 33.912052 -97.976128 33.932518 -97.950684 33.94865 -97.962997 33.959751 -97.947754 33.971161 -97.950226 34.001286 -97.982681 33.986984 -98.023491 33.989799 -98.055557 34.005314 -98.086205 34.06982 -98.110687 34.134556 -98.094124 34.148987 -98.114868 34.138432 -98.136864 34.115368 -98.172844 34.122871 -98.277 34.13942 -98.320488 34.14212 -98.350403 34.11578 -98.384254 34.087231 -98.390953 34.082455 -98.407135 34.06583 -98.421341 34.054375 -98.448189 34.066414 -98.499519 34.105335 -98.557579 34.14193 -98.576332 34.151398 -98.607246 34.158436 -98.625992 34.147038 -98.66172 34.149998 -98.682213 34.130714 -98.705292 34.131962 -98.778534 34.145935 -98.811066 34.16082 -98.891342 34.194565 -98.952507 34.209496 -98.996193 34.198921 -99.035217 34.208359 -99.07843 34.201469 -99.127945 34.21273 -99.176155 34.223736 -99.190483 34.255646 -99.204597 34.305122 -99.196304 34.331993 -99.20549 34.368214 -99.254105 34.398285 -99.267174 34.412708 -99.323296 34.450195 -99.364204 34.428993 -99.392792 34.396744 -99.394157 34.369106 -99.409958 34.364704 -99.438377 34.383522 -99.479439 34.404068 -99.502136 34.41518 -99.553864 34.408913 -99.57785 34.384857 -99.58522 34.368557 -99.601448 34.377445 -99.684906 34.443993 -99.777687 34.501778 -99.829933 34.518627 -99.860573 34.548176 -99.8806 34.579109 -99.931908 34.579571 -99.94474 34.561863 -99.972099 34.562321 -99.996094 34.747185 -99.998878 35.030998 -99.996071 35.182182 -99.997185 35.424572 -99.994354 35.618809 -100 35.883793 -99.997726 36.057549 -99.997154 36.492519 -100.001144 36.493877 -100.006866 36.489449 -100.549416 36.489609 -100.956909 36.488022 -101.089668 36.492004 -101.620316 36.492954 -102.03421 36.490208 -102.165222 36.492344 -102.996918 36.998505 -102.997223 36.988972 -102.036758 36.988853 -102.024071 36.996666 -101.553238 36.99744 -101.071159 36.996635 -100.950142 36.997807 -100.633812 36.997623 -100.088158 36.995388 -99.998848 36.995434 -99.544243 36.99453 -99.43708 36.998043 -98.999138 36.998348 -98.539864 36.999035 -98.346794 36.998646 -98.104187 36.998543 -97.803917 36.996441 -97.46508 36.999779 -97.137375 37.000134 -96.74839 37.000538 -96.518898 36.998264 -96.005791 37.000011 -95.957703 36.998035 -95.785492 37.000938 -95.525764 37.000538 -95.406372 37.001408 -95.071693 37.00071 -95.032509 36.996983 -94.620155 36.763538 -94.62146 36.670471 -94.62085 36.489338 -94.617035 36.478714 -94.607231 36.164444 -94.552895 36.106754 -94.542198 35.760227 -94.485718 35.641003 -94.468269 35.400455 -94.428337 34.92905 -94.439102
Oklahoma
40
W S Cen
OK
177877.536
3170.998
3145585.0
855321.0
1206135.0
1530819.0
1614766.0
1146497.0
1078894.0
190902.0
7817.0
1369138.0
100931.0
405802.0
205601.0
0.487
0.513
528722.0
虽然WFS的请求与响应语法初看起来有些吓人,不过在实际使用过程中,并不需要我们手工来编写。GIS软件通常都支持查看与发布WFS服务。
正如上面所演示的,GeoServer可将图层发布为WFS服务,而且这是默认设置,并不需要用户额外的配置。其他开源GIW服务器软件,例如MapServer与Degree等也都支持创建WFS服务。
在商业软件领域,ESRI的ArcGIS Server也可用于发布WFS服务。不过ESRI开发了其自身基于REST的“要素服务”,用于完成与WFS相同功能。ESRI的ArcGIS API for JavaScript及其编辑控件使用的是其自身的要素服务,而不是标准的WFS。
对于大多数的Web地图API,通常将WFS作为一图层。例如,在OpenLayers中,地图容器中要加入一个WFS服务数据,与前面内容介绍的加入KML与GeoJSON数据一样,使用ol.layer.Vector即可,只是协议不同。对于要素的样式与符号,具体如下:
不过Leaflet以及许多其他轻量级的开源Web地图API中,并不原生支持WFS。
客户端GIS软件一般都能查看WFS服务。