我正在 Angular 中为地理服务器构建 WFS 客户端服务。到目前为止,我使用 $http GET 来检索功能,但是 cql_filter 有时会很大,并且由于 URL 太大,http GET 不起作用。你能帮我把下面的http GET翻译成http POST吗?如果可能的话,我更喜欢使用 CQL 过滤而不是 OGC,因为我已经实现了它。这是我的 getFeature 方法:
this.getWfsFeature = function(typeName, filter){
var deffered = $q.defer();
$http({
method: 'GET',
url: ConfigService.getGeoserverURL() + "/frqaim/ows",
params: {
service: 'WFS',
version: '1.0.0',
cql_filter: filter,
request: 'GetFeature',
typeName: typeName,
maxFeatures: 60,
outputFormat:'application/json'
},
}).success(function(data){
deffered.resolve(data.features);
}).error(function(data, status, headers, config) {
var msg = 'could not get wfs features. status: ' + status;
console.log(msg);
deffered.reject(msg);
});
return deffered.promise;
}
这是我的试验:
this.getWfsFeature2 = function(typeName, filter){
var deffered = $q.defer();
$http({
method: 'POST',
url: ConfigService.getGeoserverURL() + "/frqaim/ows",
data: {
service: 'WFS',
version: '1.0.0',
cql_filter: filter,
request: 'GetFeature',
typeName: typeName,
maxFeatures: 60,
outputFormat:'application/json'
}
}).success(function(data){
deffered.resolve(data.features);
}).error(function(data, status, headers, config) {
var msg = 'could not get wfs features. status: ' + status;
console.log(msg);
deffered.reject(msg);
});
return deffered.promise;
}
响应异常:
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://localhost:8081/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="NoApplicableCode">
<ows:ExceptionText>org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1)
only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1) </ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
我想创建与 GET 请求给出相同结果的“数据”xml。
使固定:
这是帖子的样子:
<wfs:GetFeature service="WFS" version="1.0.0" request="getFeature" outputFormat="application/json"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gml="http://www.opengis.net/gml"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
<wfs:Query typeName="typeName">
<ogc:Filter>
<ogc:And>
<ogc:Within>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>-62,48.30519115013797 -62,56.525823385131694 -30,56.525823385131694 -30,48.30519115013797 -62,48.30519115013797 </gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ogc:Within>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>propName</ogc:PropertyName>
<ogc:Literal>value</ogc:Literal>
</ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>propName</ogc:PropertyName>
<ogc:Literal>value</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>valid_to</ogc:PropertyName>
<ogc:Function name="dateParse">
<ogc:Literal>yyyy-MM-dd'T'hh:mm:ss.SSSZ</ogc:Literal>
<ogc:Literal>2015-03-06T09:47:46.260Z</ogc:Literal>
</ogc:Function>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>valid_from</ogc:PropertyName>
<ogc:Function name="dateParse">
<ogc:Literal>yyyy-MM-dd'T'hh:mm:ss.SSSZ</ogc:Literal>
<ogc:Literal>2015-03-06T10:47:46.260Z</ogc:Literal>
</ogc:Function>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>