I'm building a WFS client service in Angular for geoserver. So far I used $http GET to retrieve features, but the cql_filter is sometimes to big and http GET does not work because of a too big URL. Could you help me translate the following http GET into an http POST? I would prefer to use CQL filtering instead of OGC if possible, since I have it implemented already. Here's my getFeature method:
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 is my trial:
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;
}
Response exception:
<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>
I would like to create the "data" xml that gives the same result as the GET request.
Fix:
THis is how the post looks like:
<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>