标签:
在geoserver自定义的地图中通过geoserver wfs 查询,删除,添加相关的POI。
相关操作的格式如下:
查询
<wfs:GetFeature service="WFS" version="1.0.0"
outputFormat="GML2"
xmlns:opengis="http://www.cetusOpengis.com"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
<wfs:Query typeName="opengis:qqy">
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>status</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>;
添加
<wfs:Transaction service="WFS" version="1.0.0"
outputFormat="GML2"
xmlns:opengis="http://www.cetusOpengis.com"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
<wfs:Insert handle="someprj1">
<opengis:someprj>
<opengis:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#3395" >
<gml:coordinates decimal="." cs="," ts="">13404701.212,3850391.781</gml:coordinates>
</gml:Point>
</opengis:the_geom>
<opengis:ssds>13</opengis:ssds>
<opengis:qqybh>12</opengis:qqybh>
<opengis:status>0</opengis:status>
</opengis:someprj>
</wfs:Insert>
</wfs:Transaction>;
修改
<wfs:Transaction service="WFS" version="1.0.0"
outputFormat="GML2"
xmlns:opengis="http://www.cetusOpengis.com"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
<wfs:Update typeName="opengis:qqyproject">
<wfs:Property>
<wfs:Name>qqybh</wfs:Name>
<wfs:Value>12</wfs:Value>
</wfs:Property>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>qqybh</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
</wfs:Update>
</wfs:Transaction>;
删除
<wfs:Transaction service="WFS" version="1.0.0"
outputFormat="GML2"
xmlns:opengis="http://www.cetusOpengis.com"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
<wfs:Delete typeName="opengis:qqyproject">
<ogc:Filter>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>qqybh</ogc:PropertyName>
<ogc:Literal>12</ogc:Literal>
</ogc:PropertyIsLessThan>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>qqybh</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:PropertyIsGreaterThan>
</ogc:Filter>
</wfs:Delete>
</wfs:Transaction>;
具体实现如下:
package com.geoserver; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; /** * 操作geoserver的几种方法 * * * * @Title: TODO * @Description: 实现TODO * @Copyright:Copyright (c) 2011 * @Company: * @Date:2012-8-30 * @author * @version 1.0 */ public class MainGeoService { public static void main(String[] args) { addGeoServerService(); } /** * 添加地图定的信息 */ public static void addGeoServerService(){ String layerName="loc_point"; String namespaceValue="http://www.easyway.net.cn"; double lat=139.54d; double lon=-116.23d; Map<String,String> params=new HashMap<String,String>(); params.put("FID", "loc_point.4"); params.put("NAME", "easyway_001"); params.put("OBJECT_CODE", "beijing_tsingperk_768"); params.put("HANDLE_ID", "768"); params.put("STATUS", "1"); params.put("DESCRIPTION", "this is point add by programe"); StringBuffer sb = new StringBuffer(); sb.append("<wfs:Transaction service=‘WFS‘ version=‘1.0.0‘ "); sb.append("outputFormat=‘GML2‘ "); sb.append(" xmlns:opengis=‘"+namespaceValue+"‘ "); sb.append(" xmlns:wfs=‘http://www.opengis.net/wfs‘ "); sb.append(" xmlns:ogc=‘http://www.opengis.net/ogc‘ "); sb.append(" xmlns:gml=‘http://www.opengis.net/gml‘ "); sb.append("xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-instance‘ "); sb.append(" xsi:schemaLocation=‘http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd‘> "); sb.append(" <wfs:Insert handle=‘"+layerName+"‘>"); sb.append(" <opengis:"+layerName+">"); sb.append(" <opengis:the_geom>"); sb.append(" <gml:Point srsName=‘http://www.opengis.net/gml/srs/epsg.xml#3395‘ >"); sb.append(" <gml:coordinates decimal=‘.‘ cs=‘,‘ ts=‘ ‘>"+lat+","+lon+"</gml:coordinates>"); sb.append(" </gml:Point>"); sb.append(" </opengis:the_geom>"); if(!params.isEmpty()){ for (Entry<String,String> entry : params.entrySet()) { sb.append(" <opengis:"+entry.getKey()+">"+entry.getValue()+"</opengis:"+entry.getKey()+">"); } } sb.append(" </opengis:"+layerName+">"); sb.append(" </wfs:Insert> "); sb.append(" </wfs:Transaction>"); String response = HttpUtils.doGeoServerPOST( "http://10.100.108.20:8080/geoserver/wfs?outputFormat=json", sb.toString()); System.out.println("response:"); System.out.println("" + response); } /** * 查询地图中的访问 * 假定我们指定的查询范围为bbox,根据上述参数设定,进行范围查询的Url为: * “WfsUrl?REQUEST=GetFeature&typeName= WfsNamespace : WfsLayerName &bbox=bbox&outputFormat=json”。 * bbox是怎么来的呢?bbox实际上描绘的是一个矩形,假定矩形左下角的点是Max(x1,y1),右上角的点是Min(x2,y2), * 则bbox是形如“x1,y1,x2,y2”的一个字符串。 */ public static void queryRangeGeoServerService() { //空间 String namespace="jacob"; //图层名称 String layerName="loc_point"; double minX=40.34d; double minY=65.344d; double maxX=45.34d; double maxY=67.34d; String queryRangeURL="http://10.100.108.20:8080/geoserver/wfs?REQUEST=GetFeature&typeName="+namespace+":"+layerName+"&bbox="+minX+","+minY+","+maxX+","+maxY+"&outputFormat=json"; String response = HttpUtils.doGeoServerPOST(queryRangeURL,""); System.out.println("response:"); System.out.println("" + response); } /** * 查询名称为cesuo 的地方 * */ public static void queryGeoServerService() { String namespace="jacob"; String namespaceValue="http://www.easyway.net.cn"; String layerName="loc_point"; Map<String,String> params=new HashMap<String,String>(); params.put("Name", "cesuo"); StringBuffer sb = new StringBuffer(); sb.append("<w:GetFeature service=‘WFS‘ version=‘1.1.0‘ "); sb.append(" xmlns:w=‘http://www.opengis.net/wfs‘ "); sb.append(" xmlns:f=‘"+namespaceValue+"‘ "); sb.append(" xmlns:g=‘http://www.opengis.net/gml‘ "); sb.append(" xmlns:o=‘http://www.opengis.net/ogc‘ "); sb.append(" x:schemaLocation=‘http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd WfsUrl/DescribeFeatureType?version=1.1.0&typename="+namespace+":"+layerName+"‘ "); sb.append(" xmlns:x=‘http://www.w3.org/2001/XMLSchema-instance‘>"); sb.append(" <w:Query typeName=‘f:"+layerName+"‘>"); sb.append(" <o:Filter>"); sb.append(" <o:PropertyIsEqualTo>"); if(!params.isEmpty()){ for (Entry<String,String> entry : params.entrySet()) { sb.append(" <o:PropertyName>f:"+entry.getKey()+"</o:PropertyName>"); sb.append(" <o:Literal>"+entry.getValue()+"</o:Literal>"); } } sb.append(" </o:PropertyIsEqualTo>"); sb.append(" </o:Filter>"); sb.append(" </w:Query>"); sb.append("</w:GetFeature>"); String response = HttpUtils.doGeoServerPOST( "http://10.100.108.20:8080/geoserver/wfs?outputFormat=json", sb.toString()); System.out.println("response:"); System.out.println("" + response); } /** * * 假定我们要删除的STATE_NAME为北京的点,则根据上述参数设定,此查询的url为:WfsUrl, * 同时需要将如下形式的参数信息,提交到服务器。如以post的方式, * 将参数信息写入HttpWebRequest的RequestStream中。 * */ public static void deletePointGeoServerService() { String namespace="jacob"; String namespaceValue="http://www.easyway.net.cn"; String layerName="loc_point"; Map<String,String> params=new HashMap<String,String>(); params.put("Name", "cesuo"); StringBuffer sb = new StringBuffer(); sb.append("<w:Transaction xmlns:w=‘http://www.opengis.net/wfs‘ "); sb.append(" xmlns:f=‘"+namespaceValue+"‘ xmlns:g=‘http://www.opengis.net/gml‘ "); sb.append(" service=‘WFS‘ version=‘1.1.0‘ xmlns:o=‘http://www.opengis.net/ogc‘ "); sb.append(" x:schemaLocation=‘http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd WfsUrl /DescribeFeatureType?version=1.1.0&typename="+namespace+":"+layerName+" ‘ xmlns:x=‘http://www.w3.org/2001/XMLSchema-instance‘>"); sb.append(" <w:Delete typeName=‘f:"+layerName+"‘>"); sb.append(" <o:Filter>"); sb.append(" <o:PropertyIsEqualTo>"); if(!params.isEmpty()){ for (Entry<String,String> entry : params.entrySet()) { sb.append(" <o:PropertyName>f:"+entry.getKey()+"</o:PropertyName>"); sb.append(" <o:Literal>"+entry.getValue()+"</o:Literal>"); } } sb.append(" </o:PropertyIsEqualTo>"); sb.append(" </o:Filter>"); sb.append(" </w:Delete>"); sb.append(" </w:Transaction>"); String response = HttpUtils.doGeoServerPOST( "http://10.100.108.20:8080/geoserver/wfs?outputFormat=json", sb.toString()); System.out.println("response:"); System.out.println("" + response); } }
GIS学习 Geoserver使用添加、删除、查询地图中的POI
标签:
原文地址:http://www.cnblogs.com/tian830937/p/4419757.html