• WFS简介

1.WFS即,Web要素服务,全称WebFeatureService。GIS下,支持对地理要素的插入,更新,删除,检索和发现服务。

2.属于OGC标准下的通信协议。OGC标准下的GIS服务还有:WMS、WMTS、WCS等。

3.服务根据HTTP客户请求返回GML(Geography Markup Language、地理标识语言)数据。 WFS对应于常见桌面程序中的条件查询功能,WFS通过OGC Filter构造查询条件,支持基于空间几何关系的查询,基于属性域的查询,当然还包括基于空间关系和属性域的共同查询。

  • 自言自语

网上已经有关于wfs使用方法的文章,零零散散,有的关于insert,有关于delete,不是特别完整。这几天工作上有需求,尽快搭好了geoserver,完整地开发并测试了增删改查。其中查询使用了get请求,其他使用了post。有此文章以自备,提供较为完整的方案,如能帮助他人,再好不过。

  • GeoServer安装、部署

1.安装依赖

由于依赖于JDK,所以先按照此依赖。我安装的是1.8版本,具体版本是8u73。安装后,可以不用配置环境变量。

2.安装

安装geoserver2.15.1。注意默认端口号是8080,建议修改为其他,防止冲突。账号和密码可以使用默认的。

3.启动

安装完之后,启动服务器。可以使用开始菜单栏的快捷方式,也可以使用文件目录下的脚本。

4.登陆

登陆url→localhost:端口号。登陆后的界面:

5.新建工作区

点击左侧“工作区”,添加新的工作区。name和命名空间url,都非常重要,不要随意填写。

6.新建数据源

点击左侧“数据存储”,添加新的数据源,选择shpfile类型。指向你的shp文件。工作区选择刚刚自己新建的那个,数据源名称不是很重要。因为最终的数据源名称使用的是你的shp的文件名。

7.预览

创建完毕后,点击左侧的"Layer Preview",在列表中可以看到自己创建的数据源。点击openlayers,可以预览。

8.开启跨域权限

由于GIS应用基本上都构建于其他的服务器,这里必须开启跨域才能访问。打开如下路径的web.xml

需要Uncomment如下代码。可以直接在文本编辑器中搜索Uncomment。

-------------------------------------------------------------------分割线---------------------------------------------------------------------

9.开启读写权限

回到geoserver配置页,左侧Security→Data,在rule path中,找到*.*.W,然后勾选Grant access to any role。至此全部配置完毕

  • WFS请求

  下面以点要素为例,介绍相关协议。

1.查询

1     var xhr = new XMLHttpRequest();

     xhr.open("GET", "http://localhost:9000/geoserver/zzjz/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=zzjz%3AExport_Output&maxFeatures=50&outputFormat=application%2Fjson", true);

     xhr.onreadystatechange = function () {
//请求后的处理
}; xhr.send();

这里的zzjz是工作区名称,typeName是工作区和数据源名称, 以冒号相连,outputFormat是要求服务器返回JSON格式的结果。

实际请求内容:

请求成功会见到如下返回response:

2.新增

     var format = new ol.format.WFS();

     var xml = format.writeTransaction([feature], null, null, {
featureNS: "www.zzjz.com",
featurePrefix: "ZZJZ",
featureType: "Export_Output",
srsName: "EPSG:3857"
}); var serializer = new XMLSerializer();
var featString = serializer.serializeToString(xml); featString = featString.replace("geometry", "the_geom");
featString = featString.replace("geometry", "the_geom");
featString = featString.replace("pos", 'coordinates decimal="." cs=" "');
featString = featString.replace("pos", 'coordinates');
featString = featString.replace(" undefined", ''); var xhrInsert = new XMLHttpRequest();
xhrInsert.open("POST", "http://localhost:9000/geoserver/zzjz/ows?service=WFS", true);
xhrInsert.setRequestHeader('Content-Type', 'text/xml');
xhrInsert.send(featString);
xhrInsert.onreadystatechange = function () {
//请求后的处理
}

这里使用了ol的方法,将feature要素序列化。需要注意的是,需要将geometry标签替换为the_geom标签,将pos标签替换为coordinates标签,同时将高程数据删除。

3.删除

     var xml = '<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">';
xml += '<Delete typeName="ZZJZ:Export_Output" xmlns:ZZJZ="www.zzjz.com">';
xml += '<Filter xmlns="http://www.opengis.net/ogc">'//www.zzjz.com
xml += '<PropertyIsEqualTo>'
xml += '<PropertyName>' + propertySTR + '</PropertyName>'
xml += '<Literal>' + feature.getProperties()[propertySTR] + '</Literal>'
xml += '</PropertyIsEqualTo>'
xml += '</Filter>'
xml += '</Delete>'
xml += '</Transaction>'
var xhrDelete = new XMLHttpRequest();
xhrDelete.open("POST", "http://localhost:9000/geoserver/zzjz/ows?service=WFS", t
xhrDelete.setRequestHeader('Content-Type', 'text/xml');
xhrDelete.send(xml);
xhrDelete.onreadystatechange = function () {
}

这里使用了自己构建的GML文本,Filter指向删除条件,PropertyName指向属性名称,Literal指向属性值

4.更新(位置信息)

     var xml = '<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">';
xml += '<Update typeName="ZZJZ:Export_Output" xmlns:ZZJZ="www.zzjz.com">';
xml += '<Property>'
xml += '<Name>the_geom</Name>';
xml += '<Value>'
xml += '<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:3857">';
xml += '<coordinates decimal="." cs=",">'
xml += feature.getGeometry().getCoordinates().toString();
xml += '</coordinates>'
xml += '</Point>'
xml += '</Value>'
xml += '</Property>'
xml += '<Filter xmlns="http://www.opengis.net/ogc">'//www.zzjz.com
xml += '<PropertyIsEqualTo>'
xml += '<PropertyName>' + propertySTR + '</PropertyName>'
xml += '<Literal>' + feature.getProperties()[propertySTR] + '</Literal>'
xml += '</PropertyIsEqualTo>'
xml += '</Filter>'
xml += '</Update>'
xml += '</Transaction>'
var xhrUpdate = new XMLHttpRequest();
xhrUpdate.open("POST", "http://localhost:9000/geoserver/zzjz/ows?service=WFS", true);
xhrUpdate.setRequestHeader('Content-Type', 'text/xml');
xhrUpdate.send(xml);
xhrUpdate.onreadystatechange = function () {
}

更新位置信息,需要在Update标签下设置两个属性:Property、Filter。一个用于更新属性,一个用于设置条件。Property中的Name固定为“the_geom”,Value为要素信息。

5.更新(属性信息)

     var xml = '<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">';
xml += '<Update typeName="ZZJZ:Export_Output" xmlns:ZZJZ="www.zzjz.com">';
xml += '<Property>'
xml += '<Name>OBJECTID</Name>';
xml += '<Value>'
xml += feature.getProperties()["OBJECTID"]
xml += '</Value>'
xml += '</Property>'
xml += '<Property>'
xml += '<Name>heitht</Name>';
xml += '<Value>'
xml += feature.getProperties()["heitht"]
xml += '</Value>'
xml += '</Property>'
xml += '<Property>'
xml += '<Name>remark</Name>';
xml += '<Value>'
xml += feature.getProperties()["remark"]
xml += '</Value>'
xml += '</Property>'
xml += '<Filter xmlns="http://www.opengis.net/ogc">'//www.zzjz.com
xml += '<PropertyIsEqualTo>'
xml += '<PropertyName>' + propertySTR + '</PropertyName>'
xml += '<Literal>' + feature.getProperties()[propertySTR] + '</Literal>'
xml += '</PropertyIsEqualTo>'
xml += '</Filter>'
xml += '</Update>'
xml += '</Transaction>'
var xhrUpdate = new XMLHttpRequest();
xhrUpdate.open("POST", "http://localhost:9000/geoserver/zzjz/ows?service=WFS", true);
xhrUpdate.setRequestHeader('Content-Type', 'text/xml');
xhrUpdate.send(xml);
// xhrUpdate.send(featString);
xhrUpdate.onreadystatechange = function () {
}

更新属性信息,需要在Update标签下设置两个属性:Property、Filter。一个用于更新属性,一个用于设置条件。Property中的Name为属性名称,Value为属性值。

  • 关于Openlayers

Openlayers4.3.1的版本由于工作需要不能更换,所以构建出的文本信息与当前geoserver默认的协议格式有些不同,所以目前只在insert操作时可以使用ol的接口,直接生成文本。其他操作都必须修改大量请求内容。

个人觉得,不依赖接口反而更容易理解协议规范。

WFS1.1.0协议(增删改查)+openlayers4.3.1前端构建+geoserver2.15.1安装部署+shpfile数据源配置的更多相关文章

  1. 使用iBATIS3.0完成增删改查

    使用iBATIS3.0完成增删改查 iBATIS3.0和以前的版本有一些改变,不过学过以前版本的再学习3.0应该不是太难,3.0要求JDK1.5支持,因为其中增加了注解和泛型,这些都是JDK1.5才有 ...

  2. MVC3.0 EF增删改查的封装类

    本人亲身使用EF CodeFirst,因为增删改查都是使用EF内置的一些方法,我想把它封装到一个类调用就行了.结合网上的资料和自己的整理,若有不对的地方望斧正,感激不尽.直接上代码吧.我就用新闻的增删 ...

  3. YII2.0 数据库增删改查

    /*==================== dkhBaseModel 数据库增删改查方法 start ================================*/ //新增一条数据 publ ...

  4. hbase 2.0.2 增删改查

    package cn.hbase.demo; import java.io.IOException; import java.util.Iterator; import org.apache.hado ...

  5. 用AngularJS实现对表格的增删改查(仅限前端)

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. HBase1.2.0增删改查Scala代码实现

    增删改查工具类 class HbaseUtils { /** * 获取管理员对象 * * @param conf 对hbase client配置一些参数 * @return 返回hbase的HBase ...

  7. MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存

    目录(?)[-] 二SQL语句映射文件2增删改查参数缓存 select insert updatedelete sql parameters 基本类型参数 Java实体类型参数 Map参数 多参数的实 ...

  8. vue.js+element ui Table+spring boot增删改查

    小白初学,不懂的还是太多了,找了好多资料才做出来的先记录一下 1.先用Spring boot创建一个包含了增删改查的项目 2.创建vue.js项目 3.安装Element UI (1)进入项目文件夹下 ...

  9. MongoDB 3.0.6 安装 增删改查

    下载 安装包MSI http://yunpan.cn/cmhHdTPkXZRM2  访问密码 9b6c 上边提供的是 MongoDB 3.0.6 64Bit 的安装包 安装 如果不想直接安装在C盘.. ...

随机推荐

  1. 为什么utf8占用3个字节

    UNICODE是万能编码,包含了所有符号的编码,它规定了所有符号在计算机底层的二进制的表示顺序.有关Unicode为什么会出现就不叙述了,Unicode是针对所有计算机的使用者定义一套统一的编码规范, ...

  2. HDU 6333 莫队+组合数

    Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  3. pycharm查看代码注释的方法,代码编写日志及作者信息等

    竟然在边栏有个右键的快捷键.annotate可以查看代码书写日期及作者 鼠标悬停可以看到更加详细的时间等信息 原理应该是利用git blame

  4. 【转载】epoll与select/poll的区别总结

    因为这道题目经常被问到.干脆总结一下,免得遗漏了. 参考文章:http://www.cnblogs.com/qiaoconglovelife/p/5735936.html 1 本质上都是同步I/O 三 ...

  5. QT窗体间传值总结之Signal&Slot

    在写程序时,难免会碰到多窗体之间进行传值的问题.依照自己的理解,我把多窗体传值的可以使用的方法归纳如下: 1.使用QT中的Signal&Slot机制进行传值: 2.使用全局变量: 3.使用pu ...

  6. Teamviewer ubuntu 提示 TeamViewer Daemon is not running

    http://blog.csdn.net/laohuang1122/article/details/12657343 Ubunut 12.04下面安装了Teamviewer,刚安装完启动是没有问题的, ...

  7. iOS用户体验之-modal上下文

    iOS用户体验之-modal上下文 何为模态视图,它的作用时聚焦当前.获得用户的注意,用户仅仅有完毕模态的任务才 退出模态视图.否则你将不能运行app的任务,比如,alert view,model v ...

  8. C#中泛型方法与泛型接口 C#泛型接口 List<IAll> arssr = new List<IAll>(); interface IPerson<T> c# List<接口>小技巧 泛型接口协变逆变的几个问题

    http://blog.csdn.net/aladdinty/article/details/3486532 using System; using System.Collections.Generi ...

  9. BestCoder Round #2 1001 TIANKENG’s restaurant

    不得不说,bastcoder是个hack游戏啊.!. 题意:求最少要多少张椅子才干让全部来的客人有地方坐!! 就是一个区间的处理吧!!!和HDU  1556 我待水似流年.流年待我似水神似! ..! ...

  10. iOS开发人员:事实上你还有非常多东西须要学

    iOS 新特性总结(since iOS6) iOS 6 1.废除viewDidUnLoad 收到内存警告须要到didReceiveMemoryWarning中处理 [小技巧] -(void)didRe ...