1

I need to create the GetSpatialDataSet stored query in my WFS service to follow the INSPIRE rules.

That WFS service is in a GeoServer 2.10.0. I have checked the official docs about how to create a stored query: http://docs.geoserver.org/stable/en/user/services/wfs/reference.html

The problem is I don't know what I am supposed to do with that piece of code.

<wfs:CreateStoredQuery service='WFS' version='2.0.0'
 xmlns:wfs='http://www.opengis.net/wfs/2.0'
 xmlns:fes='http://www.opengis.org/fes/2.0'
 xmlns:gml='http://www.opengis.net/gml/3.2'
 xmlns:myns='http://www.someserver.com/myns'
 xmlns:topp='http://www.openplans.org/topp'>
<wfs:StoredQueryDefinition id='myStoredQuery'>
<wfs:Parameter name='AreaOfInterest' type='gml:Polygon'/>
<wfs:QueryExpressionText
 returnFeatureTypes='topp:states'
 language='urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression'
 isPrivate='false'>
  <wfs:Query typeNames='topp:states'>
    <fes:Filter>
      <fes:Within>
        <fes:ValueReference>the_geom</fes:ValueReference>
         ${AreaOfInterest}
      </fes:Within>
    </fes:Filter>
  </wfs:Query>
</wfs:QueryExpressionText>

Where should I paste it? It says it's a POST request, but that doesn't tell me anything.

EDIT: I have tried the following script from another answer:

<html>
<head>
<title>WFS Test</title>
<script language="JavaScript">
  function doit()
  {
    var url = 'http://myserver:8080/geoserver/test/wfs';
    var method = 'POST';
    var postData = '<wfs:CreateStoredQuery\n'
    + 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'
    + 'xsi:schemaLocation=\n'
    + '"http://www.opengis.net/wfs/2.0\n'
    + 'http://schemas.opengis.net/wfs/2.0/wfs.xsd"\n'
    + 'xmlns:cp_inspire="urn:x-
inspire:specification:gmlas:CadastralParcels:4.0"\n'
    + 'xmlns:fes="http://www.opengis.org/fes/2.0"\n'
    + 'xmlns:wfs="http://www.opengis.net/wfs/2.0"\n'
    + 'xmlns:gml="http://www.opengis.net/gml/3.2"\n'
    + 'xmlns:xsd="http://www.w3.org/2001/XMLSchema"\n'
    + 'service="WFS"\n'
    + 'version="2.0.0">\n'
    + '<wfs:StoredQueryDefinition\n'
    + 'id=\'' + 
'http://inspire.ec.europa.eu/operation/download/GetSpatialDataSet' + '\'>\n'
    + '<wfs:Parameter name=\'' + 'CRS' + '\' type=\'' + 'xsd:string' + '\'/>\n'
    + '<wfs:Parameter name=\'' + 'DataSetIdCode' + '\' type=\'' + 'xsd:string' +'\'/>\n'
    + '<wfs:Parameter name=\'' + 'DataSetIdNamespace' + '\' type=\'' + 'xsd:string' +'\'/>\n'
    + '<wfs:Parameter name=\'' + 'Language' + '\' type=\'' + 'xsd:string' + '\'/>\n'
    + '<wfs:Parameter name="count" type="xsd:integer"></wfs:Parameter>\n'
    + '<wfs:QueryExpressionText\n'
    + 'returnFeatureTypes=\'' + 'cp_inspire:CP.CadastralParcel' + '\'\n'
    + 'language=\'' + 'urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression' + '\'\n'
    + 'isPrivate=\'' + 'false' + '\'>\n'
    + '<wfs:Query typeNames=\'' + 'cp_inspire:CP.CadastralParcel' + '\' srsName="${CRS}">\n'
    + '</wfs:Query>\n'
    + '</wfs:QueryExpressionText>\n'
    + '</wfs:StoredQueryDefinition>\n'
    + '</wfs:CreateStoredQuery>\n';

var req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
req.setRequestHeader('Content-type', 'test/xml');
req.onreadystatechange = function () {
  if (req.readyState != 4) return;
  if (req.status != 200 && req.status != 304) {
    alert('HTTP error ' + req.status);
    return;
  }
  alert(req.responseText);
}
if (req.readyState == 4) return;
req.send(postData);

}

But I'm getting this error:

enter image description here

Does anyone see where is the problem?

0

2 Answers 2

2

See the following post on INSPIRE Thematic Clusters: It seems that there is only one fully compliant solution to serve multiple harmonised datasets trough WFS 2.0

It appears that your problem is related to a bug in GeoServer fixed in version 2.12-beta.

1
  • Thanks for the answer. That's a bug I will face later. In my request I'm using just one Type Name, so I don't think it's the same issue.
    – O.D.
    May 31, 2017 at 6:09
2

I modified your request a bit to use JQUERY and test with the data I had available, but this one seemed to work:

<html>
<head>
    <title>WFS Test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
    Press this button to create a stored Query with the parameters<br>
    <input type="button" value="doit" onclick="doit()"/>
    <script language="JavaScript">
        function doit() {
            $.ajax({ type: 'POST',
                url: 'http://myserver:8080/geoserver/wfs?',
                data: '<wfs:CreateStoredQuery service="WFS" version="2.0.0"'
                        + ' xmlns="http://www.opengis.net/wfs/2.0"'
                        + ' xmlns:wfs="http://www.opengis.net/wfs/2.0"'
                        + ' xmlns:fes="http://www.opengis.org/fes/2.0"'
                        + ' xmlns:ows="http://www.opengis.net/ows/1.1"'
                        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema">'
                        + '<wfs:StoredQueryDefinition id="http://inspire.ec.europa.eu/operation/download/GetSpatialDataSet">'
                        + '<wfs:Title>Stored Query for hy-n:WatercourseLink</wfs:Title>'
                        + '<wfs:Parameter name="CRS" type="xsd:string" />'
                        + '<wfs:Parameter name="DataSetIdCode" type="xsd:string" />'
                        + '<wfs:Parameter name="DataSetIdNamespace" type="xsd:string" />'
                        + '<wfs:Parameter name="Language" type="xsd:string" />'
                        + '<wfs:Parameter name="count" type="xsd:integer" />'
                        + '<wfs:QueryExpressionText returnFeatureTypes="hy-n:WatercourseLink" language="urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression" isPrivate="false">'
                        + '<wfs:Query typeNames="hy-n:WatercourseLink" srsName="${CRS}">'
                        + '</wfs:Query>'
                        + '</wfs:QueryExpressionText>'
                        + '</wfs:StoredQueryDefinition>'
                        + '</wfs:CreateStoredQuery>',
                contentType: "text/xml",
                dataType: "text",
                error: function (xhr, ajaxOptions, thrownError) {
                    console.log(xhr.status);
                    console.log(thrownError);
                }
            });
        }
    </script>
</body>

You may encounter some additional namespace issues, depending on your GeoServer workspaces.

Once it works, you can use other commands like

http://myserver:8080/geoserver/wfs?request=ListStoredQueries&version=2.0.0&service=WFS

to see all your Stored Queries,

http://myserver:8080/geoserver/wfs?request=DescribeStoredQueries& storedQuery_Id=http://inspire.ec.europa.eu/operation/download/GetSpatialDataSet

to show associated Metadata or

http://myserver:8080/geoserver/wfs?request=DropStoredQuery&storedQuery_Id=http://inspire.ec.europa.eu/operation/download/GetSpatialDataSet

to drop the element again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.