GeoServer-WMS,WFS,WCS

目录

GeoServer-WMS,WFS,WCS

sf2gis@163.com

2016年8月23日重构

2016年10月17日添加jsonp操作

1 方法:发布WMS

1.1 目标:WMS(OpenGIS Web Map Service),将地图数据发布为WEB服务,提供网络地图图片。

功能包括:GetCapabilities,GetMap,GetFeatureInfo,GetLegendGraphic。

1.2 发布:图层上设置发布信息,保存后就可以发布了。

1.3 测试:使用QGIS测试

1.3.1获取WMS地址

1.3.1.1  获取WMS地址:http://服务器IP:PORT/geoserver[/工作空间[/图层名]]/wms

如果可选部分不使用的话,将获取其下所有的服务。

1.3.1.2  或从WMS的文档中获取:在OnlineReference中获取。

1.3.1.3  或在LayerPreview中选择需要服务:

从中获取服务地址,只需要到WMS就可以,http://localhost:8080/geoserver/testShp/wms

 

1.3.2在Qgis加载WMS服务:设置连接参数

将WMS地址输入,设置名字,就可以查看当前工作区中所有WMS服务。选择需要的图层,加入到Qgis中进行显示。

 

1.4 示例:

WMS GetMap:

http://localhost:8080/geoserver/testShp/wms?service=WMS&version=1.1.0&request=GetMap&layers=testShp:states&styles=&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=768&height=330&srs=EPSG:4326&format=application/openlayers

WMS GetFeatureInfo:

http://localhost:8080/geoserver/testShp/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=testShp%3Astates&LAYERS=testShp%3Astates&STYLES&INFO_FORMAT=text%2Fhtml&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&WIDTH=101&HEIGHT=101&BBOX=-97.82817456250004%2C36.41678068750001%2C-88.95122143750004%2C45.29373381250001

返回值:

<html>

<head>

<title>Geoserver GetFeatureInfo output</title>

</head>

<style type=”text/css”>

table.featureInfo, table.featureInfo td, table.featureInfo th {

border:1px solid #ddd;

border-collapse:collapse;

margin:0;

padding:0;

font-size: 90%;

padding:.2em .1em;

}

table.featureInfo th {

padding:.2em .2em;

font-weight:bold;

background:#eee;

}

table.featureInfo td{

background:#fff;

}

table.featureInfo tr.odd td{

background:#eee;

}

table.featureInfo caption{

text-align:left;

font-size:100%;

font-weight:bold;

padding:.2em .2em;

}

</style>

<body>

<table class=”featureInfo”>

<caption class=”featureInfo”>states</caption>

<tr>

<th>fid</th>

<th >STATE_NAME</th>

<th >STATE_FIPS</th>

<th >SUB_REGION</th>

<th >STATE_ABBR</th>

<th >LAND_KM</th>

<th >WATER_KM</th>

<th >PERSONS</th>

<th >FAMILIES</th>

<th >HOUSHOLD</th>

<th >MALE</th>

<th >FEMALE</th>

<th >WORKERS</th>

<th >DRVALONE</th>

<th >CARPOOL</th>

<th >PUBTRANS</th>

<th >EMPLOYED</th>

<th >UNEMPLOY</th>

<th >SERVICE</th>

<th >MANUAL</th>

<th >P_MALE</th>

<th >P_FEMALE</th>

<th >SAMP_POP</th>

</tr>

<tr>

<td>states.36</td>

<td>Iowa</td>

<td>19</td>

<td>W N Cen</td>

<td>IA</td>

<td>144715.989</td>

<td>1037.659</td>

<td>2776755.0</td>

<td>740819.0</td>

<td>1064325.0</td>

<td>1344802.0</td>

<td>1431953.0</td>

<td>1013757.0</td>

<td>970933.0</td>

<td>156930.0</td>

<td>16373.0</td>

<td>1340242.0</td>

<td>63641.0</td>

<td>429860.0</td>

<td>217271.0</td>

<td>0.484</td>

<td>0.516</td>

<td>579075.0</td>

</tr>

</table>

<br/>

</body>

</html>

参考:http://blog.csdn.net/chenxiaodan_danny/article/details/42675411

2方法:发布WFS

2.1 目标:WFS(Web Feature Service)目的是提供对矢量地图的查询、编译等操作。

功能包含:GetCapabilities,DescribeFeatureType,GetFeature(查询),LockFeature(加锁,用于事务),Transaction(编辑事务)。

2.2 发布:将工作区设置为WFS启用,然后在Layer中设置发布属性。

参考:http://girona-geoserver-workshop.readthedocs.org/en/latest/overview/wfs.html

https://wiki.state.ma.us/confluence/display/massgis/GeoServer+-+WFS+-+Extract+-+Shapefile+Format

2.2.1启用jsonp输出格式:默认是禁止的。

参考:

http://gis.stackexchange.com/questions/57494/geoserver-2-3-how-to-enable-jsonp

http://stackoverflow.com/questions/15647259/geoserver-not-returning-correct-json-for-wfs-using-openlayers-protocol-script

在web.xml中去掉jsonp的注释。

jsonp将返回parseResponse()函数调用。

示例:参见:leaflet.docx《Identify地图元素信息:JSONP跨域操作》部分。

2.3 测试:QGIS加载WFS,并执行编辑。

2.3.1获取WFS地址:与WMS相似

2.3.1.1  获取WMS地址:http://服务器IP:PORT/geoserver[/工作空间[/图层名]]/WFS

2.3.1.2  或从WMS的文档中获取:在Operation中获取Url,但这样获取的是所有的WFS。

2.3.1.3  或在LayerPreview中选择需要服务,从中获取xsi:schemaLocation中找到wfs地址。

2.3.2在Qgis加载WFS服务:设置连接参数,添加图层。

 

WFS可以进行图层编辑

2.4 示例:

http://localhost:8080/geoserver/wfs?request=GetFeature&version=1.0.0&typename=testShp:states&featureid=states.2

返回值:

This XML file doesnot appear to have any style information associated with it. The document treeis shown below.

<wfs:FeatureCollection xmlns=”http://www.opengis.net/wfs” xmlns:wfs=”http://www.opengis.net/wfs” xmlns:testShp=”localhost:8080/testShp” xmlns:gml=”http://www.opengis.net/gml”xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.opengis.net/wfshttp://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-basic.xsdlocalhost:8080/testShphttp://localhost:8080/geoserver/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=testShp%3Astates”>

<gml:boundedBy>

<gml:null>unknown</gml:null>

</gml:boundedBy>

<gml:featureMember>

<testShp:states fid=”states.2″>

<testShp:the_geom>

<gml:MultiPolygon srsName=”http://www.opengis.net/gml/srs/epsg.xml#4326″>

<gml:polygonMember>

<gml:Polygon>

<gml:outerBoundaryIs>

<gml:LinearRing>

<gml:coordinates xmlns:gml=”http://www.opengis.net/gml” decimal=”.” cs=”,” ts=” “>

-77.008232,38.966557-76.911209,38.889988 -77.045448,38.78812 -77.035248,38.813915-77.045189,38.829365 -77.040405,38.838413 -77.039078,38.862431-77.067886,38.886101 -77.078949,38.9156 -77.122627,38.93206-77.042389,38.993431 -77.008232,38.966557

</gml:coordinates>

</gml:LinearRing>

</gml:outerBoundaryIs>

</gml:Polygon>

</gml:polygonMember>

</gml:MultiPolygon>

</testShp:the_geom>

<testShp:STATE_NAME>Districtof Columbia</testShp:STATE_NAME>

<testShp:STATE_FIPS>11</testShp:STATE_FIPS>

<testShp:SUB_REGION>SAtl</testShp:SUB_REGION>

<testShp:STATE_ABBR>DC</testShp:STATE_ABBR>

<testShp:LAND_KM>159.055</testShp:LAND_KM>

<testShp:WATER_KM>17.991</testShp:WATER_KM>

<testShp:PERSONS>606900.0</testShp:PERSONS>

<testShp:FAMILIES>122087.0</testShp:FAMILIES>

<testShp:HOUSHOLD>249634.0</testShp:HOUSHOLD>

<testShp:MALE>282970.0</testShp:MALE>

<testShp:FEMALE>323930.0</testShp:FEMALE>

<testShp:WORKERS>229975.0</testShp:WORKERS>

<testShp:DRVALONE>106694.0</testShp:DRVALONE>

<testShp:CARPOOL>36621.0</testShp:CARPOOL>

<testShp:PUBTRANS>111422.0</testShp:PUBTRANS>

<testShp:EMPLOYED>303994.0</testShp:EMPLOYED>

<testShp:UNEMPLOY>23442.0</testShp:UNEMPLOY>

<testShp:SERVICE>65498.0</testShp:SERVICE>

<testShp:MANUAL>22407.0</testShp:MANUAL>

<testShp:P_MALE>0.466</testShp:P_MALE>

<testShp:P_FEMALE>0.534</testShp:P_FEMALE>

<testShp:SAMP_POP>72696.0</testShp:SAMP_POP>

</testShp:states>

</gml:featureMember>

</wfs:FeatureCollection>

 

3方法:发布WCS

3.1 目标:WCS(Web Coverage Service),目标是发布原始栅格数据。

功能包括GetCapabilities,GetCoverage,DescribeCoverage。

3.2 发布:工作空间启用WCS并设置图层的发布属性。

3.3 测试:QGIS加载WCS

3.3.1获取WMS地址

3.3.1.1  获取WMS地址:http://服务器IP:PORT/geoserver[/工作空间[/图层名]]/WCS

3.3.1.2  或从WMS的文档中获取:在Operation中获取Url,但这样获取的是所有的WCS。

 

3.3.1.3  或演示中获取地址

3.3.2QGIS中加载WCS

WCS图片加载完成后,可能会有空白的地方,这是因为默认将0值设置为无值像素。

在图层属性中将无值像素去掉,可以正常显示。

3.4 测试:使用演示-》WCS Request Builder可以生成请求POST的XML和测试。

参考:

http://support.supermap.com.cn:8090/iserver/help/html/mergedProjects/iServerJavadoc/com/supermap/services/protocols/wcs/wcs.html

示例:

 

GetCoverage则下载图像。

点击Generate就可以生成XML。

<?xmlversion=”1.0″ encoding=”UTF-8″?>

<GetCoverageversion=”1.0.0″ service=”WCS”xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xmlns=”http://www.opengis.net/wcs” xmlns:ows=”http://www.opengis.net/ows/1.1″xmlns:gml=”http://www.opengis.net/gml”xmlns:ogc=”http://www.opengis.net/ogc”xsi:schemaLocation=”http://www.opengis.net/wcshttp://schemas.opengis.net/wcs/1.0.0/getCoverage.xsd”>

  <sourceCoverage>nurc:Img_Sample</sourceCoverage>

  <domainSubset>

    <spatialSubset>

      <gml:EnvelopesrsName=”EPSG:4326″>

        <gml:pos>-130.8516820.7052</gml:pos>

        <gml:pos>-62.005454.1141</gml:pos>

      </gml:Envelope>

      <gml:Grid dimension=”2″>

        <gml:limits>

          <gml:GridEnvelope>

            <gml:low>0 0</gml:low>

            <gml:high>983597</gml:high>

          </gml:GridEnvelope>

        </gml:limits>

       <gml:axisName>x</gml:axisName>

       <gml:axisName>y</gml:axisName>

      </gml:Grid>

    </spatialSubset>

  </domainSubset>

  <output>

    <crs>EPSG:4326</crs>

    <format>GeoTIFF</format>

  </output>

</GetCoverage>

转载自:https://blog.csdn.net/sf2gis2/article/details/52854030

You may also like...