File v.1.1.1...master.patch of Package tinyows

From f9b0a68358b178e12752c929d522e4d9772a9b24 Mon Sep 17 00:00:00 2001
From: Olivier Courtin <olivier.courtin@oslandia.com>
Date: Mon, 26 Oct 2015 02:26:33 +0100
Subject: [PATCH 01/30] Update cgi_request.c

Increase CGI GET Limit
---
 src/struct/cgi_request.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/struct/cgi_request.c b/src/struct/cgi_request.c
index 7801be8..613e37f 100644
--- a/src/struct/cgi_request.c
+++ b/src/struct/cgi_request.c
@@ -33,7 +33,7 @@
 /*
  * Max query string length send via QUERY_STRING CGI
  */
-#define CGI_QUERY_MAX 32768
+#define CGI_QUERY_MAX 1000000
 
 
 /*

From ba686fc9dfd10cb950b16e09a9d0e0de56f2249b Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu@ip-172-31-38-220.eu-west-1.compute.internal>
Date: Wed, 6 Jan 2016 17:18:59 +0000
Subject: [PATCH 02/30] fix WFS 1.1 BBOX Envelope - POST - Need reprojection

---
 src/fe/fe_spatial_ops.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/fe/fe_spatial_ops.c b/src/fe/fe_spatial_ops.c
index 5351a2a..59ef8a8 100644
--- a/src/fe/fe_spatial_ops.c
+++ b/src/fe/fe_spatial_ops.c
@@ -433,11 +433,17 @@ static buffer *fe_bbox_layer(ows *o, buffer *typename, buffer *sql, buffer *prop
   if (transform) {
     buffer_add(sql, ',');
     buffer_add_int(sql, srid);
+    buffer_add(sql, ')');
   }
-  buffer_add(sql, ')');
 
   buffer_add_str(sql, ",");
+  if (transform) buffer_add_str(sql, "ST_Transform(");
   buffer_copy(sql, envelope);
+  if (transform) {
+    buffer_add(sql, ',');
+    buffer_add_int(sql, srid);
+    buffer_add(sql, ')');
+  }
   buffer_add_str(sql, ") AND ");
   if (transform) buffer_add_str(sql, "ST_Transform(");
 
@@ -448,11 +454,17 @@ static buffer *fe_bbox_layer(ows *o, buffer *typename, buffer *sql, buffer *prop
   if (transform) {
     buffer_add(sql, ',');
     buffer_add_int(sql, srid);
+    buffer_add(sql, ')');
   }
-  buffer_add(sql, ')');
 
   buffer_add_str(sql, " && ");
+  if (transform) buffer_add_str(sql, "ST_Transform(");
   buffer_copy(sql, envelope);
+  if (transform) {
+    buffer_add(sql, ',');
+    buffer_add_int(sql, srid);
+    buffer_add(sql, ')');
+  }
   buffer_add_str(sql, ")");
 
   return sql;

From f0312cec7dea154265749ab5f83e7dca404531cd Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu@ip-172-31-38-220.eu-west-1.compute.internal>
Date: Mon, 18 Jan 2016 03:00:24 +0000
Subject: [PATCH 03/30] add JSONP support

---
 src/ows_struct.h          |  1 +
 src/wfs/wfs_get_feature.c | 14 +++++++++++---
 src/wfs/wfs_request.c     |  3 +++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/ows_struct.h b/src/ows_struct.h
index 16f9136..111384c 100644
--- a/src/ows_struct.h
+++ b/src/ows_struct.h
@@ -273,6 +273,7 @@ enum wfs_format {
   WFS_GML311,
   WFS_GML321,
   WFS_GEOJSON,
+  WFS_JSONP,
   WFS_TEXT_XML,
   WFS_APPLICATION_XML
 };
diff --git a/src/wfs/wfs_get_feature.c b/src/wfs/wfs_get_feature.c
index 9fb1b44..1146efb 100644
--- a/src/wfs/wfs_get_feature.c
+++ b/src/wfs/wfs_get_feature.c
@@ -511,7 +511,7 @@ static buffer *wfs_retrieve_sql_request_select(ows * o, wfs_request * wr, buffer
         buffer_add_str(select, ") AS \"");
         buffer_copy(select, an->key);
         buffer_add_str(select, "\" ");
-      } else if (wr->format == WFS_GEOJSON) {
+      } else if (wr->format == WFS_GEOJSON || wr->format == WFS_JSONP) {
         buffer_add_str(select, "ST_AsGeoJSON(");
 
         /* Geometry Reprojection on the fly step if asked */
@@ -786,7 +786,14 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque
   prop = buffer_init();
   id_name = buffer_init();
 
-  fprintf(o->output, "Content-Type: application/json\n\n");
+  if (wr->format == WFS_JSONP)
+  {
+         fprintf(o->output, "Content-Type: application/javascript\n\n");
+         fprintf(o->output, "wfs_jsonp_callback(");
+
+  } else fprintf(o->output, "Content-Type: application/json\n\n");
+  
+
   fprintf(o->output, "{\"type\": \"FeatureCollection\", \"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"");
   if (ows_version_get(o->request->version) == 100)
     fprintf(o->output, "EPSG:%i", wr->srs->srid);
@@ -872,6 +879,7 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque
   }
 
   fprintf(o->output, "]}");
+  if (wr->format == WFS_JSONP) fprintf(o->output, ");");
 
   buffer_free(geom);
   buffer_free(prop);
@@ -897,7 +905,7 @@ void wfs_get_feature(ows * o, wfs_request * wr)
     else
       wfs_gml_display_results(o, wr, request_list);
 
-  } else if (wr->format == WFS_GEOJSON)
+  } else if (wr->format == WFS_GEOJSON || wr->format == WFS_JSONP)
     wfs_geojson_display_results(o, wr, request_list);
 
   /* Add here other functions to display GetFeature response in other formats */
diff --git a/src/wfs/wfs_request.c b/src/wfs/wfs_request.c
index 5befa96..1ccd215 100644
--- a/src/wfs/wfs_request.c
+++ b/src/wfs/wfs_request.c
@@ -467,6 +467,9 @@ static void wfs_request_check_output(ows * o, wfs_request * wr)
     else if (    buffer_cmp(array_get(o->cgi, "outputformat"), "JSON")
               || buffer_cmp(array_get(o->cgi, "outputformat"), "application/json"))
       wr->format = WFS_GEOJSON;
+    else if (    buffer_cmp(array_get(o->cgi, "outputformat"), "JSONP")
+              || buffer_cmp(array_get(o->cgi, "outputformat"), "application/javascript"))
+      wr->format = WFS_JSONP;
     else if (    wr->request == WFS_DESCRIBE_FEATURE_TYPE
               && buffer_cmp(array_get(o->cgi, "outputformat"), "XMLSCHEMA"))  // FIXME: really ?
       wr->format = WFS_XML_SCHEMA;

From ddcd722a8d7b3a4d5ae2620e545a36b6af4578d4 Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu@ip-172-31-38-220.eu-west-1.compute.internal>
Date: Wed, 3 Feb 2016 22:47:23 +0000
Subject: [PATCH 04/30] add callback paramter for JSONP output format

---
 src/ows_struct.h          |  1 +
 src/wfs/wfs_get_feature.c |  5 ++++-
 src/wfs/wfs_request.c     | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/ows_struct.h b/src/ows_struct.h
index 111384c..322bc1a 100644
--- a/src/ows_struct.h
+++ b/src/ows_struct.h
@@ -304,6 +304,7 @@ typedef struct Wfs_request {
   buffer * resulttype;
   buffer * sortby;
   list * sections;
+  buffer * callback;
 
   alist * insert_results;
   int delete_results;
diff --git a/src/wfs/wfs_get_feature.c b/src/wfs/wfs_get_feature.c
index 1146efb..2cbc07e 100644
--- a/src/wfs/wfs_get_feature.c
+++ b/src/wfs/wfs_get_feature.c
@@ -788,8 +788,11 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque
 
   if (wr->format == WFS_JSONP)
   {
+         assert(wr->callback);
+
          fprintf(o->output, "Content-Type: application/javascript\n\n");
-         fprintf(o->output, "wfs_jsonp_callback(");
+         fprintf(o->output, wr->callback->buf);
+         fprintf(o->output, "(");
 
   } else fprintf(o->output, "Content-Type: application/json\n\n");
   
diff --git a/src/wfs/wfs_request.c b/src/wfs/wfs_request.c
index 1ccd215..1e935be 100644
--- a/src/wfs/wfs_request.c
+++ b/src/wfs/wfs_request.c
@@ -55,6 +55,7 @@ wfs_request *wfs_request_init()
   wr->resulttype = NULL;
   wr->sortby = NULL;
   wr->sections = NULL;
+  wr->callback = NULL;
 
   wr->insert_results = NULL;
   wr->delete_results = 0;
@@ -150,6 +151,12 @@ void wfs_request_flush(wfs_request * wr, FILE * output)
     fprintf(output, "\n");
   }
 
+  if (wr->callback) {
+    fprintf(output, " callback -> ");
+    list_flush(wr->callback, output);
+    fprintf(output, "\n");
+  }
+
   fprintf(output, "]\n");
 }
 #endif
@@ -174,6 +181,7 @@ void wfs_request_free(wfs_request * wr)
   if (wr->sortby)         buffer_free(wr->sortby);
   if (wr->sections)       list_free(wr->sections);
   if (wr->insert_results) alist_free(wr->insert_results);
+  if (wr->callback)       buffer_free(wr->callback);
 
   free(wr);
   wr = NULL;
@@ -469,7 +477,15 @@ static void wfs_request_check_output(ows * o, wfs_request * wr)
       wr->format = WFS_GEOJSON;
     else if (    buffer_cmp(array_get(o->cgi, "outputformat"), "JSONP")
               || buffer_cmp(array_get(o->cgi, "outputformat"), "application/javascript"))
+    {
       wr->format = WFS_JSONP;
+
+      wr->callback = buffer_init();
+      if (!array_is_key(o->cgi, "callback"))
+          buffer_add_str(wr->callback, "wfs_jsonp_callback");
+      else 
+          buffer_copy(wr->callback, array_get(o->cgi, "callback"));
+    }
     else if (    wr->request == WFS_DESCRIBE_FEATURE_TYPE
               && buffer_cmp(array_get(o->cgi, "outputformat"), "XMLSCHEMA"))  // FIXME: really ?
       wr->format = WFS_XML_SCHEMA;
@@ -477,6 +493,9 @@ static void wfs_request_check_output(ows * o, wfs_request * wr)
       wfs_error(o, wr, WFS_ERROR_OUTPUT_FORMAT_NOT_SUPPORTED,
                 "OutputFormat is not supported", "GetFeature");
   }
+
+
+
 }
 
 

From 349947d3ce77d4b40f6d95c88e949c4151ca80e4 Mon Sep 17 00:00:00 2001
From: Jeff McKenna <jeffmckenna@gmail.com>
Date: Wed, 24 Feb 2016 17:34:26 -0400
Subject: [PATCH 05/30] handle unistd.h reference on Windows (issue #78)

---
 src/mapfile/mapfile.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/mapfile/mapfile.c b/src/mapfile/mapfile.c
index e4e109a..742a671 100644
--- a/src/mapfile/mapfile.c
+++ b/src/mapfile/mapfile.c
@@ -1672,8 +1672,10 @@ static void end_layer()
  * down here because we want the user's section 1 to have been scanned first.
  * The user has a chance to override it with an option.
  */
+#ifndef _WIN32
 #include <unistd.h>
 #endif
+#endif
 
 #ifndef YY_EXTRA_TYPE
 #define YY_EXTRA_TYPE void *

From 2e1b13c5b76e102b1f1b1b1ac5e863a479ab4076 Mon Sep 17 00:00:00 2001
From: Jeff McKenna <jeffmckenna@gmail.com>
Date: Wed, 24 Feb 2016 17:39:47 -0400
Subject: [PATCH 06/30] handle snprintf use on Windows (issue #77)

---
 src/struct/buffer.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/struct/buffer.c b/src/struct/buffer.c
index 2436834..50c77fa 100644
--- a/src/struct/buffer.c
+++ b/src/struct/buffer.c
@@ -141,7 +141,11 @@ buffer *buffer_ftoa(double f)
 
   res = buffer_init();
   while (res->size < 100) buffer_realloc(res);
+  #ifndef _WIN32
   snprintf(res->buf, 99, "%f", f);
+  #else
+  _snprintf(res->buf, 99, "%f", f);
+  #endif 
   res->use = strlen(res->buf);
 
   return res;

From cc3e5cac1922bb8e52e29bd541e522fe27b6fb08 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Thu, 3 Mar 2016 13:02:28 +0100
Subject: [PATCH 07/30] Fix segfault when inserting feature with empty content

For example with the following feature:
<wfs:Insert><world xmlns="http://www.tinyows.org/"></world></wfs:Insert>
---
 src/wfs/wfs_transaction.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/wfs/wfs_transaction.c b/src/wfs/wfs_transaction.c
index 7740133..b80cd60 100644
--- a/src/wfs/wfs_transaction.c
+++ b/src/wfs/wfs_transaction.c
@@ -505,7 +505,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
     node = n->children;
 
     /* Jump to the next element if spaces */
-    while (node->type != XML_ELEMENT_NODE) node = node->next;
+    while (node != NULL && node->type != XML_ELEMENT_NODE) node = node->next;
 
     /* Fill SQL fields and values at once */
     for ( /* empty */ ; node; node = node->next) {

From a8a29e05c570da8c143261266c2e7c1ba4c8cf88 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Thu, 3 Mar 2016 13:11:24 +0100
Subject: [PATCH 08/30] Fix segfault when inserting feature with empty geometry

For example with :
<wfs:Insert><world xmlns="http://www.tinyows.org/"><wkb_geometry xmlns="http://www.tinyows.org/"></wkb_geometry></world></wfs:Insert>
---
 src/wfs/wfs_transaction.c | 73 ++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 35 deletions(-)

diff --git a/src/wfs/wfs_transaction.c b/src/wfs/wfs_transaction.c
index b80cd60..adaa73c 100644
--- a/src/wfs/wfs_transaction.c
+++ b/src/wfs/wfs_transaction.c
@@ -541,45 +541,48 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
           elemt = node->children;
 
           /* Jump to the next element if spaces */
-          while (elemt->type != XML_ELEMENT_NODE) elemt = elemt->next;
-
-          if (!strcmp((char *) elemt->name, "Box") ||
-              !strcmp((char *) elemt->name, "Envelope")) {
-
-            fe = filter_encoding_init();
-            fe->sql = fe_envelope(o, layer_name, fe, fe->sql, elemt);
-            if (fe->error_code != FE_NO_ERROR) {
-              result = fill_fe_error(o, fe);
-              buffer_free(sql);
-              buffer_free(values);
-              buffer_free(column);
-              buffer_free(id);
+          while (elemt != NULL && elemt->type != XML_ELEMENT_NODE) elemt = elemt->next;
+          if (elemt != NULL) {
+            if (!strcmp((char *) elemt->name, "Box") ||
+                !strcmp((char *) elemt->name, "Envelope")) {
+
+              fe = filter_encoding_init();
+              fe->sql = fe_envelope(o, layer_name, fe, fe->sql, elemt);
+              if (fe->error_code != FE_NO_ERROR) {
+                result = fill_fe_error(o, fe);
+                buffer_free(sql);
+                buffer_free(values);
+                buffer_free(column);
+                buffer_free(id);
+                filter_encoding_free(fe);
+                return result;
+              }
+              buffer_copy(values, fe->sql);
               filter_encoding_free(fe);
-              return result;
-            }
-            buffer_copy(values, fe->sql);
-            filter_encoding_free(fe);
-
-          } else if (!strcmp((char *) elemt->name, "Null")) {
-            buffer_add_str(values, "''");
-          } else {
-            gml = ows_psql_gml_to_sql(o, elemt, srid_root);
-            if (gml) {
-              buffer_add_str(values, "'");
-              buffer_copy(values, gml);
-              buffer_add_str(values, "'");
-              buffer_free(gml);
+
+            } else if (!strcmp((char *) elemt->name, "Null")) {
+              buffer_add_str(values, "''");
             } else {
-              buffer_free(sql);
-              buffer_free(values);
-              buffer_free(column);
-              buffer_free(id);
-              buffer_free(layer_name);
-
-              result = buffer_from_str("Error invalid Geometry");
-              return result;
+              gml = ows_psql_gml_to_sql(o, elemt, srid_root);
+              if (gml) {
+                buffer_add_str(values, "'");
+                buffer_copy(values, gml);
+                buffer_add_str(values, "'");
+                buffer_free(gml);
+              } else {
+                buffer_free(sql);
+                buffer_free(values);
+                buffer_free(column);
+                buffer_free(id);
+                buffer_free(layer_name);
+
+                result = buffer_from_str("Error invalid Geometry");
+                return result;
+              }
             }
           }
+          else
+            buffer_add_str(values, "NULL");
 
         } else values = wfs_retrieve_value(o, wr, values, xmldoc, node);
 

From ddfc6776a235c0655285b47481e1cefef1057044 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Fri, 11 Mar 2016 11:11:23 +0100
Subject: [PATCH 09/30] Fix ows_geobbox_copy() to use correct sizeof()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The function should do a sizeof() of the structure, and not a pointer
to the structure. Raised by GCC 4.8

src/ows/ows_geobbox.c: In function ‘ows_geobbox_copy’:
src/ows/ows_geobbox.c:62:29: warning: argument to ‘sizeof’ in ‘memcpy’ call is the same pointer type ‘struct ows_geobbox *’ as the destination; expected ‘ows_geobbox’ or an explicit length [-Wsizeof-pointer-memaccess]
   return memcpy(c, g, sizeof(g));
---
 src/ows/ows_geobbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ows/ows_geobbox.c b/src/ows/ows_geobbox.c
index ea3760a..fe4e7b5 100644
--- a/src/ows/ows_geobbox.c
+++ b/src/ows/ows_geobbox.c
@@ -58,8 +58,8 @@ ows_geobbox *ows_geobbox_copy(ows_geobbox *g)
   ows_geobbox *c;
 
   assert(g);
-  c = malloc(sizeof(g));
-  return memcpy(c, g, sizeof(g));
+  c = malloc(sizeof(*g));
+  return memcpy(c, g, sizeof(*g));
 }
 
 

From 6fea4fea55569c45bdb64770ac5a6e30c7911807 Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu@ip-172-31-38-220.eu-west-1.compute.internal>
Date: Tue, 15 Mar 2016 03:19:37 +0000
Subject: [PATCH 10/30] fix escape JSON special char

---
 src/struct/buffer.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/struct/buffer.c b/src/struct/buffer.c
index 2436834..daeeac9 100644
--- a/src/struct/buffer.c
+++ b/src/struct/buffer.c
@@ -538,9 +538,6 @@ buffer *buffer_encode_xml_entities_str(const char * str)
 /*
  * Modify string to replace encoded characters by their true value
  * for JSON output
- *
- * The replacements performed are:
- *  " -> \"
  */
 buffer *buffer_encode_json_str(const char * str)
 {
@@ -555,6 +552,22 @@ buffer *buffer_encode_json_str(const char * str)
         buffer_add_str(buf, "\\\"");
         break;
 
+      case '\n':
+        buffer_add_str(buf, "\\\\n");
+        break;
+
+      case '\r':
+        buffer_add_str(buf, "\\\\r");
+        break;
+
+      case '\t':
+        buffer_add_str(buf, "\\\\t");
+        break;
+
+      case '\\':
+        buffer_add_str(buf, "\\\\");
+        break;
+
       default:
         buffer_add(buf, *str);
     }

From a7b9d46bb8ed41383cbbc0f902148ee87b243668 Mon Sep 17 00:00:00 2001
From: root <root@ip-172-31-11-115.eu-west-1.compute.internal>
Date: Tue, 15 Mar 2016 04:34:34 +0000
Subject: [PATCH 11/30] xml entities filter some UTF8 accent text

---
 src/struct/buffer.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/struct/buffer.c b/src/struct/buffer.c
index 2f556bb..8066ac6 100644
--- a/src/struct/buffer.c
+++ b/src/struct/buffer.c
@@ -507,8 +507,6 @@ buffer *buffer_encode_xml_entities_str(const char * str)
 
   for( /* empty */ ; *str ; str++) {
 
-    if ((int) *str < 32 && (*str != '\n' && *str != '\r' && *str != '	')) break;
-
     switch(*str) {
       case '&':
         buffer_add_str(buf, "&amp;");

From f1bdd0af5218a5d0ab70e825983598de01aa76c4 Mon Sep 17 00:00:00 2001
From: Olivier Courtin <olivier.courtin@oslandia.com>
Date: Mon, 21 Mar 2016 19:02:40 +0100
Subject: [PATCH 12/30] fix unable to use separator chars as underscore in
 typename

---
 schema/wfs/1.1.0/wfs.xsd | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/schema/wfs/1.1.0/wfs.xsd b/schema/wfs/1.1.0/wfs.xsd
index 4007bed..a861d2e 100644
--- a/schema/wfs/1.1.0/wfs.xsd
+++ b/schema/wfs/1.1.0/wfs.xsd
@@ -818,7 +818,7 @@
    </xsd:simpleType>
    <xsd:simpleType name="TypeNameListType">
       <xsd:restriction base="wfs:Base_TypeNameListType">
-         <xsd:pattern value="((\w:)?\w(=\w)?){1,}">
+         <xsd:pattern value="((\w:)?[a-zA-Z._-](=\w)?){1,}">
             <xsd:annotation>
                <xsd:documentation>
                   Example typeName attribute value might be:

From 5af0e48bd0e8be5c685c4b7f23b0ddc88bb2d245 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:53:30 +0100
Subject: [PATCH 13/30] Demo / testsuite install script: make them work with
 recent PostGIS / PostgreSQL

---
 demo/install.sh.in                 | 20 +++++++++++++++++---
 test/wfs_100/install_wfs_100.sh.in | 28 ++++++++++++++++++++++++++--
 test/wfs_110/install_wfs_110.sh.in | 28 ++++++++++++++++++++++++++--
 3 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/demo/install.sh.in b/demo/install.sh.in
index d27ffa0..e1928f8 100755
--- a/demo/install.sh.in
+++ b/demo/install.sh.in
@@ -3,13 +3,25 @@
 # don't launch directly this script
 # use 'make install-demo' to do so
 
+set -e
+
 PGBIN=@POSTGIS_BIN@
 PGSHARE=@POSTGIS_SHARE@/contrib/postgis-1.5
 PGUSER=postgres
 SHP2PGSQL=@SHP2PGSQL@
 DB=tinyows_demo
 
-if [ -d @POSTGIS_SHARE@/contrib/postgis-2.1 ]; then
+if [ -d @POSTGIS_SHARE@/contrib/postgis-3.0 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-3.0
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.5 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.5
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.4 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.4
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.3 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.3
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.2 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.2
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.1 ]; then
 	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.1
 elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.0 ]; then
 	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.0
@@ -20,9 +32,11 @@ else
 fi
 
 echo "Create Spatial Database: $DB"
-su $PGUSER -c "$PGBIN/dropdb $DB > /dev/null 2> /dev/null"
+su $PGUSER -c "$PGBIN/dropdb $DB > /dev/null 2> /dev/null || /bin/true"
 su $PGUSER -c "$PGBIN/createdb $DB"
-su $PGUSER -c "$PGBIN/createlang plpgsql $DB"
+if test -f "$PGBIN/createlang"; then
+    su $PGUSER -c "$PGBIN/createlang plpgsql $DB"
+fi
 su $PGUSER -c "$PGBIN/psql $DB < $PGSHARE/postgis.sql"
 su $PGUSER -c "$PGBIN/psql $DB < $PGSHARE/spatial_ref_sys.sql"
 
diff --git a/test/wfs_100/install_wfs_100.sh.in b/test/wfs_100/install_wfs_100.sh.in
index 76728f6..840b742 100755
--- a/test/wfs_100/install_wfs_100.sh.in
+++ b/test/wfs_100/install_wfs_100.sh.in
@@ -3,15 +3,39 @@
 # don't launch directly this script
 # use 'make install-test100' to do so
 
+set -e
+
 PGBIN=@POSTGIS_BIN@
 PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.0
 PGUSER=postgres
 DB=tinyows_test
 
+if [ -d @POSTGIS_SHARE@/contrib/postgis-3.0 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-3.0
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.5 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.5
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.4 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.4
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.3 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.3
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.2 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.2
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.1 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.1
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.0 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.0
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-1.5 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-1.5
+else
+	echo "Unable to find PostGIS dir in @POSTGIS_SHARE@/contrib/" && exit 1
+fi
+
 echo "Create Spatial Database: $DB"
-su $PGUSER -c "$PGBIN/dropdb $DB > /dev/null"
+su $PGUSER -c "$PGBIN/dropdb $DB > /dev/null 2> /dev/null || /bin/true"
 su $PGUSER -c "$PGBIN/createdb $DB"
-su $PGUSER -c "$PGBIN/createlang plpgsql $DB"
+if test -f "$PGBIN/createlang"; then
+    su $PGUSER -c "$PGBIN/createlang plpgsql $DB"
+fi
 su $PGUSER -c "$PGBIN/psql $DB < $PGSHARE/postgis.sql"
 su $PGUSER -c "$PGBIN/psql $DB < $PGSHARE/spatial_ref_sys.sql"
 su $PGUSER -c "$PGBIN/psql $DB < test/wfs_100/ogc_wfs_sf0.sql"
diff --git a/test/wfs_110/install_wfs_110.sh.in b/test/wfs_110/install_wfs_110.sh.in
index ba9f4b4..aaddd41 100755
--- a/test/wfs_110/install_wfs_110.sh.in
+++ b/test/wfs_110/install_wfs_110.sh.in
@@ -3,15 +3,39 @@
 # don't launch directly this script
 # use 'make install-test110' to do so
 
+set -e
+
 PGBIN=@POSTGIS_BIN@
 PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.0
 PGUSER=postgres
 DB=tinyows_test
 
+if [ -d @POSTGIS_SHARE@/contrib/postgis-3.0 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-3.0
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.5 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.5
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.4 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.4
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.3 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.3
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.2 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.2
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.1 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.1
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-2.0 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-2.0
+elif [ -d @POSTGIS_SHARE@/contrib/postgis-1.5 ]; then
+	PGSHARE=@POSTGIS_SHARE@/contrib/postgis-1.5
+else
+	echo "Unable to find PostGIS dir in @POSTGIS_SHARE@/contrib/" && exit 1
+fi
+
 echo "Create Spatial Database: $DB"
-su $PGUSER -c "$PGBIN/dropdb $DB > /dev/null"
+su $PGUSER -c "$PGBIN/dropdb $DB > /dev/null 2> /dev/null || /bin/true"
 su $PGUSER -c "$PGBIN/createdb $DB"
-su $PGUSER -c "$PGBIN/createlang plpgsql $DB"
+if test -f "$PGBIN/createlang"; then
+    su $PGUSER -c "$PGBIN/createlang plpgsql $DB"
+fi
 su $PGUSER -c "$PGBIN/psql $DB < $PGSHARE/postgis.sql"
 su $PGUSER -c "$PGBIN/psql $DB < $PGSHARE/spatial_ref_sys.sql"
 su $PGUSER -c "$PGBIN/psql $DB < test/wfs_110/ogc_wfs_sf0.sql"

From c726adbd36477c47b06e1a60eb1126144c5cd54e Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:54:04 +0100
Subject: [PATCH 14/30] test/unit_test: make it work with XML POST requests

---
 test/unit_test | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/test/unit_test b/test/unit_test
index 8226056..15fd0e5 100755
--- a/test/unit_test
+++ b/test/unit_test
@@ -48,7 +48,12 @@ sed "/LIST$/d" $list_tmp > $sed_tmp && mv $sed_tmp $list_tmp
 for unit_id in `cat $list_tmp`; do
 
 option=`cat $unit_id`
-export QUERY_STRING=$option
+export QUERY_STRING="$option"
+
+echo "---"
+echo "Run: $unit_id"
+echo "Query: $QUERY_STRING"
+
 
 # Valgrind resume mode
 if [ $mode -eq 1 ]; then

From 87c844afc746baaa12029327be23167ade55a7cf Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:55:08 +0100
Subject: [PATCH 15/30] ows_psql_generate_id(): fix compiler warning (output
 buffer cannot be used as input)

---
 src/ows/ows_psql.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/ows/ows_psql.c b/src/ows/ows_psql.c
index 4fe0e35..ebc6dae 100644
--- a/src/ows/ows_psql.c
+++ b/src/ows/ows_psql.c
@@ -630,8 +630,11 @@ buffer *ows_psql_generate_id(ows * o, buffer * layer_name)
 
   fp = fopen("/dev/urandom","r");
   if (fp) {
-    for (i=0 ; i<seed_len ; i++)
-      sprintf(seed,"%s%03d", seed, fgetc(fp));
+    for (i=0 ; i<seed_len ; i++) {
+      char szBuf[4];
+      sprintf(szBuf, "%03d", fgetc(fp));
+      strcat(seed, szBuf);
+    }
     fclose(fp);
     buffer_add_str(id, seed);
     free(seed);

From 42fed9603d0f5b09a80561b04252fcb9725d6500 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:55:28 +0100
Subject: [PATCH 16/30] cgi_getback_query(): fix compiler warning about unused
 variable

---
 src/struct/cgi_request.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/struct/cgi_request.c b/src/struct/cgi_request.c
index 613e37f..64f766b 100644
--- a/src/struct/cgi_request.c
+++ b/src/struct/cgi_request.c
@@ -81,6 +81,7 @@ char *cgi_getback_query(ows * o)
       return NULL;
     }
     s = fread(query, query_size, 1, stdin);
+    (void)s;
     if (ferror(stdin)) {
       ows_error(o, OWS_ERROR_REQUEST_HTTP, "Error on QUERY input", "request");
       return NULL;

From d0a20b80fc53f06fae98ff3679b0bb28123907fc Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:55:50 +0100
Subject: [PATCH 17/30] wfs_insert_xml(): fix compiler warning about unused
 variable

---
 src/wfs/wfs_transaction.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/wfs/wfs_transaction.c b/src/wfs/wfs_transaction.c
index adaa73c..a777e4f 100644
--- a/src/wfs/wfs_transaction.c
+++ b/src/wfs/wfs_transaction.c
@@ -447,6 +447,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
     }
 
     layer_ns_prefix = ows_layer_ns_prefix(o->layers, layer_name);
+    (void)layer_ns_prefix; // FIXME : unused variable ?
 
     /* ReplaceDuplicate look if an ID is already used
      *

From f4345f886a5da620a7fe9185c64f8b92c403994c Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:57:09 +0100
Subject: [PATCH 18/30] GetFeature request output: avoid repeated prefix of the
 typename in the schemaLocation attribute

---
 src/wfs/wfs_get_feature.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/wfs/wfs_get_feature.c b/src/wfs/wfs_get_feature.c
index 2cbc07e..5d4078b 100644
--- a/src/wfs/wfs_get_feature.c
+++ b/src/wfs/wfs_get_feature.c
@@ -237,7 +237,6 @@ static void wfs_gml_display_namespaces(ows * o, wfs_request * wr)
   array *namespaces;
   array_node *an;
   list_node *ln;
-  buffer * ns_prefix;
 
   assert(o);
   assert(wr);
@@ -276,8 +275,7 @@ static void wfs_gml_display_namespaces(ows * o, wfs_request * wr)
   if (wr->typename) {
     fprintf(o->output, "&amp;Typename=");
     for (ln = wr->typename->first ; ln ; ln = ln->next) {
-      ns_prefix = ows_layer_ns_prefix(o->layers, ln->value);
-      fprintf(o->output, "%s:%s", ns_prefix->buf, ln->value->buf);
+      fprintf(o->output, "%s", ln->value->buf);
       if (ln->next) fprintf(o->output, ",");
     }
   }

From 2d8fdfb081a4f6208de24f5d369aa0c3d4ef7abd Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:57:51 +0100
Subject: [PATCH 19/30] Fix crashes in DescribeFetureType when running the CITE
 1.0 test suite

---
 src/wfs/wfs_describe.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/wfs/wfs_describe.c b/src/wfs/wfs_describe.c
index a04593d..c6aee74 100644
--- a/src/wfs/wfs_describe.c
+++ b/src/wfs/wfs_describe.c
@@ -199,7 +199,16 @@ void wfs_describe_feature_type(ows * o, wfs_request * wr)
     fprintf(o->output, " elementFormDefault='qualified'> ");
 
     for (elemt = ns_prefix->first ; elemt ; elemt = elemt->next) {
+      if (buffer_cmp(elemt->value, "gml")) {
+          continue;
+      }
       namespace = ows_layer_ns_prefix_to_ns_uri(o->layers, elemt->value);
+      if( namespace == NULL ) {
+          fprintf(stderr, "Cannot find namespace URI for prefix %s\n",
+                  elemt->value->buf);
+          continue;
+      }
+
       fprintf(o->output, "<xs:import namespace='%s' ", namespace->buf);
       fprintf(o->output, "schemaLocation='%s?service=WFS&amp;version=",
               o->online_resource->buf);
@@ -270,7 +279,7 @@ void wfs_describe_feature_type(ows * o, wfs_request * wr)
  */
 buffer * wfs_generate_schema(ows * o, ows_version * version)
 {
-  list *ns_prefix, *typename, *layers;
+  list *ns_prefix, *typename, *layers, *layers_name_prefix;
   buffer *namespace, *schema;
   list_node *elemt, *t;
   int wfs_version;
@@ -281,6 +290,11 @@ buffer * wfs_generate_schema(ows * o, ows_version * version)
   wfs_version = ows_version_get(version);
   layers = ows_layer_list_having_storage(o->layers);
 
+  layers_name_prefix = list_init();
+  for (elemt = layers->first; elemt ; elemt = elemt->next) {
+    list_add_by_copy(layers_name_prefix, ows_layer_uri_to_prefix(o->layers, elemt->value));
+  }
+
   buffer_add_str(schema, "<?xml version='1.0' encoding='utf-8'?>\n");
 
   ns_prefix = ows_layer_list_ns_prefix(o->layers, layers);
@@ -296,7 +310,15 @@ buffer * wfs_generate_schema(ows * o, ows_version * version)
   buffer_add_str(schema, "'/>\n");
 
   for (elemt = ns_prefix->first ; elemt ; elemt = elemt->next) {
+    if (buffer_cmp(elemt->value, "gml")) {
+        continue;
+    }
     namespace = ows_layer_ns_prefix_to_ns_uri(o->layers, elemt->value);
+    if( namespace == NULL ) {
+        fprintf(stderr, "Cannot find namespace URI for prefix %s\n",
+                elemt->value->buf);
+        continue;
+    }
     buffer_add_str(schema, "<xs:import namespace='");
     buffer_copy(schema, namespace);
     buffer_add_str(schema, "' schemaLocation='");
@@ -307,7 +329,7 @@ buffer * wfs_generate_schema(ows * o, ows_version * version)
     if (elemt->next || elemt != ns_prefix->first) {
       buffer_add_str(schema, "&amp;Typename=");
 
-      typename = ows_layer_list_by_ns_prefix(o->layers, layers, elemt->value);
+      typename = ows_layer_list_by_ns_prefix(o->layers, layers_name_prefix, elemt->value);
       for (t = typename->first ; t ; t = t->next) {
         buffer_copy(schema, t->value);
         if (t->next) buffer_add(schema, ',');
@@ -324,6 +346,7 @@ buffer * wfs_generate_schema(ows * o, ows_version * version)
   buffer_add_str(schema, "</xs:schema>");
   list_free(ns_prefix);
   list_free(layers);
+  list_free(layers_name_prefix);
 
   return schema;
 }

From 700caa138ca7597215e532f48362b1185b1e52b3 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:58:53 +0100
Subject: [PATCH 20/30] fe_distance_functions(): fix crashes / incorrect
 behaviour when running the CITE 1.0 test suite on distance functions

---
 src/fe/fe_spatial_ops.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/fe/fe_spatial_ops.c b/src/fe/fe_spatial_ops.c
index 59ef8a8..e8b1ab9 100644
--- a/src/fe/fe_spatial_ops.c
+++ b/src/fe/fe_spatial_ops.c
@@ -330,7 +330,7 @@ static buffer *fe_spatial_functions(ows * o, buffer * typename, filter_encoding
 static buffer *fe_distance_functions(ows * o, buffer * typename, filter_encoding * fe, xmlNodePtr n)
 {
   xmlChar *content, *units;
-  buffer *tmp, *op, *sql;
+  buffer *tmp, *op, *sql, *layer_name;
   float km;
 
   assert(o);
@@ -341,11 +341,13 @@ static buffer *fe_distance_functions(ows * o, buffer * typename, filter_encoding
   tmp = NULL;
   op = buffer_init();
 
+  layer_name = ows_layer_prefix_to_uri(o->layers, typename);
+
   if (!strcmp((char *) n->name, "Beyond"))  buffer_add_str(op, " > ");
   if (!strcmp((char *) n->name, "DWithin")) buffer_add_str(op, " < ");
 
   buffer_add_str(fe->sql, "ST_Distance(");
-  if (!ows_srs_meter_units(o, typename))
+  if (!ows_srs_meter_units(o, layer_name))
     buffer_add_str(fe->sql, "ST_Transform(");
 
   n = n->children;
@@ -355,7 +357,7 @@ static buffer *fe_distance_functions(ows * o, buffer * typename, filter_encoding
   fe->sql = fe_property_name(o, typename, fe, fe->sql, n, true, true);
   buffer_add(fe->sql, '"');
 
-  if (!ows_srs_meter_units(o, typename))
+  if (!ows_srs_meter_units(o, layer_name))
     buffer_add_str(fe->sql, ", 4326)::geography");
 
   buffer_add_str(fe->sql, "),('");
@@ -364,7 +366,7 @@ static buffer *fe_distance_functions(ows * o, buffer * typename, filter_encoding
 
   while (n->type != XML_ELEMENT_NODE) n = n->next;
 
-  if (!ows_srs_meter_units(o, typename))
+  if (!ows_srs_meter_units(o, layer_name))
     buffer_add_str(fe->sql, "ST_Transform(");
 
   /* display the geometry */
@@ -374,7 +376,7 @@ static buffer *fe_distance_functions(ows * o, buffer * typename, filter_encoding
     buffer_free(sql);
   } else fe->error_code = FE_ERROR_GEOMETRY;
 
-  if (!ows_srs_meter_units(o, typename))
+  if (!ows_srs_meter_units(o, layer_name))
     buffer_add_str(fe->sql, ", 4326)::geography");
 
   buffer_add_str(fe->sql, "'))");

From 30659c11467fe9d2719626b46c361d3337c48ec7 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 23:03:07 +0100
Subject: [PATCH 21/30] Add autogen.sh

---
 autogen.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100755 autogen.sh

diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..e929a8e
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# Autotools boostrapping script
+#
+giveup()
+{
+        echo
+        echo "  Something went wrong, giving up!"
+        echo
+        exit 1
+}
+
+echo "Running autoconf"
+autoconf || giveup
+
+echo "======================================"
+echo "Now you are ready to run './configure'"
+echo "======================================"

From 533f240b577bf8e7600e3c424606501962fe1045 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 23:03:17 +0100
Subject: [PATCH 22/30] Add .gitignore

---
 .gitignore | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8eed704
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+Makefile
+configure
+demo/install.sh
+demo/tinyows.xml
+src/ows_define.h
+test/wfs_100/config_wfs_100.xml
+test/wfs_100/install_wfs_100.sh
+test/wfs_110/config_wfs_110.xml
+test/wfs_110/install_wfs_110.sh
+tinyows

From aea00a0f584c6ccd91d52833c7a938408330b044 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 22:59:18 +0100
Subject: [PATCH 23/30] Add github action to build on Linux

---
 .github/workflows/linux.sh  | 33 +++++++++++++++++++++++++++++++++
 .github/workflows/linux.yml | 15 +++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100755 .github/workflows/linux.sh
 create mode 100644 .github/workflows/linux.yml

diff --git a/.github/workflows/linux.sh b/.github/workflows/linux.sh
new file mode 100755
index 0000000..cc4b610
--- /dev/null
+++ b/.github/workflows/linux.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+set -e
+
+apt-get update
+
+DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
+    gcc libxml2-dev libpq-dev libfcgi-dev \
+    autoconf make flex libfl-dev \
+    postgresql-12 postgresql-client postgis postgresql-12-postgis-3 postgresql-12-postgis-3-scripts \
+    wget ca-certificates patch valgrind
+
+cd "${WORK_DIR}"
+./autogen.sh
+CFLAGS="-Werror" ./configure
+make
+make install
+
+cp /etc/postgresql/12/main/pg_hba.conf /etc/postgresql/12/main/pg_hba.conf.bak
+echo "local all postgres trust" |  cat - /etc/postgresql/12/main/pg_hba.conf.bak > /etc/postgresql/12/main/pg_hba.conf
+echo "host all all 127.0.0.1/32 trust" |  cat - /etc/postgresql/12/main/pg_hba.conf.bak > /etc/postgresql/12/main/pg_hba.conf
+/etc/init.d/postgresql start
+
+make install-demo
+
+# wget https://github.com/MapServer/tinyows/commit/633ca487113d032e261a4a5c8b5f3b7850580f4f.patch
+# patch -p1 -R < 633ca487113d032e261a4a5c8b5f3b7850580f4f.patch
+
+# rm -f /etc/tinyows.xml
+# make install-test100
+
+# rm -f /etc/tinyows.xml
+# make install-test110
\ No newline at end of file
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
new file mode 100644
index 0000000..bf7850a
--- /dev/null
+++ b/.github/workflows/linux.yml
@@ -0,0 +1,15 @@
+name: Linux build
+
+on: [push, pull_request]
+
+jobs:
+
+  linux_build:
+    runs-on: ubuntu-latest
+    if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Build
+        run: docker run --rm -e WORK_DIR=$PWD -v $PWD:$PWD ubuntu:20.04 $PWD/.github/workflows/linux.sh

From 22c6dfefc8d40700fbc5222d439bdc3cfdabd73e Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 25 Nov 2020 23:53:03 +0100
Subject: [PATCH 24/30] Document a few fields of Ows_layer structure

---
 src/ows_struct.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ows_struct.h b/src/ows_struct.h
index 322bc1a..025c9a9 100644
--- a/src/ows_struct.h
+++ b/src/ows_struct.h
@@ -166,9 +166,9 @@ enum ows_error_code {
 typedef struct Ows_layer {
   struct Ows_layer * parent;
   int depth;
-  buffer * name;
-  buffer * name_prefix;
-  buffer * name_no_uri;
+  buffer * name;            /* Nominally concatenation of ns_uri:name_no_uri, e.g. "http://www.tinyows.org/:world" , or name_no_uri if no ns_uri */
+  buffer * name_prefix;     /* Nominally concatenation of ns_prefix:name_no_uri, e.g. "tows:world" , or name_no_uri if no ns_prefix */
+  buffer * name_no_uri;     /* the name as in the "name" attribute in the config, e.g "world" */
   buffer * title;
   bool retrievable;
   bool writable;
@@ -181,8 +181,8 @@ typedef struct Ows_layer {
   buffer * pkey;
   buffer * pkey_sequence;
   list * gml_ns;
-  buffer * ns_prefix;
-  buffer * ns_uri;
+  buffer * ns_prefix;       /* value of the "ns_prefix" attribute in the config, e.g. "tows" */
+  buffer * ns_uri;          /* value of the "ns_uri" attribute in the config, e.g. "http://www.tinyows.org/" */
   buffer * encoding;
   ows_layer_storage * storage;
 } ows_layer;

From 62fcd67d8d538f2e19f4180d83e4119b3d982f78 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Thu, 26 Nov 2020 00:24:52 +0100
Subject: [PATCH 25/30] Add basic 'make check' target

---
 .github/workflows/linux.sh                    |   1 +
 Makefile.in                                   |   3 +
 demo/check.sh                                 |  24 ++
 demo/tests/expected/wfs10_describe.txt        |  40 +++
 demo/tests/expected/wfs10_getcaps.txt         | 152 +++++++++++
 .../wfs10_getfeatures_france_onefeature.txt   |  36 +++
 .../wfs10_getfeatures_world_onefeature.txt    |  28 ++
 demo/tests/expected/wfs11_describe.txt        |  40 +++
 demo/tests/expected/wfs11_getcaps.txt         | 257 ++++++++++++++++++
 .../wfs11_getfeatures_france_onefeature.txt   |  35 +++
 .../wfs11_getfeatures_world_onefeature.txt    |  27 ++
 demo/tests/input/wfs10_describe.txt           |   1 +
 demo/tests/input/wfs10_getcaps.txt            |   1 +
 .../wfs10_getfeatures_france_onefeature.txt   |   1 +
 .../wfs10_getfeatures_world_onefeature.txt    |   1 +
 demo/tests/input/wfs11_describe.txt           |   1 +
 demo/tests/input/wfs11_getcaps.txt            |   1 +
 .../wfs11_getfeatures_france_onefeature.txt   |   1 +
 .../wfs11_getfeatures_world_onefeature.txt    |   1 +
 19 files changed, 651 insertions(+)
 create mode 100755 demo/check.sh
 create mode 100644 demo/tests/expected/wfs10_describe.txt
 create mode 100644 demo/tests/expected/wfs10_getcaps.txt
 create mode 100644 demo/tests/expected/wfs10_getfeatures_france_onefeature.txt
 create mode 100644 demo/tests/expected/wfs10_getfeatures_world_onefeature.txt
 create mode 100644 demo/tests/expected/wfs11_describe.txt
 create mode 100644 demo/tests/expected/wfs11_getcaps.txt
 create mode 100644 demo/tests/expected/wfs11_getfeatures_france_onefeature.txt
 create mode 100644 demo/tests/expected/wfs11_getfeatures_world_onefeature.txt
 create mode 100644 demo/tests/input/wfs10_describe.txt
 create mode 100644 demo/tests/input/wfs10_getcaps.txt
 create mode 100644 demo/tests/input/wfs10_getfeatures_france_onefeature.txt
 create mode 100644 demo/tests/input/wfs10_getfeatures_world_onefeature.txt
 create mode 100644 demo/tests/input/wfs11_describe.txt
 create mode 100644 demo/tests/input/wfs11_getcaps.txt
 create mode 100644 demo/tests/input/wfs11_getfeatures_france_onefeature.txt
 create mode 100644 demo/tests/input/wfs11_getfeatures_world_onefeature.txt

diff --git a/.github/workflows/linux.sh b/.github/workflows/linux.sh
index cc4b610..fc1e38c 100755
--- a/.github/workflows/linux.sh
+++ b/.github/workflows/linux.sh
@@ -22,6 +22,7 @@ echo "host all all 127.0.0.1/32 trust" |  cat - /etc/postgresql/12/main/pg_hba.c
 /etc/init.d/postgresql start
 
 make install-demo
+make check
 
 # wget https://github.com/MapServer/tinyows/commit/633ca487113d032e261a4a5c8b5f3b7850580f4f.patch
 # patch -p1 -R < 633ca487113d032e261a4a5c8b5f3b7850580f4f.patch
diff --git a/Makefile.in b/Makefile.in
index 1d17052..4dd219d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -58,6 +58,9 @@ install-demo:
 	@demo/install.sh
 	cp -i demo/tinyows.xml /etc/tinyows.xml
 
+check:
+	@demo/check.sh
+
 install-test100:
 	@chmod +x test/wfs_100/install_wfs_100.sh
 	@test/wfs_100/install_wfs_100.sh
diff --git a/demo/check.sh b/demo/check.sh
new file mode 100755
index 0000000..be80d00
--- /dev/null
+++ b/demo/check.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -eu
+
+RET=0
+
+for i in demo/tests/input/*; do
+    echo "Running $i"
+    QUERY_STRING="$(cat $i)" ./tinyows > /tmp/output.txt
+    if ! diff -u /tmp/output.txt demo/tests/expected/$(basename $i); then
+        mkdir -p demo/tests/got
+        mv /tmp/output.txt demo/tests/got/$(basename $i)
+        echo "Result got put in demo/tests/got/$(basename $i)"
+        RET=1
+    fi
+done
+
+if test "$RET" -eq "0"; then
+    echo "Tests OK !"
+else
+    echo "Tests failed !"
+fi
+
+exit $RET
\ No newline at end of file
diff --git a/demo/tests/expected/wfs10_describe.txt b/demo/tests/expected/wfs10_describe.txt
new file mode 100644
index 0000000..146b9f8
--- /dev/null
+++ b/demo/tests/expected/wfs10_describe.txt
@@ -0,0 +1,40 @@
+Content-Type: text/xml; subtype=gml/2.1.2;
+
+<?xml version='1.0' encoding='UTF-8'?>
+<xs:schema targetNamespace='http://www.tinyows.org/' xmlns:tows='http://www.tinyows.org/' xmlns:ogc='http://www.opengis.net/ogc' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns='http://www.w3.org/2001/XMLSchema' xmlns:gml='http://www.opengis.net/gml' elementFormDefault='qualified' version='1.0'>
+<xs:import namespace='http://www.opengis.net/gml' schemaLocation='http://schemas.opengis.net/gml/2.1.2/feature.xsd'/>
+<xs:element name='world' type='tows:worldType' substitutionGroup='gml:_Feature' />
+<xs:complexType name='worldType'>
+ <xs:complexContent>
+  <xs:extension base='gml:AbstractFeatureType'>
+   <xs:sequence>
+    <xs:element name ='name' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='40'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='gmi_cntry' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='3'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='region' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='25'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='geom' type='gml:MultiPolygonPropertyType' nillable='true' minOccurs='0' maxOccurs='1'/>
+   </xs:sequence>
+  </xs:extension>
+ </xs:complexContent>
+</xs:complexType>
+<xs:element name='france' type='tows:franceType' substitutionGroup='gml:_Feature' />
+<xs:complexType name='franceType'>
+ <xs:complexContent>
+  <xs:extension base='gml:AbstractFeatureType'>
+   <xs:sequence>
+    <xs:element name ='id_geofla' type='long' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='code_chf_l' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='3'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='nom_chf_l' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='50'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='x_chf_lieu' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='y_chf_lieu' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='x_centroid' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='y_centroid' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='nom_dept' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='30'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='code_reg' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='2'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='nom_region' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='30'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='code_dept' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='3'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='geom' type='gml:MultiPolygonPropertyType' nillable='true' minOccurs='0' maxOccurs='1'/>
+   </xs:sequence>
+  </xs:extension>
+ </xs:complexContent>
+</xs:complexType>
+</xs:schema>
\ No newline at end of file
diff --git a/demo/tests/expected/wfs10_getcaps.txt b/demo/tests/expected/wfs10_getcaps.txt
new file mode 100644
index 0000000..f22b30f
--- /dev/null
+++ b/demo/tests/expected/wfs10_getcaps.txt
@@ -0,0 +1,152 @@
+Content-Type: application/xml
+
+<?xml version='1.0' encoding='UTF-8'?>
+<WFS_Capabilities
+version='1.0.0' updateSequence='0'
+ xmlns='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xsi:schemaLocation='http://www.opengis.net/wfs
+ http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd' >
+ <Service>
+  <Name>TinyOWS Server</Name>
+  <Title>TinyOWS Server - Demo Service</Title>
+  <OnlineResource>http://127.0.0.1/cgi-bin/tinyows</OnlineResource>
+ </Service>
+ <Capability>
+  <Request>
+   <GetCapabilities>
+    <DCPType>
+     <HTTP>
+      <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </HTTP>
+    </DCPType>
+    <DCPType>
+     <HTTP>
+      <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+     </HTTP>
+    </DCPType>
+   </GetCapabilities>
+   <DescribeFeatureType>
+     <SchemaDescriptionLanguage>
+        <XMLSCHEMA/>
+     </SchemaDescriptionLanguage>
+    <DCPType>
+     <HTTP>
+      <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </HTTP>
+    </DCPType>
+    <DCPType>
+     <HTTP>
+      <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+     </HTTP>
+    </DCPType>
+   </DescribeFeatureType>
+   <GetFeature>
+<ResultFormat>
+<GML2/>
+</ResultFormat>
+    <DCPType>
+     <HTTP>
+      <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </HTTP>
+    </DCPType>
+    <DCPType>
+     <HTTP>
+      <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+     </HTTP>
+    </DCPType>
+   </GetFeature>
+   <Transaction>
+    <DCPType>
+     <HTTP>
+      <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </HTTP>
+    </DCPType>
+    <DCPType>
+     <HTTP>
+      <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+     </HTTP>
+    </DCPType>
+   </Transaction>
+  </Request>
+ </Capability>
+ <FeatureTypeList>
+  <Operations>
+   <Query/>
+   <Insert/>
+   <Update/>
+   <Delete/>
+  </Operations>
+<FeatureType xmlns:tows="http://www.tinyows.org/">
+  <Name>tows:world</Name>
+  <Title>World Administrative Boundaries</Title>
+ <SRS>EPSG:4326</SRS>
+  <LatLongBoundingBox minx='-180.000183' miny='-90.000000' maxx='180.000000' maxy='83.623032' />
+</FeatureType>
+<FeatureType xmlns:tows="http://www.tinyows.org/">
+  <Name>tows:france</Name>
+  <Title>French Administrative Sub Boundaries (IGN - GeoFLA Departements)</Title>
+ <SRS>EPSG:27582</SRS>
+  <LatLongBoundingBox minx='-6.091001' miny='41.347435' maxx='10.812651' maxy='50.803540' />
+</FeatureType>
+ </FeatureTypeList>
+<ogc:Filter_Capabilities>
+ <ogc:Spatial_Capabilities>
+  <ogc:Spatial_Operators>
+   <ogc:Disjoint/>
+   <ogc:Equals/>
+   <ogc:DWithin/>
+   <ogc:Beyond/>
+   <ogc:Intersect/>
+   <ogc:Touches/>
+   <ogc:Crosses/>
+   <ogc:Within/>
+   <ogc:Contains/>
+   <ogc:Overlaps/>
+   <ogc:BBOX/>
+  </ogc:Spatial_Operators>
+ </ogc:Spatial_Capabilities>
+ <ogc:Scalar_Capabilities>
+  <ogc:Logical_Operators/>
+  <ogc:Comparison_Operators>
+   <ogc:Simple_Comparisons/>
+   <ogc:Between/>
+   <ogc:Like/>
+   <ogc:NullCheck/>
+  </ogc:Comparison_Operators>
+  <ogc:Arithmetic_Operators>
+   <ogc:Simple_Arithmetic/>
+   <ogc:Functions>
+    <ogc:Function_Names>
+     <ogc:Function_Name nArgs='1'>abs</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>acos</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>asin</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>atan</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>avg</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>cbrt</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>ceil</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>ceiling</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>cos</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>cot</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>count</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>degrees</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>exp</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>floor</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>length</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>ln</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>log</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>min</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>max</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>radians</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>round</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>sin</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>sqrt</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>tan</ogc:Function_Name>
+     <ogc:Function_Name nArgs='1'>trunc</ogc:Function_Name>
+    </ogc:Function_Names>
+   </ogc:Functions>
+  </ogc:Arithmetic_Operators>
+ </ogc:Scalar_Capabilities>
+</ogc:Filter_Capabilities>
+</WFS_Capabilities>
diff --git a/demo/tests/expected/wfs10_getfeatures_france_onefeature.txt b/demo/tests/expected/wfs10_getfeatures_france_onefeature.txt
new file mode 100644
index 0000000..fc7a979
--- /dev/null
+++ b/demo/tests/expected/wfs10_getfeatures_france_onefeature.txt
@@ -0,0 +1,36 @@
+Content-Type: text/xml; subtype=gml/2.1.2
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.0.0&amp;request=DescribeFeatureType&amp;Typename=tows:france   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/2.1.2/feature.xsd'
+>
+<gml:boundedBy><gml:null>missing</gml:null></gml:boundedBy>
+  <gml:featureMember>
+   <tows:france fid="france.1">
+   <tows:id_geofla>49</tows:id_geofla>
+   <tows:code_chf_l>053</tows:code_chf_l>
+   <tows:nom_chf_l>BOURG-EN-BRESSE</tows:nom_chf_l>
+   <tows:x_chf_lieu>8231</tows:x_chf_lieu>
+   <tows:y_chf_lieu>21379</tows:y_chf_lieu>
+   <tows:x_centroid>8244</tows:x_centroid>
+   <tows:y_centroid>21380</tows:y_centroid>
+   <tows:nom_dept>AIN</tows:nom_dept>
+   <tows:code_reg>82</tows:code_reg>
+   <tows:nom_region>RHONE-ALPES</tows:nom_region>
+   <tows:code_dept>01</tows:code_dept>
+   <tows:geom><gml:MultiPolygon srsName="EPSG:27582"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>801150,2092615 800669,2093190 800688,2095430 800780,2095795 800589,2096112 800333,2097190 799095,2098505 799136,2098838 799690,2100360 799329,2100395 797715,2100950 797655,2101330 797410,2102850 797149,2102788 796755,2102425 796738,2102785 796612,2103487 795234,2103892 794905,2104515 794547,2104359 791555,2102570 791465,2102760 791935,2104075 791835,2105023 791670,2105295 790205,2105555 790035,2105875 789304,2107116 788617,2107148 788005,2106760 787670,2106708 786705,2106990 786350,2107029 785720,2107335 785562,2108399 786670,2109486 786930,2109775 787055,2110010 787208,2110344 787367,2111056 786900,2113550 786795,2114260 786830,2114370 786811,2114751 786384,2116197 786550,2116940 786560,2117563 786465,2117860 785956,2119206 787211,2120474 787415,2120775 787600,2121475 787536,2121809 787137,2122743 786610,2123110 786457,2124100 787138,2124890 787365,2125160 787545,2125377 787880,2125830 788198,2126745 788225,2127075 789130,2128290 789370,2128585 789790,2129209 789995,2129525 790445,2131460 790237,2131793 789585,2132230 788993,2132742 788830,2133100 788650,2133655 788638,2134028 788673,2135142 789501,2136382 789510,2137110 789596,2138174 789680,2138520 789845,2139015 790050,2139590 790594,2140547 790750,2142011 790740,2142380 790739,2142716 791139,2143599 791749,2144456 791860,2144790 792199,2147049 792285,2147420 792880,2148815 793615,2150425 793737,2150782 793650,2152285 793618,2152660 793480,2153400 794012,2155103 794347,2155696 794535,2155980 794686,2156241 795135,2157025 796115,2159030 796193,2160314 796250,2160635 796311,2161408 796335,2161795 796324,2162102 796316,2163021 796385,2163470 796495,2163785 797830,2165380 797970,2165700 797959,2167362 797910,2167695 797905,2167835 798850,2169845 798930,2170117 798980,2170395 799122,2171035 799255,2171335 799340,2171435 800295,2171593 800326,2170924 800757,2170498 801505,2170754 802043,2171611 802820,2171760 804846,2171217 805165,2171380 805338,2170485 805485,2170210 808352,2168729 808655,2168520 809605,2168719 809930,2168735 811710,2170150 813076,2169640 814292,2170568 814670,2170640 815189,2171442 816978,2171075 817045,2172530 818290,2171719 819798,2171534 819990,2171205 819753,2170948 820496,2169812 820305,2169145 820810,2168648 821023,2167568 821020,2167190 821753,2167185 822453,2166355 822690,2166075 823263,2166394 823585,2166285 824250,2165476 825284,2165330 825600,2165160 828440,2165065 829372,2163119 828470,2162490 828705,2161655 828395,2161531 827745,2161519 828485,2161005 830445,2159908 831525,2159915 832747,2158958 833030,2158780 833286,2158494 833885,2158105 833687,2157807 832940,2157040 832830,2156696 833866,2155806 833825,2155445 833752,2155097 833675,2154750 835995,2153047 835930,2152675 836194,2151171 836185,2150780 836190,2150680 836405,2150149 836690,2150070 837059,2153840 837545,2154400 838628,2151187 838735,2150820 840056,2151192 840530,2151708 840855,2151840 841371,2151081 841670,2150965 841591,2150606 841093,2148479 840525,2148155 840483,2146631 841576,2145603 841898,2145394 843750,2145800 843973,2146033 844372,2145523 844675,2145410 846805,2146002 848292,2147688 848440,2148035 848651,2148733 850029,2148841 850390,2148775 851184,2149407 851650,2150710 851857,2150922 851710,2151180 852195,2152638 853883,2153465 854050,2153815 854684,2154550 854950,2153948 855010,2153605 854706,2152546 856495,2152522 857425,2151954 857675,2151680 857795,2151135 860115,2150917 860522,2149401 860356,2147845 860868,2145955 861160,2145690 861499,2145842 861800,2146060 863931,2146529 864270,2146675 867954,2146311 868320,2146245 868625,2146162 868940,2146145 870819,2146227 871569,2147047 872099,2147009 872230,2146655 873891,2148801 874080,2149145 875215,2148900 875688,2149908 875836,2151749 876350,2152270 877249,2151866 877575,2151825 877751,2152160 879950,2156500 880577,2157904 882757,2159490 884049,2160898 885600,2163565 886165,2164270 886435,2164140 889069,2163415 889778,2162493 890867,2162099 893000,2160395 894101,2160083 894575,2159465 894622,2158743 893375,2156340 892712,2155944 892540,2155185 891600,2153375 891281,2152677 891245,2152295 891340,2150917 890292,2149984 890080,2149695 890987,2147869 891235,2147615 891560,2147405 891794,2146272 891337,2145258 890413,2144570 889185,2145445 888822,2145356 887853,2144792 887180,2145110 886092,2143618 885735,2143730 885432,2143963 884760,2143997 883760,2143495 883455,2143280 882749,2142419 882058,2142149 881989,2141782 880591,2141448 880422,2140052 879890,2139555 879855,2139435 882197,2138192 882019,2137078 881408,2136753 880810,2134940 880202,2133632 880177,2132631 879600,2132205 879351,2132001 878142,2131755 877449,2131650 876853,2131962 875845,2130970 875089,2130628 874800,2130520 874322,2129464 874925,2128114 874725,2126982 872900,2126720 872100,2126810 871837,2127080 870648,2128513 869972,2128829 869296,2128495 869435,2127050 868710,2125650 868663,2125275 868525,2123780 868760,2123569 868985,2123070 868525,2121885 868617,2121591 868760,2120685 868864,2120349 869034,2119679 868545,2118760 868661,2118458 868975,2117935 868911,2117610 869020,2116295 869215,2115554 870970,2114005 870979,2113621 870925,2112855 871130,2111817 870721,2110485 870455,2110250 870800,2110165 870344,2109573 870311,2108843 870897,2107500 870710,2106390 870615,2106018 869975,2103410 869465,2101545 869314,2101232 869040,2099875 868989,2099512 868710,2098080 868050,2097320 867940,2096964 867995,2094425 867975,2094056 867825,2092595 867736,2092277 867995,2091670 867979,2091277 867788,2090131 868170,2088645 867935,2088380 867643,2088330 867110,2088110 867246,2087753 867588,2086334 866723,2085607 866013,2084278 865294,2084187 864275,2084575 864000,2084465 863659,2084328 861885,2084450 861845,2084109 862185,2083150 862398,2082820 862694,2082092 862533,2081333 860925,2079632 860842,2078870 861160,2078155 861300,2077808 861210,2077080 860973,2076787 860337,2076386 858511,2076155 858205,2075110 858072,2074811 857453,2074591 857320,2073960 857265,2073584 856650,2073221 856355,2073460 856182,2073797 855610,2074780 854744,2075941 854474,2077758 852864,2078730 852620,2079020 852647,2079386 851685,2079920 851354,2080021 850753,2079717 850470,2079917 850320,2080840 850069,2081131 850023,2082613 850741,2082507 851509,2081230 852157,2081554 852073,2082291 850451,2083206 850375,2083940 850111,2084174 849805,2084350 848375,2084500 848150,2084810 847545,2086215 847281,2086449 845980,2087620 845694,2087856 844840,2088564 842895,2091270 842098,2091898 841825,2092105 841604,2092424 841170,2093065 840895,2093318 839825,2094355 839769,2096198 840798,2096536 840745,2096910 840580,2097185 840305,2097470 839320,2098117 839165,2098880 839016,2099191 838200,2099825 836342,2100899 836100,2101165 835840,2101453 834252,2102554 833175,2102260 833017,2102031 832785,2101525 832719,2101162 832433,2100482 831189,2099710 830330,2098550 829565,2095140 829550,2094745 829422,2094389 828638,2093577 827810,2091920 827523,2091724 826955,2091325 826653,2091135 825785,2090510 825487,2090257 824587,2089517 822700,2089735 822339,2089692 821748,2090044 821660,2090765 821459,2091109 820815,2092110 820470,2092273 819281,2093148 818215,2093260 817851,2093406 816405,2093980 815735,2093715 815844,2092629 815501,2092497 814830,2094120 814502,2094025 814175,2093925 813785,2093907 811510,2093620 811202,2093793 810503,2093796 809935,2093390 808612,2093210 808305,2093030 807965,2092976 807085,2093490 806759,2093370 806450,2093210 805480,2092960 804700,2093105 804426,2093280 803230,2093210 802864,2093269 801150,2092615</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></tows:geom>
+   </tows:france>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/expected/wfs10_getfeatures_world_onefeature.txt b/demo/tests/expected/wfs10_getfeatures_world_onefeature.txt
new file mode 100644
index 0000000..f480e80
--- /dev/null
+++ b/demo/tests/expected/wfs10_getfeatures_world_onefeature.txt
@@ -0,0 +1,28 @@
+Content-Type: text/xml; subtype=gml/2.1.2
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.0.0&amp;request=DescribeFeatureType&amp;Typename=tows:world   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/2.1.2/feature.xsd'
+>
+<gml:boundedBy><gml:null>missing</gml:null></gml:boundedBy>
+  <gml:featureMember>
+   <tows:world fid="world.1">
+   <tows:name>Afghanistan</tows:name>
+   <tows:gmi_cntry>AFG</tows:gmi_cntry>
+   <tows:region>Asia</tows:region>
+   <tows:geom><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>65.627296,37.333199 65.646927,37.458881 65.70137,37.53693 65.766083,37.534161 65.785522,37.568878 66.30275,37.323601 66.538765,37.360512 66.586906,37.368038 66.665253,37.338322 66.744423,37.36137 67.021637,37.377201 67.200256,37.246651 67.229424,37.191929 67.266373,37.185261 67.424408,37.234989 67.521637,37.27248 67.557457,37.215542 67.649406,37.24609 67.774139,37.206089 67.777153,37.185799 67.791641,37.088322 67.885529,37.061371 67.910522,37.014431 68.035522,36.924709 68.28331,37.019981 68.278313,37.086929 68.301643,37.111099 68.413017,37.104431 68.412193,37.148041 68.524979,37.16193 68.654694,37.246929 68.825813,37.247761 68.809402,37.322491 68.85025,37.324711 68.904968,37.272209 68.924408,37.28471 68.891647,37.31749 68.999687,37.307758 69.246628,37.094151 69.333038,37.124981 69.45137,37.22998 69.381348,37.344151 69.382736,37.455818 69.515808,37.580818 69.91803,37.611931 69.958588,37.564991 70.134979,37.529148 70.255539,37.62109 70.276917,37.741371 70.165527,37.872211 70.170242,37.94165 70.203857,37.92054 70.378304,38.057758 70.491913,38.16721 70.584412,38.278591 70.596359,38.334148 70.685516,38.375259 70.672203,38.414429 70.880524,38.453041 71.101913,38.40609 71.363022,38.248871 71.363861,38.18803 71.284698,38.019981 71.264137,37.918049 71.37468,37.905819 71.546356,37.942478 71.591919,37.903042 71.588577,37.81609 71.528847,37.764431 71.49025,37.284161 71.446907,37.20776 71.43219,37.05859 71.568314,36.741371 71.695236,36.672211 71.842743,36.692478 72.011368,36.812199 72.346626,36.989979 72.663589,37.026089 72.798859,37.22998 73.08136,37.320541 73.150528,37.400822 73.314407,37.463322 73.776642,37.434429 73.752762,37.331379 73.649406,37.304428 73.619957,37.26276 73.634407,37.239979 73.792473,37.22942 74.363861,37.4286 74.400803,37.399429 74.699692,37.39193 74.898827,37.240299 74.816933,37.219151 74.763313,37.30109 74.669418,37.266102 74.651077,37.234711 74.537193,37.243038 74.392197,37.175259 74.400528,37.139149 74.567749,37.02647 74.558006,36.96526 74.482193,37.011101 74.336906,36.958881 74.251923,36.899429 74.158859,36.906651 74.06218,36.821659 73.963028,36.837761 73.779694,36.901089 73.113022,36.873871 72.492462,36.771931 72.181641,36.71471 72.191643,36.6572 72.073303,36.628868 72.074692,36.58942 71.795807,36.491928 71.817749,36.41666 71.753036,36.40749 71.646637,36.46804 71.563019,36.372478 71.582748,36.335819 71.248581,36.133041 71.188019,36.047211 71.291077,35.96859 71.380524,35.946091 71.545242,35.711102 71.508591,35.626652 71.613861,35.561932 71.606918,35.48193 71.647202,35.436939 71.549133,35.32832 71.553574,35.28915 71.659126,35.207489 71.618027,35.131371 71.543297,35.0947 71.496078,34.959431 71.313858,34.886929 71.225517,34.744431 71.09581,34.676651 71.094971,34.56805 70.995796,34.55859 70.978027,34.510818 71.073029,34.39415 71.153313,34.36137 71.135529,34.166088 70.981079,34.008881 70.905533,34.013321 70.900528,33.973591 70.491348,33.943039 69.902763,34.031101 69.907471,33.881931 69.985519,33.75304 70.132736,33.735538 70.196617,33.64082 70.197739,33.485821 70.306084,33.396099 70.32692,33.33194 70.144974,33.202492 70.067749,33.20499 70.033577,33.139431 69.881073,33.089981 69.791351,33.126942 69.561081,33.081928 69.492462,33.008598 69.515259,32.873878 69.394974,32.773869 69.456917,32.682209 69.397751,32.587761 69.287483,32.526379 69.248016,32.443871 69.283043,32.21777 69.287483,32.069149 69.333862,31.94389 69.029694,31.64555 68.833038,31.60388 68.731918,31.69944 68.712479,31.778879 68.54747,31.829161 68.444122,31.79472 68.447739,31.77277 68.57164,31.76527 68.53775,31.72666 68.221626,31.81559 68.166077,31.83305 67.98053,31.63583 67.887482,31.63999 67.738022,31.53083 67.581093,31.5336 67.646362,31.40999 67.766922,31.4111 67.799698,31.38249 67.791924,31.341101 67.288017,31.2136 67.256363,31.22249 67.069702,31.239161 67.034698,31.25444 67.051643,31.297779 67.036911,31.318609 66.891647,31.296101 66.723022,31.21221 66.684128,31.086109 66.56636,30.97777 66.404968,30.94611 66.281921,30.57527 66.35025,30.45055 66.259697,30.114161 66.238297,30.071381 66.361359,29.966101 66.256638,29.85194 65.417473,29.640551 65.034126,29.5411 64.695511,29.58638 64.273857,29.52389 64.193024,29.48749 64.131348,29.394159 63.5872,29.50388 62.78693,29.43388 62.484428,29.406099 61.743599,29.615829 60.99387,29.826099 60.866871,29.862431 61.25304,30.259991 61.812759,30.843611 61.803871,30.94582 61.84721,31.04888 61.76582,31.24527 61.771099,31.318331 61.7136,31.383329 61.619431,31.395821 60.843868,31.498329 60.810261,31.8736 60.857769,32.234718 60.74165,32.578869 60.581928,33.071659 60.591091,33.16304 60.85165,33.418049 60.858318,33.49387 60.9286,33.504429 60.901649,33.554428 60.649151,33.574989 60.522758,33.653042 60.50526,33.739151 60.55415,33.81332 60.52137,33.999149 60.513599,34.150822 60.67165,34.313599 60.911091,34.31638 60.89777,34.345821 60.756649,34.483318 60.733601,34.54166 60.863602,34.576389 61.065262,34.812759 61.11388,35.201649 61.104431,35.279148 61.1861,35.29694 61.239151,35.481091 61.27776,35.52026 61.278721,35.60675 61.365822,35.639709 61.464989,35.52721 61.576649,35.450821 61.802479,35.411091 61.97221,35.45998 62.100819,35.394711 62.259159,35.297771 62.305538,35.145538 62.459431,35.286381 62.62331,35.224979 63.110538,35.481369 63.095261,35.626091 63.23888,35.69553 63.10416,35.825821 63.119431,35.861931 63.317211,35.852211 63.538879,35.90971 63.595539,35.9622 63.933868,36.03915 64.063858,36.000271 64.059692,36.088039 64.169418,36.167488 64.282471,36.15192 64.32164,36.216381 64.458862,36.247211 64.570534,36.35638 64.627747,36.45998 64.61525,36.629429 64.795242,36.923038 64.779137,37.095821 64.798019,37.124981 65.072746,37.244431 65.530807,37.2486 65.627296,37.333199</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></tows:geom>
+   </tows:world>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/expected/wfs11_describe.txt b/demo/tests/expected/wfs11_describe.txt
new file mode 100644
index 0000000..aad422c
--- /dev/null
+++ b/demo/tests/expected/wfs11_describe.txt
@@ -0,0 +1,40 @@
+Content-Type: text/xml; subtype=gml/3.1.1;
+
+<?xml version='1.0' encoding='UTF-8'?>
+<xs:schema targetNamespace='http://www.tinyows.org/' xmlns:tows='http://www.tinyows.org/' xmlns:ogc='http://www.opengis.net/ogc' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns='http://www.w3.org/2001/XMLSchema' xmlns:gml='http://www.opengis.net/gml' elementFormDefault='qualified' version='1.1'>
+<xs:import namespace='http://www.opengis.net/gml' schemaLocation='http://schemas.opengis.net/gml/3.1.1/base/gml.xsd'/>
+<xs:element name='world' type='tows:worldType' substitutionGroup='gml:_Feature' />
+<xs:complexType name='worldType'>
+ <xs:complexContent>
+  <xs:extension base='gml:AbstractFeatureType'>
+   <xs:sequence>
+    <xs:element name ='name' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='40'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='gmi_cntry' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='3'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='region' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='25'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='geom' type='gml:MultiSurfacePropertyType' nillable='true' minOccurs='0' maxOccurs='1'/>
+   </xs:sequence>
+  </xs:extension>
+ </xs:complexContent>
+</xs:complexType>
+<xs:element name='france' type='tows:franceType' substitutionGroup='gml:_Feature' />
+<xs:complexType name='franceType'>
+ <xs:complexContent>
+  <xs:extension base='gml:AbstractFeatureType'>
+   <xs:sequence>
+    <xs:element name ='id_geofla' type='long' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='code_chf_l' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='3'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='nom_chf_l' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='50'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='x_chf_lieu' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='y_chf_lieu' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='x_centroid' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='y_centroid' type='int' nillable='true' minOccurs='0' maxOccurs='1'/>
+    <xs:element name ='nom_dept' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='30'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='code_reg' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='2'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='nom_region' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='30'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='code_dept' nillable='true' minOccurs='0' maxOccurs='1'>
+<xs:simpleType><xs:restriction base='string'><xs:maxLength value='3'/></xs:restriction></xs:simpleType></xs:element>    <xs:element name ='geom' type='gml:MultiSurfacePropertyType' nillable='true' minOccurs='0' maxOccurs='1'/>
+   </xs:sequence>
+  </xs:extension>
+ </xs:complexContent>
+</xs:complexType>
+</xs:schema>
\ No newline at end of file
diff --git a/demo/tests/expected/wfs11_getcaps.txt b/demo/tests/expected/wfs11_getcaps.txt
new file mode 100644
index 0000000..6091c9c
--- /dev/null
+++ b/demo/tests/expected/wfs11_getcaps.txt
@@ -0,0 +1,257 @@
+Content-Type: application/xml
+
+<?xml version='1.0' encoding='UTF-8'?>
+<WFS_Capabilities version='1.1.0' updateSequence='0'
+  xmlns='http://www.opengis.net/wfs'
+  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+  xmlns:ogc='http://www.opengis.net/ogc'
+  xmlns:gml='http://www.opengis.net/gml'
+  xmlns:ows='http://www.opengis.net/ows'
+  xmlns:xlink='http://www.w3.org/1999/xlink'
+  xsi:schemaLocation='http://www.opengis.net/wfs
+  http://schemas.opengis.net/wfs/1.1.0/wfs.xsd' >
+ <ows:ServiceIdentification>
+  <ows:Title>TinyOWS Server - Demo Service</ows:Title>
+  <ows:ServiceType>WFS</ows:ServiceType>
+  <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
+  <ows:ServiceTypeVersion>1.1.0</ows:ServiceTypeVersion>
+ </ows:ServiceIdentification>
+ <ows:OperationsMetadata>
+  <ows:Operation name='GetCapabilities'>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Get xlink:href="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </ows:HTTP>
+    </ows:DCP>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Post xlink:href="http://127.0.0.1/cgi-bin/tinyows"/>
+     </ows:HTTP>
+    </ows:DCP>
+  <ows:Parameter name='AcceptVersions'>
+  <ows:Value>1.1.0</ows:Value>
+  <ows:Value>1.0.0</ows:Value>
+  </ows:Parameter>
+  <ows:Parameter name='AcceptFormats'>
+  <ows:Value>text/xml</ows:Value>
+  </ows:Parameter>
+  <ows:Parameter name='Sections'>
+  <ows:Value>ServiceIdentification</ows:Value>
+  <ows:Value>ServiceProvider</ows:Value>
+  <ows:Value>OperationsMetadata</ows:Value>
+  <ows:Value>FeatureTypeList</ows:Value>
+  <ows:Value>ServesGMLObjectTypeList</ows:Value>
+  <ows:Value>SupportsGMLObjectTypeList</ows:Value>
+  </ows:Parameter>
+   </ows:Operation>
+   <ows:Operation name='DescribeFeatureType'>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Get xlink:href="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </ows:HTTP>
+    </ows:DCP>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Post xlink:href="http://127.0.0.1/cgi-bin/tinyows"/>
+     </ows:HTTP>
+    </ows:DCP>
+  <ows:Parameter name='outputFormat'>
+  <ows:Value>text/xml; subtype=gml/3.1.1</ows:Value>
+  <ows:Value>text/xml; subtype=gml/2.1.2</ows:Value>
+  </ows:Parameter>
+   </ows:Operation>
+   <ows:Operation name='GetFeature'>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Get xlink:href="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </ows:HTTP>
+    </ows:DCP>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Post xlink:href="http://127.0.0.1/cgi-bin/tinyows"/>
+     </ows:HTTP>
+    </ows:DCP>
+  <ows:Parameter name='resultType'>
+  <ows:Value>results</ows:Value>
+  <ows:Value>hits</ows:Value>
+  </ows:Parameter>
+  <ows:Parameter name='outputFormat'>
+  <ows:Value>text/xml; subtype=gml/3.1.1</ows:Value>
+  <ows:Value>text/xml; subtype=gml/2.1.2</ows:Value>
+  <ows:Value>application/json</ows:Value>
+  </ows:Parameter>
+   </ows:Operation>
+   <ows:Operation name='Transaction'>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Get xlink:href="http://127.0.0.1/cgi-bin/tinyows?"/>
+     </ows:HTTP>
+    </ows:DCP>
+    <ows:DCP>
+     <ows:HTTP>
+      <ows:Post xlink:href="http://127.0.0.1/cgi-bin/tinyows"/>
+     </ows:HTTP>
+    </ows:DCP>
+    <ows:Parameter name='inputFormat'>
+     <ows:Value>text/xml; subtype=gml/3.1.1</ows:Value>
+    </ows:Parameter>
+    <ows:Parameter name='idgen'>
+     <ows:Value>GenerateNew</ows:Value>
+     <ows:Value>UseExisting</ows:Value>
+    </ows:Parameter>
+   </ows:Operation>
+   <ows:Constraint name='LocalTraverseXLinkScope'>
+    <ows:Value>0</ows:Value>
+   </ows:Constraint>
+   <ows:Constraint name='RemoteTraverseXLinkScope'>
+    <ows:Value>0</ows:Value>
+   </ows:Constraint>
+ </ows:OperationsMetadata>
+ <FeatureTypeList>
+  <Operations>
+ <Operation>Query</Operation>
+   <Operation>Insert</Operation>
+   <Operation>Update</Operation>
+   <Operation>Delete</Operation>
+  </Operations>
+<FeatureType xmlns:tows="http://www.tinyows.org/">
+  <Name>tows:world</Name>
+  <Title>World Administrative Boundaries</Title>
+ <DefaultSRS>urn:ogc:def:crs:EPSG::4326</DefaultSRS>
+  <ows:WGS84BoundingBox> <ows:LowerCorner>-180.000183 -90.000000</ows:LowerCorner> <ows:UpperCorner>180.000000 83.623032</ows:UpperCorner> </ows:WGS84BoundingBox>
+</FeatureType>
+<FeatureType xmlns:tows="http://www.tinyows.org/">
+  <Name>tows:france</Name>
+  <Title>French Administrative Sub Boundaries (IGN - GeoFLA Departements)</Title>
+ <DefaultSRS>urn:ogc:def:crs:EPSG::27582</DefaultSRS>
+  <ows:WGS84BoundingBox> <ows:LowerCorner>-6.091001 41.347435</ows:LowerCorner> <ows:UpperCorner>10.812651 50.803540</ows:UpperCorner> </ows:WGS84BoundingBox>
+</FeatureType>
+ </FeatureTypeList>
+ <SupportsGMLObjectTypeList>
+  <GMLObjectType>
+   <Name>gml:AbstractGMLFeatureType</Name>
+   <OutputFormats>
+    <Format>text/xml; subtype=gml/2.1.2</Format>
+    <Format>text/xml; subtype=gml/3.1.1</Format>
+   </OutputFormats>
+  </GMLObjectType>
+  <GMLObjectType>
+   <Name>gml:PointType</Name>
+   <OutputFormats>
+    <Format>text/xml; subtype=gml/2.1.2</Format>
+    <Format>text/xml; subtype=gml/3.1.1</Format>
+   </OutputFormats>
+  </GMLObjectType>
+  <GMLObjectType>
+   <Name>gml:LineStringType</Name>
+   <OutputFormats>
+    <Format>text/xml; subtype=gml/2.1.2</Format>
+    <Format>text/xml; subtype=gml/3.1.1</Format>
+   </OutputFormats>
+  </GMLObjectType>
+  <GMLObjectType>
+   <Name>gml:PolygonType</Name>
+   <OutputFormats>
+    <Format>text/xml; subtype=gml/2.1.2</Format>
+    <Format>text/xml; subtype=gml/3.1.1</Format>
+   </OutputFormats>
+  </GMLObjectType>
+  <GMLObjectType>
+   <Name>gml:MultiPointType</Name>
+   <OutputFormats>
+    <Format>text/xml; subtype=gml/2.1.2</Format>
+    <Format>text/xml; subtype=gml/3.1.1</Format>
+   </OutputFormats>
+  </GMLObjectType>
+  <GMLObjectType>
+   <Name>gml:MultiLineStringType</Name>
+   <OutputFormats>
+    <Format>text/xml; subtype=gml/2.1.2</Format>
+    <Format>text/xml; subtype=gml/3.1.1</Format>
+   </OutputFormats>
+  </GMLObjectType>
+  <GMLObjectType>
+   <Name>gml:MultiPolygonType</Name>
+   <OutputFormats>
+    <Format>text/xml; subtype=gml/2.1.2</Format>
+    <Format>text/xml; subtype=gml/3.1.1</Format>
+   </OutputFormats>
+  </GMLObjectType>
+ </SupportsGMLObjectTypeList>
+<ogc:Filter_Capabilities>
+ <ogc:Spatial_Capabilities>
+  <ogc:GeometryOperands>
+   <ogc:GeometryOperand>gml:Envelope</ogc:GeometryOperand>
+   <ogc:GeometryOperand>gml:Point</ogc:GeometryOperand>
+   <ogc:GeometryOperand>gml:LineString</ogc:GeometryOperand>
+   <ogc:GeometryOperand>gml:Polygon</ogc:GeometryOperand>
+   <ogc:GeometryOperand>gml:Triangle</ogc:GeometryOperand>
+   <ogc:GeometryOperand>gml:PolyhedralSurface</ogc:GeometryOperand>
+   <ogc:GeometryOperand>gml:Tin</ogc:GeometryOperand>
+  </ogc:GeometryOperands>
+  <ogc:SpatialOperators>
+  <ogc:SpatialOperator name='Disjoint'/>
+  <ogc:SpatialOperator name='Equals'/>
+  <ogc:SpatialOperator name='DWithin'/>
+  <ogc:SpatialOperator name='Beyond'/>
+  <ogc:SpatialOperator name='Intersects'/>
+  <ogc:SpatialOperator name='Touches'/>
+  <ogc:SpatialOperator name='Crosses'/>
+  <ogc:SpatialOperator name='Within'/>
+  <ogc:SpatialOperator name='Contains'/>
+  <ogc:SpatialOperator name='Overlaps'/>
+  <ogc:SpatialOperator name='BBOX'/>
+ </ogc:SpatialOperators>
+ </ogc:Spatial_Capabilities>
+ <ogc:Scalar_Capabilities>
+  <ogc:LogicalOperators/>
+  <ogc:ComparisonOperators>
+   <ogc:ComparisonOperator>EqualTo</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>NotEqualTo</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>LessThan</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>GreaterThan</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>LessThanEqualTo</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>GreaterThanEqualTo</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>Between</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>Like</ogc:ComparisonOperator>
+   <ogc:ComparisonOperator>NullCheck</ogc:ComparisonOperator>
+  </ogc:ComparisonOperators>
+  <ogc:ArithmeticOperators>
+   <ogc:SimpleArithmetic/>
+   <ogc:Functions>
+    <ogc:FunctionNames>
+     <ogc:FunctionName nArgs='1'>abs</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>acos</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>asin</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>atan</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>avg</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>cbrt</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>ceil</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>ceiling</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>cos</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>cot</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>count</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>degrees</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>exp</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>floor</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>length</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>ln</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>log</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>min</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>max</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>radians</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>round</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>sin</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>sqrt</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>tan</ogc:FunctionName>
+     <ogc:FunctionName nArgs='1'>trunc</ogc:FunctionName>
+    </ogc:FunctionNames>
+   </ogc:Functions>
+  </ogc:ArithmeticOperators>
+ </ogc:Scalar_Capabilities>
+ <ogc:Id_Capabilities>
+  <ogc:EID/>
+  <ogc:FID/>
+ </ogc:Id_Capabilities>
+</ogc:Filter_Capabilities>
+</WFS_Capabilities>
diff --git a/demo/tests/expected/wfs11_getfeatures_france_onefeature.txt b/demo/tests/expected/wfs11_getfeatures_france_onefeature.txt
new file mode 100644
index 0000000..2b3c20d
--- /dev/null
+++ b/demo/tests/expected/wfs11_getfeatures_france_onefeature.txt
@@ -0,0 +1,35 @@
+Content-Type: text/xml; subtype=gml/3.1.1
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;Typename=tows:france   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.1.0/wfs.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/3.1.1/base/gml.xsd'
+>
+  <gml:featureMember>
+   <tows:france gml:id="france.1">
+   <tows:id_geofla>49</tows:id_geofla>
+   <tows:code_chf_l>053</tows:code_chf_l>
+   <tows:nom_chf_l>BOURG-EN-BRESSE</tows:nom_chf_l>
+   <tows:x_chf_lieu>8231</tows:x_chf_lieu>
+   <tows:y_chf_lieu>21379</tows:y_chf_lieu>
+   <tows:x_centroid>8244</tows:x_centroid>
+   <tows:y_centroid>21380</tows:y_centroid>
+   <tows:nom_dept>AIN</tows:nom_dept>
+   <tows:code_reg>82</tows:code_reg>
+   <tows:nom_region>RHONE-ALPES</tows:nom_region>
+   <tows:code_dept>01</tows:code_dept>
+   <tows:geom><gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::27582"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>2092615 801150 2093190 800669 2095430 800688 2095795 800780 2096112 800589 2097190 800333 2098505 799095 2098838 799136 2100360 799690 2100395 799329 2100950 797715 2101330 797655 2102850 797410 2102788 797149 2102425 796755 2102785 796738 2103487 796612 2103892 795234 2104515 794905 2104359 794547 2102570 791555 2102760 791465 2104075 791935 2105023 791835 2105295 791670 2105555 790205 2105875 790035 2107116 789304 2107148 788617 2106760 788005 2106708 787670 2106990 786705 2107029 786350 2107335 785720 2108399 785562 2109486 786670 2109775 786930 2110010 787055 2110344 787208 2111056 787367 2113550 786900 2114260 786795 2114370 786830 2114751 786811 2116197 786384 2116940 786550 2117563 786560 2117860 786465 2119206 785956 2120474 787211 2120775 787415 2121475 787600 2121809 787536 2122743 787137 2123110 786610 2124100 786457 2124890 787138 2125160 787365 2125377 787545 2125830 787880 2126745 788198 2127075 788225 2128290 789130 2128585 789370 2129209 789790 2129525 789995 2131460 790445 2131793 790237 2132230 789585 2132742 788993 2133100 788830 2133655 788650 2134028 788638 2135142 788673 2136382 789501 2137110 789510 2138174 789596 2138520 789680 2139015 789845 2139590 790050 2140547 790594 2142011 790750 2142380 790740 2142716 790739 2143599 791139 2144456 791749 2144790 791860 2147049 792199 2147420 792285 2148815 792880 2150425 793615 2150782 793737 2152285 793650 2152660 793618 2153400 793480 2155103 794012 2155696 794347 2155980 794535 2156241 794686 2157025 795135 2159030 796115 2160314 796193 2160635 796250 2161408 796311 2161795 796335 2162102 796324 2163021 796316 2163470 796385 2163785 796495 2165380 797830 2165700 797970 2167362 797959 2167695 797910 2167835 797905 2169845 798850 2170117 798930 2170395 798980 2171035 799122 2171335 799255 2171435 799340 2171593 800295 2170924 800326 2170498 800757 2170754 801505 2171611 802043 2171760 802820 2171217 804846 2171380 805165 2170485 805338 2170210 805485 2168729 808352 2168520 808655 2168719 809605 2168735 809930 2170150 811710 2169640 813076 2170568 814292 2170640 814670 2171442 815189 2171075 816978 2172530 817045 2171719 818290 2171534 819798 2171205 819990 2170948 819753 2169812 820496 2169145 820305 2168648 820810 2167568 821023 2167190 821020 2167185 821753 2166355 822453 2166075 822690 2166394 823263 2166285 823585 2165476 824250 2165330 825284 2165160 825600 2165065 828440 2163119 829372 2162490 828470 2161655 828705 2161531 828395 2161519 827745 2161005 828485 2159908 830445 2159915 831525 2158958 832747 2158780 833030 2158494 833286 2158105 833885 2157807 833687 2157040 832940 2156696 832830 2155806 833866 2155445 833825 2155097 833752 2154750 833675 2153047 835995 2152675 835930 2151171 836194 2150780 836185 2150680 836190 2150149 836405 2150070 836690 2153840 837059 2154400 837545 2151187 838628 2150820 838735 2151192 840056 2151708 840530 2151840 840855 2151081 841371 2150965 841670 2150606 841591 2148479 841093 2148155 840525 2146631 840483 2145603 841576 2145394 841898 2145800 843750 2146033 843973 2145523 844372 2145410 844675 2146002 846805 2147688 848292 2148035 848440 2148733 848651 2148841 850029 2148775 850390 2149407 851184 2150710 851650 2150922 851857 2151180 851710 2152638 852195 2153465 853883 2153815 854050 2154550 854684 2153948 854950 2153605 855010 2152546 854706 2152522 856495 2151954 857425 2151680 857675 2151135 857795 2150917 860115 2149401 860522 2147845 860356 2145955 860868 2145690 861160 2145842 861499 2146060 861800 2146529 863931 2146675 864270 2146311 867954 2146245 868320 2146162 868625 2146145 868940 2146227 870819 2147047 871569 2147009 872099 2146655 872230 2148801 873891 2149145 874080 2148900 875215 2149908 875688 2151749 875836 2152270 876350 2151866 877249 2151825 877575 2152160 877751 2156500 879950 2157904 880577 2159490 882757 2160898 884049 2163565 885600 2164270 886165 2164140 886435 2163415 889069 2162493 889778 2162099 890867 2160395 893000 2160083 894101 2159465 894575 2158743 894622 2156340 893375 2155944 892712 2155185 892540 2153375 891600 2152677 891281 2152295 891245 2150917 891340 2149984 890292 2149695 890080 2147869 890987 2147615 891235 2147405 891560 2146272 891794 2145258 891337 2144570 890413 2145445 889185 2145356 888822 2144792 887853 2145110 887180 2143618 886092 2143730 885735 2143963 885432 2143997 884760 2143495 883760 2143280 883455 2142419 882749 2142149 882058 2141782 881989 2141448 880591 2140052 880422 2139555 879890 2139435 879855 2138192 882197 2137078 882019 2136753 881408 2134940 880810 2133632 880202 2132631 880177 2132205 879600 2132001 879351 2131755 878142 2131650 877449 2131962 876853 2130970 875845 2130628 875089 2130520 874800 2129464 874322 2128114 874925 2126982 874725 2126720 872900 2126810 872100 2127080 871837 2128513 870648 2128829 869972 2128495 869296 2127050 869435 2125650 868710 2125275 868663 2123780 868525 2123569 868760 2123070 868985 2121885 868525 2121591 868617 2120685 868760 2120349 868864 2119679 869034 2118760 868545 2118458 868661 2117935 868975 2117610 868911 2116295 869020 2115554 869215 2114005 870970 2113621 870979 2112855 870925 2111817 871130 2110485 870721 2110250 870455 2110165 870800 2109573 870344 2108843 870311 2107500 870897 2106390 870710 2106018 870615 2103410 869975 2101545 869465 2101232 869314 2099875 869040 2099512 868989 2098080 868710 2097320 868050 2096964 867940 2094425 867995 2094056 867975 2092595 867825 2092277 867736 2091670 867995 2091277 867979 2090131 867788 2088645 868170 2088380 867935 2088330 867643 2088110 867110 2087753 867246 2086334 867588 2085607 866723 2084278 866013 2084187 865294 2084575 864275 2084465 864000 2084328 863659 2084450 861885 2084109 861845 2083150 862185 2082820 862398 2082092 862694 2081333 862533 2079632 860925 2078870 860842 2078155 861160 2077808 861300 2077080 861210 2076787 860973 2076386 860337 2076155 858511 2075110 858205 2074811 858072 2074591 857453 2073960 857320 2073584 857265 2073221 856650 2073460 856355 2073797 856182 2074780 855610 2075941 854744 2077758 854474 2078730 852864 2079020 852620 2079386 852647 2079920 851685 2080021 851354 2079717 850753 2079917 850470 2080840 850320 2081131 850069 2082613 850023 2082507 850741 2081230 851509 2081554 852157 2082291 852073 2083206 850451 2083940 850375 2084174 850111 2084350 849805 2084500 848375 2084810 848150 2086215 847545 2086449 847281 2087620 845980 2087856 845694 2088564 844840 2091270 842895 2091898 842098 2092105 841825 2092424 841604 2093065 841170 2093318 840895 2094355 839825 2096198 839769 2096536 840798 2096910 840745 2097185 840580 2097470 840305 2098117 839320 2098880 839165 2099191 839016 2099825 838200 2100899 836342 2101165 836100 2101453 835840 2102554 834252 2102260 833175 2102031 833017 2101525 832785 2101162 832719 2100482 832433 2099710 831189 2098550 830330 2095140 829565 2094745 829550 2094389 829422 2093577 828638 2091920 827810 2091724 827523 2091325 826955 2091135 826653 2090510 825785 2090257 825487 2089517 824587 2089735 822700 2089692 822339 2090044 821748 2090765 821660 2091109 821459 2092110 820815 2092273 820470 2093148 819281 2093260 818215 2093406 817851 2093980 816405 2093715 815735 2092629 815844 2092497 815501 2094120 814830 2094025 814502 2093925 814175 2093907 813785 2093620 811510 2093793 811202 2093796 810503 2093390 809935 2093210 808612 2093030 808305 2092976 807965 2093490 807085 2093370 806759 2093210 806450 2092960 805480 2093105 804700 2093280 804426 2093210 803230 2093269 802864 2092615 801150</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></tows:geom>
+   </tows:france>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/expected/wfs11_getfeatures_world_onefeature.txt b/demo/tests/expected/wfs11_getfeatures_world_onefeature.txt
new file mode 100644
index 0000000..06d3726
--- /dev/null
+++ b/demo/tests/expected/wfs11_getfeatures_world_onefeature.txt
@@ -0,0 +1,27 @@
+Content-Type: text/xml; subtype=gml/3.1.1
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;Typename=tows:world   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.1.0/wfs.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/3.1.1/base/gml.xsd'
+>
+  <gml:featureMember>
+   <tows:world gml:id="world.1">
+   <tows:name>Afghanistan</tows:name>
+   <tows:gmi_cntry>AFG</tows:gmi_cntry>
+   <tows:region>Asia</tows:region>
+   <tows:geom><gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::4326"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>37.333199 65.627296 37.458881 65.646927 37.53693 65.70137 37.534161 65.766083 37.568878 65.785522 37.323601 66.30275 37.360512 66.538765 37.368038 66.586906 37.338322 66.665253 37.36137 66.744423 37.377201 67.021637 37.246651 67.200256 37.191929 67.229424 37.185261 67.266373 37.234989 67.424408 37.27248 67.521637 37.215542 67.557457 37.24609 67.649406 37.206089 67.774139 37.185799 67.777153 37.088322 67.791641 37.061371 67.885529 37.014431 67.910522 36.924709 68.035522 37.019981 68.28331 37.086929 68.278313 37.111099 68.301643 37.104431 68.413017 37.148041 68.412193 37.16193 68.524979 37.246929 68.654694 37.247761 68.825813 37.322491 68.809402 37.324711 68.85025 37.272209 68.904968 37.28471 68.924408 37.31749 68.891647 37.307758 68.999687 37.094151 69.246628 37.124981 69.333038 37.22998 69.45137 37.344151 69.381348 37.455818 69.382736 37.580818 69.515808 37.611931 69.91803 37.564991 69.958588 37.529148 70.134979 37.62109 70.255539 37.741371 70.276917 37.872211 70.165527 37.94165 70.170242 37.92054 70.203857 38.057758 70.378304 38.16721 70.491913 38.278591 70.584412 38.334148 70.596359 38.375259 70.685516 38.414429 70.672203 38.453041 70.880524 38.40609 71.101913 38.248871 71.363022 38.18803 71.363861 38.019981 71.284698 37.918049 71.264137 37.905819 71.37468 37.942478 71.546356 37.903042 71.591919 37.81609 71.588577 37.764431 71.528847 37.284161 71.49025 37.20776 71.446907 37.05859 71.43219 36.741371 71.568314 36.672211 71.695236 36.692478 71.842743 36.812199 72.011368 36.989979 72.346626 37.026089 72.663589 37.22998 72.798859 37.320541 73.08136 37.400822 73.150528 37.463322 73.314407 37.434429 73.776642 37.331379 73.752762 37.304428 73.649406 37.26276 73.619957 37.239979 73.634407 37.22942 73.792473 37.4286 74.363861 37.399429 74.400803 37.39193 74.699692 37.240299 74.898827 37.219151 74.816933 37.30109 74.763313 37.266102 74.669418 37.234711 74.651077 37.243038 74.537193 37.175259 74.392197 37.139149 74.400528 37.02647 74.567749 36.96526 74.558006 37.011101 74.482193 36.958881 74.336906 36.899429 74.251923 36.906651 74.158859 36.821659 74.06218 36.837761 73.963028 36.901089 73.779694 36.873871 73.113022 36.771931 72.492462 36.71471 72.181641 36.6572 72.191643 36.628868 72.073303 36.58942 72.074692 36.491928 71.795807 36.41666 71.817749 36.40749 71.753036 36.46804 71.646637 36.372478 71.563019 36.335819 71.582748 36.133041 71.248581 36.047211 71.188019 35.96859 71.291077 35.946091 71.380524 35.711102 71.545242 35.626652 71.508591 35.561932 71.613861 35.48193 71.606918 35.436939 71.647202 35.32832 71.549133 35.28915 71.553574 35.207489 71.659126 35.131371 71.618027 35.0947 71.543297 34.959431 71.496078 34.886929 71.313858 34.744431 71.225517 34.676651 71.09581 34.56805 71.094971 34.55859 70.995796 34.510818 70.978027 34.39415 71.073029 34.36137 71.153313 34.166088 71.135529 34.008881 70.981079 34.013321 70.905533 33.973591 70.900528 33.943039 70.491348 34.031101 69.902763 33.881931 69.907471 33.75304 69.985519 33.735538 70.132736 33.64082 70.196617 33.485821 70.197739 33.396099 70.306084 33.33194 70.32692 33.202492 70.144974 33.20499 70.067749 33.139431 70.033577 33.089981 69.881073 33.126942 69.791351 33.081928 69.561081 33.008598 69.492462 32.873878 69.515259 32.773869 69.394974 32.682209 69.456917 32.587761 69.397751 32.526379 69.287483 32.443871 69.248016 32.21777 69.283043 32.069149 69.287483 31.94389 69.333862 31.64555 69.029694 31.60388 68.833038 31.69944 68.731918 31.778879 68.712479 31.829161 68.54747 31.79472 68.444122 31.77277 68.447739 31.76527 68.57164 31.72666 68.53775 31.81559 68.221626 31.83305 68.166077 31.63583 67.98053 31.63999 67.887482 31.53083 67.738022 31.5336 67.581093 31.40999 67.646362 31.4111 67.766922 31.38249 67.799698 31.341101 67.791924 31.2136 67.288017 31.22249 67.256363 31.239161 67.069702 31.25444 67.034698 31.297779 67.051643 31.318609 67.036911 31.296101 66.891647 31.21221 66.723022 31.086109 66.684128 30.97777 66.56636 30.94611 66.404968 30.57527 66.281921 30.45055 66.35025 30.114161 66.259697 30.071381 66.238297 29.966101 66.361359 29.85194 66.256638 29.640551 65.417473 29.5411 65.034126 29.58638 64.695511 29.52389 64.273857 29.48749 64.193024 29.394159 64.131348 29.50388 63.5872 29.43388 62.78693 29.406099 62.484428 29.615829 61.743599 29.826099 60.99387 29.862431 60.866871 30.259991 61.25304 30.843611 61.812759 30.94582 61.803871 31.04888 61.84721 31.24527 61.76582 31.318331 61.771099 31.383329 61.7136 31.395821 61.619431 31.498329 60.843868 31.8736 60.810261 32.234718 60.857769 32.578869 60.74165 33.071659 60.581928 33.16304 60.591091 33.418049 60.85165 33.49387 60.858318 33.504429 60.9286 33.554428 60.901649 33.574989 60.649151 33.653042 60.522758 33.739151 60.50526 33.81332 60.55415 33.999149 60.52137 34.150822 60.513599 34.313599 60.67165 34.31638 60.911091 34.345821 60.89777 34.483318 60.756649 34.54166 60.733601 34.576389 60.863602 34.812759 61.065262 35.201649 61.11388 35.279148 61.104431 35.29694 61.1861 35.481091 61.239151 35.52026 61.27776 35.60675 61.278721 35.639709 61.365822 35.52721 61.464989 35.450821 61.576649 35.411091 61.802479 35.45998 61.97221 35.394711 62.100819 35.297771 62.259159 35.145538 62.305538 35.286381 62.459431 35.224979 62.62331 35.481369 63.110538 35.626091 63.095261 35.69553 63.23888 35.825821 63.10416 35.861931 63.119431 35.852211 63.317211 35.90971 63.538879 35.9622 63.595539 36.03915 63.933868 36.000271 64.063858 36.088039 64.059692 36.167488 64.169418 36.15192 64.282471 36.216381 64.32164 36.247211 64.458862 36.35638 64.570534 36.45998 64.627747 36.629429 64.61525 36.923038 64.795242 37.095821 64.779137 37.124981 64.798019 37.244431 65.072746 37.2486 65.530807 37.333199 65.627296</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></tows:geom>
+   </tows:world>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/input/wfs10_describe.txt b/demo/tests/input/wfs10_describe.txt
new file mode 100644
index 0000000..c10c653
--- /dev/null
+++ b/demo/tests/input/wfs10_describe.txt
@@ -0,0 +1 @@
+service=WFS&version=1.0.0&request=DescribeFeatureType
diff --git a/demo/tests/input/wfs10_getcaps.txt b/demo/tests/input/wfs10_getcaps.txt
new file mode 100644
index 0000000..9a2be12
--- /dev/null
+++ b/demo/tests/input/wfs10_getcaps.txt
@@ -0,0 +1 @@
+service=WFS&version=1.0.0&request=GetCapabilities
diff --git a/demo/tests/input/wfs10_getfeatures_france_onefeature.txt b/demo/tests/input/wfs10_getfeatures_france_onefeature.txt
new file mode 100644
index 0000000..03a729b
--- /dev/null
+++ b/demo/tests/input/wfs10_getfeatures_france_onefeature.txt
@@ -0,0 +1 @@
+service=WFS&version=1.0.0&request=GetFeature&typename=tows:france&maxfeatures=1
diff --git a/demo/tests/input/wfs10_getfeatures_world_onefeature.txt b/demo/tests/input/wfs10_getfeatures_world_onefeature.txt
new file mode 100644
index 0000000..52656eb
--- /dev/null
+++ b/demo/tests/input/wfs10_getfeatures_world_onefeature.txt
@@ -0,0 +1 @@
+service=WFS&version=1.0.0&request=GetFeature&typename=tows:world&maxfeatures=1
diff --git a/demo/tests/input/wfs11_describe.txt b/demo/tests/input/wfs11_describe.txt
new file mode 100644
index 0000000..0413e48
--- /dev/null
+++ b/demo/tests/input/wfs11_describe.txt
@@ -0,0 +1 @@
+service=WFS&version=1.1.0&request=DescribeFeatureType
diff --git a/demo/tests/input/wfs11_getcaps.txt b/demo/tests/input/wfs11_getcaps.txt
new file mode 100644
index 0000000..84710b6
--- /dev/null
+++ b/demo/tests/input/wfs11_getcaps.txt
@@ -0,0 +1 @@
+service=WFS&version=1.1.0&request=GetCapabilities
diff --git a/demo/tests/input/wfs11_getfeatures_france_onefeature.txt b/demo/tests/input/wfs11_getfeatures_france_onefeature.txt
new file mode 100644
index 0000000..660f741
--- /dev/null
+++ b/demo/tests/input/wfs11_getfeatures_france_onefeature.txt
@@ -0,0 +1 @@
+service=WFS&version=1.1.0&request=GetFeature&typename=tows:france&maxfeatures=1
diff --git a/demo/tests/input/wfs11_getfeatures_world_onefeature.txt b/demo/tests/input/wfs11_getfeatures_world_onefeature.txt
new file mode 100644
index 0000000..df4c90a
--- /dev/null
+++ b/demo/tests/input/wfs11_getfeatures_world_onefeature.txt
@@ -0,0 +1 @@
+service=WFS&version=1.1.0&request=GetFeature&typename=tows:world&maxfeatures=1

From 3f1fee7b912531ca50eb50edbdba460c8a4d8289 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Fri, 27 Nov 2020 00:52:19 +0100
Subject: [PATCH 26/30] Rework SRS axis order handling, and in particular avoid
 GetFeature WFS 1.1 to wrongly invert axis order for Easting,Northing
 projected CRS

---
 .../wfs11_getfeatures_france_onefeature.txt   |   2 +-
 src/fe/fe_spatial_ops.c                       |   2 +-
 src/ows/ows_bbox.c                            |  31 ++--
 src/ows/ows_geobbox.c                         |   2 +-
 src/ows/ows_srs.c                             | 146 +++++++++++-------
 src/ows/ows_storage.c                         |   8 +-
 src/ows_api.h                                 |   2 +-
 src/ows_struct.h                              |  25 ++-
 src/wfs/wfs_get_feature.c                     |  24 +--
 src/wfs/wfs_request.c                         |  25 ++-
 10 files changed, 163 insertions(+), 104 deletions(-)

diff --git a/demo/tests/expected/wfs11_getfeatures_france_onefeature.txt b/demo/tests/expected/wfs11_getfeatures_france_onefeature.txt
index 2b3c20d..cf71a6b 100644
--- a/demo/tests/expected/wfs11_getfeatures_france_onefeature.txt
+++ b/demo/tests/expected/wfs11_getfeatures_france_onefeature.txt
@@ -29,7 +29,7 @@ Content-Type: text/xml; subtype=gml/3.1.1
    <tows:code_reg>82</tows:code_reg>
    <tows:nom_region>RHONE-ALPES</tows:nom_region>
    <tows:code_dept>01</tows:code_dept>
-   <tows:geom><gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::27582"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>2092615 801150 2093190 800669 2095430 800688 2095795 800780 2096112 800589 2097190 800333 2098505 799095 2098838 799136 2100360 799690 2100395 799329 2100950 797715 2101330 797655 2102850 797410 2102788 797149 2102425 796755 2102785 796738 2103487 796612 2103892 795234 2104515 794905 2104359 794547 2102570 791555 2102760 791465 2104075 791935 2105023 791835 2105295 791670 2105555 790205 2105875 790035 2107116 789304 2107148 788617 2106760 788005 2106708 787670 2106990 786705 2107029 786350 2107335 785720 2108399 785562 2109486 786670 2109775 786930 2110010 787055 2110344 787208 2111056 787367 2113550 786900 2114260 786795 2114370 786830 2114751 786811 2116197 786384 2116940 786550 2117563 786560 2117860 786465 2119206 785956 2120474 787211 2120775 787415 2121475 787600 2121809 787536 2122743 787137 2123110 786610 2124100 786457 2124890 787138 2125160 787365 2125377 787545 2125830 787880 2126745 788198 2127075 788225 2128290 789130 2128585 789370 2129209 789790 2129525 789995 2131460 790445 2131793 790237 2132230 789585 2132742 788993 2133100 788830 2133655 788650 2134028 788638 2135142 788673 2136382 789501 2137110 789510 2138174 789596 2138520 789680 2139015 789845 2139590 790050 2140547 790594 2142011 790750 2142380 790740 2142716 790739 2143599 791139 2144456 791749 2144790 791860 2147049 792199 2147420 792285 2148815 792880 2150425 793615 2150782 793737 2152285 793650 2152660 793618 2153400 793480 2155103 794012 2155696 794347 2155980 794535 2156241 794686 2157025 795135 2159030 796115 2160314 796193 2160635 796250 2161408 796311 2161795 796335 2162102 796324 2163021 796316 2163470 796385 2163785 796495 2165380 797830 2165700 797970 2167362 797959 2167695 797910 2167835 797905 2169845 798850 2170117 798930 2170395 798980 2171035 799122 2171335 799255 2171435 799340 2171593 800295 2170924 800326 2170498 800757 2170754 801505 2171611 802043 2171760 802820 2171217 804846 2171380 805165 2170485 805338 2170210 805485 2168729 808352 2168520 808655 2168719 809605 2168735 809930 2170150 811710 2169640 813076 2170568 814292 2170640 814670 2171442 815189 2171075 816978 2172530 817045 2171719 818290 2171534 819798 2171205 819990 2170948 819753 2169812 820496 2169145 820305 2168648 820810 2167568 821023 2167190 821020 2167185 821753 2166355 822453 2166075 822690 2166394 823263 2166285 823585 2165476 824250 2165330 825284 2165160 825600 2165065 828440 2163119 829372 2162490 828470 2161655 828705 2161531 828395 2161519 827745 2161005 828485 2159908 830445 2159915 831525 2158958 832747 2158780 833030 2158494 833286 2158105 833885 2157807 833687 2157040 832940 2156696 832830 2155806 833866 2155445 833825 2155097 833752 2154750 833675 2153047 835995 2152675 835930 2151171 836194 2150780 836185 2150680 836190 2150149 836405 2150070 836690 2153840 837059 2154400 837545 2151187 838628 2150820 838735 2151192 840056 2151708 840530 2151840 840855 2151081 841371 2150965 841670 2150606 841591 2148479 841093 2148155 840525 2146631 840483 2145603 841576 2145394 841898 2145800 843750 2146033 843973 2145523 844372 2145410 844675 2146002 846805 2147688 848292 2148035 848440 2148733 848651 2148841 850029 2148775 850390 2149407 851184 2150710 851650 2150922 851857 2151180 851710 2152638 852195 2153465 853883 2153815 854050 2154550 854684 2153948 854950 2153605 855010 2152546 854706 2152522 856495 2151954 857425 2151680 857675 2151135 857795 2150917 860115 2149401 860522 2147845 860356 2145955 860868 2145690 861160 2145842 861499 2146060 861800 2146529 863931 2146675 864270 2146311 867954 2146245 868320 2146162 868625 2146145 868940 2146227 870819 2147047 871569 2147009 872099 2146655 872230 2148801 873891 2149145 874080 2148900 875215 2149908 875688 2151749 875836 2152270 876350 2151866 877249 2151825 877575 2152160 877751 2156500 879950 2157904 880577 2159490 882757 2160898 884049 2163565 885600 2164270 886165 2164140 886435 2163415 889069 2162493 889778 2162099 890867 2160395 893000 2160083 894101 2159465 894575 2158743 894622 2156340 893375 2155944 892712 2155185 892540 2153375 891600 2152677 891281 2152295 891245 2150917 891340 2149984 890292 2149695 890080 2147869 890987 2147615 891235 2147405 891560 2146272 891794 2145258 891337 2144570 890413 2145445 889185 2145356 888822 2144792 887853 2145110 887180 2143618 886092 2143730 885735 2143963 885432 2143997 884760 2143495 883760 2143280 883455 2142419 882749 2142149 882058 2141782 881989 2141448 880591 2140052 880422 2139555 879890 2139435 879855 2138192 882197 2137078 882019 2136753 881408 2134940 880810 2133632 880202 2132631 880177 2132205 879600 2132001 879351 2131755 878142 2131650 877449 2131962 876853 2130970 875845 2130628 875089 2130520 874800 2129464 874322 2128114 874925 2126982 874725 2126720 872900 2126810 872100 2127080 871837 2128513 870648 2128829 869972 2128495 869296 2127050 869435 2125650 868710 2125275 868663 2123780 868525 2123569 868760 2123070 868985 2121885 868525 2121591 868617 2120685 868760 2120349 868864 2119679 869034 2118760 868545 2118458 868661 2117935 868975 2117610 868911 2116295 869020 2115554 869215 2114005 870970 2113621 870979 2112855 870925 2111817 871130 2110485 870721 2110250 870455 2110165 870800 2109573 870344 2108843 870311 2107500 870897 2106390 870710 2106018 870615 2103410 869975 2101545 869465 2101232 869314 2099875 869040 2099512 868989 2098080 868710 2097320 868050 2096964 867940 2094425 867995 2094056 867975 2092595 867825 2092277 867736 2091670 867995 2091277 867979 2090131 867788 2088645 868170 2088380 867935 2088330 867643 2088110 867110 2087753 867246 2086334 867588 2085607 866723 2084278 866013 2084187 865294 2084575 864275 2084465 864000 2084328 863659 2084450 861885 2084109 861845 2083150 862185 2082820 862398 2082092 862694 2081333 862533 2079632 860925 2078870 860842 2078155 861160 2077808 861300 2077080 861210 2076787 860973 2076386 860337 2076155 858511 2075110 858205 2074811 858072 2074591 857453 2073960 857320 2073584 857265 2073221 856650 2073460 856355 2073797 856182 2074780 855610 2075941 854744 2077758 854474 2078730 852864 2079020 852620 2079386 852647 2079920 851685 2080021 851354 2079717 850753 2079917 850470 2080840 850320 2081131 850069 2082613 850023 2082507 850741 2081230 851509 2081554 852157 2082291 852073 2083206 850451 2083940 850375 2084174 850111 2084350 849805 2084500 848375 2084810 848150 2086215 847545 2086449 847281 2087620 845980 2087856 845694 2088564 844840 2091270 842895 2091898 842098 2092105 841825 2092424 841604 2093065 841170 2093318 840895 2094355 839825 2096198 839769 2096536 840798 2096910 840745 2097185 840580 2097470 840305 2098117 839320 2098880 839165 2099191 839016 2099825 838200 2100899 836342 2101165 836100 2101453 835840 2102554 834252 2102260 833175 2102031 833017 2101525 832785 2101162 832719 2100482 832433 2099710 831189 2098550 830330 2095140 829565 2094745 829550 2094389 829422 2093577 828638 2091920 827810 2091724 827523 2091325 826955 2091135 826653 2090510 825785 2090257 825487 2089517 824587 2089735 822700 2089692 822339 2090044 821748 2090765 821660 2091109 821459 2092110 820815 2092273 820470 2093148 819281 2093260 818215 2093406 817851 2093980 816405 2093715 815735 2092629 815844 2092497 815501 2094120 814830 2094025 814502 2093925 814175 2093907 813785 2093620 811510 2093793 811202 2093796 810503 2093390 809935 2093210 808612 2093030 808305 2092976 807965 2093490 807085 2093370 806759 2093210 806450 2092960 805480 2093105 804700 2093280 804426 2093210 803230 2093269 802864 2092615 801150</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></tows:geom>
+   <tows:geom><gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::27582"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>801150 2092615 800669 2093190 800688 2095430 800780 2095795 800589 2096112 800333 2097190 799095 2098505 799136 2098838 799690 2100360 799329 2100395 797715 2100950 797655 2101330 797410 2102850 797149 2102788 796755 2102425 796738 2102785 796612 2103487 795234 2103892 794905 2104515 794547 2104359 791555 2102570 791465 2102760 791935 2104075 791835 2105023 791670 2105295 790205 2105555 790035 2105875 789304 2107116 788617 2107148 788005 2106760 787670 2106708 786705 2106990 786350 2107029 785720 2107335 785562 2108399 786670 2109486 786930 2109775 787055 2110010 787208 2110344 787367 2111056 786900 2113550 786795 2114260 786830 2114370 786811 2114751 786384 2116197 786550 2116940 786560 2117563 786465 2117860 785956 2119206 787211 2120474 787415 2120775 787600 2121475 787536 2121809 787137 2122743 786610 2123110 786457 2124100 787138 2124890 787365 2125160 787545 2125377 787880 2125830 788198 2126745 788225 2127075 789130 2128290 789370 2128585 789790 2129209 789995 2129525 790445 2131460 790237 2131793 789585 2132230 788993 2132742 788830 2133100 788650 2133655 788638 2134028 788673 2135142 789501 2136382 789510 2137110 789596 2138174 789680 2138520 789845 2139015 790050 2139590 790594 2140547 790750 2142011 790740 2142380 790739 2142716 791139 2143599 791749 2144456 791860 2144790 792199 2147049 792285 2147420 792880 2148815 793615 2150425 793737 2150782 793650 2152285 793618 2152660 793480 2153400 794012 2155103 794347 2155696 794535 2155980 794686 2156241 795135 2157025 796115 2159030 796193 2160314 796250 2160635 796311 2161408 796335 2161795 796324 2162102 796316 2163021 796385 2163470 796495 2163785 797830 2165380 797970 2165700 797959 2167362 797910 2167695 797905 2167835 798850 2169845 798930 2170117 798980 2170395 799122 2171035 799255 2171335 799340 2171435 800295 2171593 800326 2170924 800757 2170498 801505 2170754 802043 2171611 802820 2171760 804846 2171217 805165 2171380 805338 2170485 805485 2170210 808352 2168729 808655 2168520 809605 2168719 809930 2168735 811710 2170150 813076 2169640 814292 2170568 814670 2170640 815189 2171442 816978 2171075 817045 2172530 818290 2171719 819798 2171534 819990 2171205 819753 2170948 820496 2169812 820305 2169145 820810 2168648 821023 2167568 821020 2167190 821753 2167185 822453 2166355 822690 2166075 823263 2166394 823585 2166285 824250 2165476 825284 2165330 825600 2165160 828440 2165065 829372 2163119 828470 2162490 828705 2161655 828395 2161531 827745 2161519 828485 2161005 830445 2159908 831525 2159915 832747 2158958 833030 2158780 833286 2158494 833885 2158105 833687 2157807 832940 2157040 832830 2156696 833866 2155806 833825 2155445 833752 2155097 833675 2154750 835995 2153047 835930 2152675 836194 2151171 836185 2150780 836190 2150680 836405 2150149 836690 2150070 837059 2153840 837545 2154400 838628 2151187 838735 2150820 840056 2151192 840530 2151708 840855 2151840 841371 2151081 841670 2150965 841591 2150606 841093 2148479 840525 2148155 840483 2146631 841576 2145603 841898 2145394 843750 2145800 843973 2146033 844372 2145523 844675 2145410 846805 2146002 848292 2147688 848440 2148035 848651 2148733 850029 2148841 850390 2148775 851184 2149407 851650 2150710 851857 2150922 851710 2151180 852195 2152638 853883 2153465 854050 2153815 854684 2154550 854950 2153948 855010 2153605 854706 2152546 856495 2152522 857425 2151954 857675 2151680 857795 2151135 860115 2150917 860522 2149401 860356 2147845 860868 2145955 861160 2145690 861499 2145842 861800 2146060 863931 2146529 864270 2146675 867954 2146311 868320 2146245 868625 2146162 868940 2146145 870819 2146227 871569 2147047 872099 2147009 872230 2146655 873891 2148801 874080 2149145 875215 2148900 875688 2149908 875836 2151749 876350 2152270 877249 2151866 877575 2151825 877751 2152160 879950 2156500 880577 2157904 882757 2159490 884049 2160898 885600 2163565 886165 2164270 886435 2164140 889069 2163415 889778 2162493 890867 2162099 893000 2160395 894101 2160083 894575 2159465 894622 2158743 893375 2156340 892712 2155944 892540 2155185 891600 2153375 891281 2152677 891245 2152295 891340 2150917 890292 2149984 890080 2149695 890987 2147869 891235 2147615 891560 2147405 891794 2146272 891337 2145258 890413 2144570 889185 2145445 888822 2145356 887853 2144792 887180 2145110 886092 2143618 885735 2143730 885432 2143963 884760 2143997 883760 2143495 883455 2143280 882749 2142419 882058 2142149 881989 2141782 880591 2141448 880422 2140052 879890 2139555 879855 2139435 882197 2138192 882019 2137078 881408 2136753 880810 2134940 880202 2133632 880177 2132631 879600 2132205 879351 2132001 878142 2131755 877449 2131650 876853 2131962 875845 2130970 875089 2130628 874800 2130520 874322 2129464 874925 2128114 874725 2126982 872900 2126720 872100 2126810 871837 2127080 870648 2128513 869972 2128829 869296 2128495 869435 2127050 868710 2125650 868663 2125275 868525 2123780 868760 2123569 868985 2123070 868525 2121885 868617 2121591 868760 2120685 868864 2120349 869034 2119679 868545 2118760 868661 2118458 868975 2117935 868911 2117610 869020 2116295 869215 2115554 870970 2114005 870979 2113621 870925 2112855 871130 2111817 870721 2110485 870455 2110250 870800 2110165 870344 2109573 870311 2108843 870897 2107500 870710 2106390 870615 2106018 869975 2103410 869465 2101545 869314 2101232 869040 2099875 868989 2099512 868710 2098080 868050 2097320 867940 2096964 867995 2094425 867975 2094056 867825 2092595 867736 2092277 867995 2091670 867979 2091277 867788 2090131 868170 2088645 867935 2088380 867643 2088330 867110 2088110 867246 2087753 867588 2086334 866723 2085607 866013 2084278 865294 2084187 864275 2084575 864000 2084465 863659 2084328 861885 2084450 861845 2084109 862185 2083150 862398 2082820 862694 2082092 862533 2081333 860925 2079632 860842 2078870 861160 2078155 861300 2077808 861210 2077080 860973 2076787 860337 2076386 858511 2076155 858205 2075110 858072 2074811 857453 2074591 857320 2073960 857265 2073584 856650 2073221 856355 2073460 856182 2073797 855610 2074780 854744 2075941 854474 2077758 852864 2078730 852620 2079020 852647 2079386 851685 2079920 851354 2080021 850753 2079717 850470 2079917 850320 2080840 850069 2081131 850023 2082613 850741 2082507 851509 2081230 852157 2081554 852073 2082291 850451 2083206 850375 2083940 850111 2084174 849805 2084350 848375 2084500 848150 2084810 847545 2086215 847281 2086449 845980 2087620 845694 2087856 844840 2088564 842895 2091270 842098 2091898 841825 2092105 841604 2092424 841170 2093065 840895 2093318 839825 2094355 839769 2096198 840798 2096536 840745 2096910 840580 2097185 840305 2097470 839320 2098117 839165 2098880 839016 2099191 838200 2099825 836342 2100899 836100 2101165 835840 2101453 834252 2102554 833175 2102260 833017 2102031 832785 2101525 832719 2101162 832433 2100482 831189 2099710 830330 2098550 829565 2095140 829550 2094745 829422 2094389 828638 2093577 827810 2091920 827523 2091724 826955 2091325 826653 2091135 825785 2090510 825487 2090257 824587 2089517 822700 2089735 822339 2089692 821748 2090044 821660 2090765 821459 2091109 820815 2092110 820470 2092273 819281 2093148 818215 2093260 817851 2093406 816405 2093980 815735 2093715 815844 2092629 815501 2092497 814830 2094120 814502 2094025 814175 2093925 813785 2093907 811510 2093620 811202 2093793 810503 2093796 809935 2093390 808612 2093210 808305 2093030 807965 2092976 807085 2093490 806759 2093370 806450 2093210 805480 2092960 804700 2093105 804426 2093280 803230 2093210 802864 2093269 801150 2092615</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></tows:geom>
    </tows:france>
   </gml:featureMember>
 </wfs:FeatureCollection>
diff --git a/src/fe/fe_spatial_ops.c b/src/fe/fe_spatial_ops.c
index e8b1ab9..6e4f10b 100644
--- a/src/fe/fe_spatial_ops.c
+++ b/src/fe/fe_spatial_ops.c
@@ -187,7 +187,7 @@ buffer *fe_envelope(ows * o, buffer * typename, filter_encoding * fe, buffer *en
 
   /* return the polygon's coordinates matching the bbox */
   bbox = ows_bbox_init();
-  if (s && s->is_reverse_axis) {
+  if (s && s->honours_authority_axis_order && !s->is_axis_order_gis_friendly) {
     ret = ows_bbox_set(o, bbox,
                        atof(coord_min->first->next->value->buf),
                        atof(coord_min->first->value->buf),
diff --git a/src/ows/ows_bbox.c b/src/ows/ows_bbox.c
index a009063..70a8bf9 100644
--- a/src/ows/ows_bbox.c
+++ b/src/ows/ows_bbox.c
@@ -93,14 +93,13 @@ bool ows_bbox_set(ows * o, ows_bbox * b, double xmin, double ymin, double xmax,
 /*
  * Set a given bbox from a string like 'xmin,ymin,xmax,ymax'
  */
-bool ows_bbox_set_from_str(ows * o, ows_bbox * bb, const char *str, int srid)
+bool ows_bbox_set_from_str(ows * o, ows_bbox * bb, const char *str, int srid,
+                           bool honours_authority_axis_order_if_no_explicit_srs)
 {
   double xmin, ymin, xmax, ymax;
-  ows_srs *s;
   buffer *b;
   list *l;
-  int srs = srid;
-  bool ret_srs = true;
+  bool ret;
 
   assert(o && bb && str);
 
@@ -123,16 +122,26 @@ bool ows_bbox_set_from_str(ows * o, ows_bbox * bb, const char *str, int srid)
 
   /* srs is optional since WFS 1.1 */
   if (l->size == 5) {
-    s = ows_srs_init();
-    ret_srs = ows_srs_set_from_srsname(o, s, l->last->value->buf);
-    srs = s->srid;
-    ows_srs_free(s);
+    ows_srs* s = ows_srs_init();
+    ret = ows_srs_set_from_srsname(o, s, l->last->value->buf);
+    if (ret)
+    {
+      srid = s->srid;
+      ret = ows_bbox_set(o, bb, xmin, ymin, xmax, ymax, srid);
+      ows_srs_free(bb->srs);
+      bb->srs = s;
+    } else {
+      ows_srs_free(s);
+    }
+
+  } else {
+    ret = ows_bbox_set(o, bb, xmin, ymin, xmax, ymax, srid);
+    bb->srs->honours_authority_axis_order = honours_authority_axis_order_if_no_explicit_srs;
   }
 
   list_free(l);
-  if(!ret_srs) return false;
 
-  return ows_bbox_set(o, bb, xmin, ymin, xmax, ymax, srs);
+  return ret;
 }
 
 
@@ -279,7 +288,7 @@ void ows_bbox_to_query(ows *o, ows_bbox *bbox, buffer *query)
 
   assert(o && bbox && query);
 
-  if (bbox->srs->is_reverse_axis) {
+  if (bbox->srs->honours_authority_axis_order && !bbox->srs->is_axis_order_gis_friendly) {
     x1 = bbox->ymin;
     y1 = bbox->xmin;
     x2 = bbox->ymax;
diff --git a/src/ows/ows_geobbox.c b/src/ows/ows_geobbox.c
index fe4e7b5..6e0619c 100644
--- a/src/ows/ows_geobbox.c
+++ b/src/ows/ows_geobbox.c
@@ -139,7 +139,7 @@ ows_geobbox *ows_geobbox_set_from_str(ows * o, ows_geobbox * g, char *str)
   assert(str);
 
   bb = ows_bbox_init();
-  ows_bbox_set_from_str(o, bb, str, 4326);
+  ows_bbox_set_from_str(o, bb, str, 4326, false);
   ows_geobbox_set_from_bbox(o, g, bb);
   ows_bbox_free(bb);
 
diff --git a/src/ows/ows_srs.c b/src/ows/ows_srs.c
index 94410d2..6daea4c 100644
--- a/src/ows/ows_srs.c
+++ b/src/ows/ows_srs.c
@@ -44,9 +44,9 @@ ows_srs *ows_srs_init()
   c->srid = -1;
   c->auth_name = buffer_init();
   c->auth_srid = 0;
-  c->is_degree = true;
-  c->is_reverse_axis = false;
-  c->is_eastern_axis = false;
+  c->is_geographic = true;
+  c->honours_authority_axis_order = false;
+  c->is_axis_order_gis_friendly = false;
   c->is_long = false;
 
   return c;
@@ -61,9 +61,9 @@ ows_srs *ows_srs_copy(ows_srs * d, ows_srs * s)
   d->srid = s->srid;
   buffer_copy(d->auth_name, s->auth_name);
   d->auth_srid = s->auth_srid;
-  d->is_degree = s->is_degree;
-  d->is_reverse_axis = s->is_reverse_axis;
-  d->is_eastern_axis = s->is_eastern_axis;
+  d->is_geographic = s->is_geographic;
+  d->honours_authority_axis_order = s->honours_authority_axis_order;
+  d->is_axis_order_gis_friendly = s->is_axis_order_gis_friendly;
   d->is_long = s->is_long;
 
   return d;
@@ -98,18 +98,20 @@ void ows_srs_flush(ows_srs * c, FILE * output)
   fprintf(output, " auth_name: %s\n", c->auth_name->buf);
   fprintf(output, " auth_srid: %i\n", c->auth_srid);
 
-  if (c->is_degree) fprintf(output, " is_degree: true\n]\n");
-  else              fprintf(output, " is_degree: false\n]\n");
+  if (c->is_geographic)
+    fprintf(output, " is_geographic: true\n]\n");
+  else
+    fprintf(output, " is_geographic: false\n]\n");
 
-  if (c->is_reverse_axis)
-    fprintf(output, " is_reverse_axis: true\n]\n");
+  if (c->honours_authority_axis_order)
+    fprintf(output, " honours_authority_axis_order: true\n]\n");
   else
-    fprintf(output, " is_reverse_axis: false\n]\n");
+    fprintf(output, " honours_authority_axis_order: false\n]\n");
 
-  if (c->is_eastern_axis)
-    fprintf(output, " is_eastern_axis: true\n]\n");
+  if (c->is_axis_order_gis_friendly)
+    fprintf(output, " is_axis_order_gis_friendly: true\n]\n");
   else
-    fprintf(output, " is_eastern_axis: false\n]\n");
+    fprintf(output, " is_axis_order_gis_friendly: false\n]\n");
 
   if (c->is_long)
     fprintf(output, " is_long: true\n]\n");
@@ -118,24 +120,71 @@ void ows_srs_flush(ows_srs * c, FILE * output)
 }
 #endif
 
+/*
+ * Set s->is_geographic and s->is_axis_order_gis_friendly
+ * from srtext.
+ */
+static void ows_srs_set_is_geographic_and_is_axis_order_gis_friendly_from_def(
+        ows_srs* s, const char* proj4text, const char* srtext)
+{
+    /* Use srtext in priority */
+    if (srtext && srtext[0] != '\0')
+    {
+        char* srtext_horizontal = (char*) malloc(strlen(srtext) + 1);
+        char* ptr;
+        strcpy(srtext_horizontal, srtext);
+
+        /* Remove the VERT_CS part if we are in a COMPD_CS */
+        ptr = strstr(srtext_horizontal, ",VERT_CS[");
+        if (ptr)
+            *ptr = '\0';
+
+        s->is_axis_order_gis_friendly = true;
+        s->is_geographic = strstr(srtext, "PROJCS[") == NULL &&
+                           strstr(srtext, "GEOCCS[") == NULL;
+
+        if( strstr(srtext_horizontal, "AXIS[") == NULL )
+        {
+            /* If there is no axis definition, then due to how GDAL < 3
+             * generated the WKT, this means that the axis order is not
+             * GIS friendly */
+            s->is_axis_order_gis_friendly = false;
+        }
+        /* In case PostGIS incorporates full WKT output some day... */
+        else if( strstr(srtext_horizontal,
+                   "AXIS[\"Northing\",NORTH],AXIS[\"Easting\",EAST]") != NULL )
+        {
+            s->is_axis_order_gis_friendly = false;
+        }
+
+        free(srtext_horizontal);
+    }
+    else if( proj4text && proj4text[0] != '\0' )
+    {
+        s->is_geographic = strstr(proj4text, "+units=m") == NULL;
+        /* This will be wrong for a number of projected CRS ! */
+        s->is_axis_order_gis_friendly = !s->is_geographic;
+    }
+}
 
 /*
  * Set projection value into srs structure
  */
-bool ows_srs_set(ows * o, ows_srs * c, const buffer * auth_name, int auth_srid)
+bool ows_srs_set(ows * o, ows_srs * s, const buffer * auth_name, int auth_srid)
 {
   PGresult *res;
   buffer *sql;
+  const char* proj4text;
+  const char* srtext;
 
   assert(o);
-  assert(c);
+  assert(s);
   assert(o->pg);
   assert(auth_name);
 
   sql = buffer_init();
-  buffer_add_str(sql, "SELECT srid, position('+units=m ' in proj4text)");
-  buffer_add_str(sql, ", (position('AXIS[\"X\",NORTH]]' in srtext) + position('AXIS[\"Northing\",NORTH]]' in srtext))");
-  buffer_add_str(sql, " FROM spatial_ref_sys WHERE auth_name='");
+  buffer_add_str(sql, "SELECT srid, proj4text, srtext "
+                      "FROM spatial_ref_sys WHERE auth_name='");
   buffer_copy(sql, auth_name);
   buffer_add_str(sql, "' AND auth_srid=");
   buffer_add_int(sql, auth_srid);
@@ -149,21 +198,15 @@ bool ows_srs_set(ows * o, ows_srs * c, const buffer * auth_name, int auth_srid)
     return false;
   }
 
-  buffer_empty(c->auth_name);
-  buffer_copy(c->auth_name, auth_name);
-  c->auth_srid = auth_srid;
-
-  c->srid = atoi(PQgetvalue(res, 0, 0));
+  buffer_empty(s->auth_name);
+  buffer_copy(s->auth_name, auth_name);
+  s->auth_srid = auth_srid;
 
-  /* Such a way to know if units is meter or degree */
-  if (atoi(PQgetvalue(res, 0, 1)) == 0)
-    c->is_degree = true;
-  else
-    c->is_degree = false;
+  s->srid = atoi(PQgetvalue(res, 0, 0));
 
-  /* Is easting-northing SRID ? */
-  if (atoi(PQgetvalue(res, 0, 2)) != 0)
-    c->is_eastern_axis = true;
+  proj4text = PQgetvalue(res, 0, 1);
+  srtext = PQgetvalue(res, 0, 2);
+  ows_srs_set_is_geographic_and_is_axis_order_gis_friendly_from_def(s, proj4text, srtext);
 
   PQclear(res);
   return true;
@@ -183,9 +226,8 @@ bool ows_srs_set_geobbox(ows * o, ows_srs * s)
   buffer_empty(s->auth_name);
   buffer_add_str(s->auth_name, "EPSG");
   s->auth_srid = 4326;
-  s->is_degree = true;
-  s->is_reverse_axis = false;
-  s->is_eastern_axis = false;
+  s->is_geographic = true;
+  s->is_axis_order_gis_friendly = false;
 
   return true;
 }
@@ -198,6 +240,8 @@ bool ows_srs_set_from_srid(ows * o, ows_srs * s, int srid)
 {
   PGresult *res;
   buffer *sql;
+  const char *proj4text;
+  const char *srtext;
 
   assert(o);
   assert(s);
@@ -206,18 +250,16 @@ bool ows_srs_set_from_srid(ows * o, ows_srs * s, int srid)
     s->srid = -1;
     buffer_empty(s->auth_name);
     s->auth_srid = 0;
-    s->is_degree = true;
-    s->is_reverse_axis = false;
-    s->is_eastern_axis = false;
+    s->is_geographic = true;
+    s->honours_authority_axis_order = false;
+    s->is_axis_order_gis_friendly = false;
 
     return true;
   }
 
   sql = buffer_init();
-  buffer_add_str(sql, "SELECT auth_name, auth_srid, ");
-  buffer_add_str(sql, "position('+units=m ' in proj4text), ");
-  buffer_add_str(sql, "(position('AXIS[\"X\",NORTH]]' in srtext) + position('AXIS[\"Northing\",NORTH]]' in srtext)) ");
-  buffer_add_str(sql, "FROM spatial_ref_sys WHERE srid = '");
+  buffer_add_str(sql, "SELECT auth_name, auth_srid, proj4text, srtext "
+                      "FROM spatial_ref_sys WHERE srid = '");
   buffer_add_int(sql, srid);
   buffer_add_str(sql, "'");
 
@@ -234,15 +276,9 @@ bool ows_srs_set_from_srid(ows * o, ows_srs * s, int srid)
   s->auth_srid = atoi(PQgetvalue(res, 0, 1));
   s->srid = srid;
 
-  /* Such a way to know if units is meter or degree */
-  if (atoi(PQgetvalue(res, 0, 2)) == 0)
-    s->is_degree = true;
-  else
-    s->is_degree = false;
-
-  /* Is easting-northing SRID ? */
-  if (atoi(PQgetvalue(res, 0, 3)) != 0)
-    s->is_eastern_axis = true;
+  proj4text = PQgetvalue(res, 0, 2);
+  srtext = PQgetvalue(res, 0, 3);
+  ows_srs_set_is_geographic_and_is_axis_order_gis_friendly_from_def(s, proj4text, srtext);
 
   PQclear(res);
   return true;
@@ -283,18 +319,18 @@ bool ows_srs_set_from_srsname(ows * o, ows_srs * s, const char *srsname)
   if    (!strncmp((char *) srsname,        "EPSG:", 5)
          || !strncmp((char *) srsname, "spatialreferencing.org", 22)) {
     sep = ':';
-    s->is_reverse_axis = false;
+    s->honours_authority_axis_order = false;
     s->is_long = false;
 
   } else if (!strncmp((char *) srsname, "urn:ogc:def:crs:EPSG:", 21)
              || !strncmp((char *) srsname, "urn:x-ogc:def:crs:EPSG:", 23)
              || !strncmp((char *) srsname, "urn:EPSG:geographicCRS:", 23)) {
     sep = ':';
-    s->is_reverse_axis = true;
+    s->honours_authority_axis_order = true;
 
   } else if (!strncmp((char *) srsname, "http://www.opengis.net/gml/srs/epsg.xml#", 40)) {
     sep = '#';
-    s->is_reverse_axis = false;
+    s->honours_authority_axis_order = false;
   } else return false; /* FIXME must we really not allow other value ? */
 
   /*  Retrieve from last separator to the end of srsName string */
@@ -319,7 +355,7 @@ bool ows_srs_meter_units(ows * o, buffer * layer_name)
 
   for (ln = o->layers->first ; ln ; ln = ln->next)
     if (ln->layer->name && ln->layer->storage && !strcmp(ln->layer->name->buf, layer_name->buf))
-      return !ln->layer->storage->is_degree;
+      return !ln->layer->storage->is_geographic;
 
   assert(0); /* Should not happen */
   return false;
diff --git a/src/ows/ows_storage.c b/src/ows/ows_storage.c
index 5898645..17cacfb 100644
--- a/src/ows/ows_storage.c
+++ b/src/ows/ows_storage.c
@@ -39,7 +39,7 @@ ows_layer_storage * ows_layer_storage_init()
   storage->schema = buffer_init();
   storage->srid = -1;
   storage->geom_columns = list_init();
-  storage->is_degree = true;
+  storage->is_geographic = true;
   storage->table = buffer_init();
   storage->pkey = NULL;
   storage->pkey_sequence = NULL;
@@ -95,7 +95,7 @@ void ows_layer_storage_flush(ows_layer_storage * storage, FILE * output)
   }
 
   fprintf(output, "srid: %i\n", storage->srid);
-  fprintf(output, "is_degree: %i\n", storage->is_degree?1:0);
+  fprintf(output, "is_geographic: %i\n", storage->is_geographic?1:0);
 
   if (storage->pkey) {
     fprintf(output, "pkey: ");
@@ -461,9 +461,9 @@ static void ows_layer_storage_fill(ows * o, ows_layer * l, bool is_geom)
   buffer_free(sql);
 
   if (PQntuples(res) != 1)
-    l->storage->is_degree = true;
+    l->storage->is_geographic = true;
   else
-    l->storage->is_degree = false;
+    l->storage->is_geographic = false;
 
   PQclear(res);
 
diff --git a/src/ows_api.h b/src/ows_api.h
index 03ea267..f887844 100644
--- a/src/ows_api.h
+++ b/src/ows_api.h
@@ -123,7 +123,7 @@ void ows_bbox_free (ows_bbox * b);
 ows_bbox *ows_bbox_init ();
 bool ows_bbox_set (ows * o, ows_bbox * b, double xmin, double ymin, double xmax, double ymax, int srid);
 bool ows_bbox_set_from_geobbox (ows * o, ows_bbox * bb, ows_geobbox * geo);
-bool ows_bbox_set_from_str (ows * o, ows_bbox * bb, const char *str, int srid);
+bool ows_bbox_set_from_str (ows * o, ows_bbox * bb, const char *str, int srid, bool honours_authority_axis_order_if_no_explicit_srs);
 bool ows_bbox_transform (ows * o, ows_bbox * bb, int srid);
 void ows_bbox_to_query(ows * o, ows_bbox *bbox, buffer *query);
 void ows_contact_flush (ows_contact * contact, FILE * output);
diff --git a/src/ows_struct.h b/src/ows_struct.h
index 025c9a9..6b1d881 100644
--- a/src/ows_struct.h
+++ b/src/ows_struct.h
@@ -108,7 +108,9 @@ typedef struct Ows_layer_storage {
   buffer * pkey_sequence;
   buffer * pkey_default;
   int pkey_column_number;
-  bool is_degree;
+  bool is_geographic;    /* true for a geographic CRS (or a compound CRS
+                            whose base is geographic), false for a projected
+                            CRS (or a compound CRS whose base is projected) */
   array * attributes;
 } ows_layer_storage;
 
@@ -116,10 +118,23 @@ typedef struct Ows_srs {
   int srid;
   buffer * auth_name;
   int auth_srid;
-  bool is_degree;
-  bool is_reverse_axis;
-  bool is_eastern_axis;
-  bool is_long;
+  bool is_geographic;              /* true for a geographic CRS (or a compound
+                                      CRS whose base is geographic), false for
+                                      a projected CRS (or a compound CRS whose
+                                      base is projected) */
+  bool is_axis_order_gis_friendly;   /* true for a CRS whose axis order is
+                                        typically easting, northing (e.g most
+                                        projected CRS, such as EPSG:32631)
+                                        false for example for EPSG:4326 (WGS 84),
+                                        EPSG:2393 (KKJ / Finland Uniform Coordinate System) */
+
+  /* The two below fields are not properties of the SRS, but of its context
+   * of use. */
+  bool honours_authority_axis_order; /* true for a context where the axis order
+                                        as defined by the authority should be
+                                        respected */
+  bool is_long;                      /* true for a context where the srsname must
+                                        be exported as a long URN */
 } ows_srs;
 
 
diff --git a/src/wfs/wfs_get_feature.c b/src/wfs/wfs_get_feature.c
index 5d4078b..dcb1a0e 100644
--- a/src/wfs/wfs_get_feature.c
+++ b/src/wfs/wfs_get_feature.c
@@ -43,7 +43,7 @@ static void wfs_gml_bounded_by(ows * o, wfs_request * wr, double xmin, double ym
   assert(wr);
   assert(srs);
 
-  if (srs->is_degree) precision = o->degree_precision;
+  if (srs->is_geographic) precision = o->degree_precision;
   else precision = o->meter_precision;
 
   if (!srs->srid || srs->srid == -1 || (xmin == ymin && xmax == ymax && xmin == xmax)) {
@@ -76,7 +76,7 @@ static void wfs_gml_bounded_by(ows * o, wfs_request * wr, double xmin, double ym
       else fprintf(o->output, "EPSG:");
       fprintf(o->output, "%d\">", srs->srid);
 
-      if (srs->is_reverse_axis && !srs->is_eastern_axis && srs->is_long) {
+      if (srs->honours_authority_axis_order && !srs->is_axis_order_gis_friendly) {
         if (fabs(xmin) > OWS_MAX_DOUBLE || fabs(ymin) > OWS_MAX_DOUBLE ||
             fabs(xmax) > OWS_MAX_DOUBLE || fabs(ymax) > OWS_MAX_DOUBLE) {
           fprintf(o->output, "<gml:lowerCorner>%g %g</gml:lowerCorner>", ymin, xmin);
@@ -457,15 +457,18 @@ static buffer *wfs_retrieve_sql_request_select(ows * o, wfs_request * wr, buffer
           buffer_add_str(select, "\",");
         }
 
-        if ((wr->srs && !wr->srs->is_degree) ||
+        if ((wr->srs && !wr->srs->is_geographic) ||
             (!wr->srs && ows_srs_meter_units(o, layer_name)))
           buffer_add_int(select, o->meter_precision);
         else
           buffer_add_int(select, o->degree_precision);
 
                                                  gml_opt  = 0; /* Short SRS */
-        if (wr->srs && wr->srs->is_long)         gml_opt += 1; /* FIXME really ? */
-        if (wr->srs && wr->srs->is_eastern_axis) gml_opt += 16;
+        if (wr->srs && wr->srs->is_long)         gml_opt += 1;
+        /* This will be actually without effect since PostGIS only honours flag = 16 for GML 3 */
+        if (wr->srs &&
+            wr->srs->honours_authority_axis_order &&
+            !wr->srs->is_axis_order_gis_friendly ) gml_opt += 16;
         if (gml_boundedby)                       gml_opt += 32;
 
         buffer_add_str(select, ",");
@@ -496,13 +499,14 @@ static buffer *wfs_retrieve_sql_request_select(ows * o, wfs_request * wr, buffer
         if (wr->srs && wr->srs->is_long) gml_opt += 1; /* Long SRS */
         if (gml_boundedby) gml_opt += 32;
 
-        if ((wr->srs && !wr->srs->is_degree) || (!wr->srs && ows_srs_meter_units(o, layer_name))) {
+        if ((wr->srs && !wr->srs->is_geographic) || (!wr->srs && ows_srs_meter_units(o, layer_name))) {
           buffer_add_int(select, o->meter_precision);
-          if (wr->srs && !wr->srs->is_eastern_axis && wr->srs->is_long) gml_opt += 16;
         } else {
           buffer_add_int(select, o->degree_precision);
-          if (wr->srs && !wr->srs->is_eastern_axis && wr->srs->is_long) gml_opt += 16;
         }
+        if (wr->srs &&
+            wr->srs->honours_authority_axis_order &&
+            !wr->srs->is_axis_order_gis_friendly ) gml_opt += 16;
 
         buffer_add_str(select, ", ");
         buffer_add_int(select, gml_opt);
@@ -526,7 +530,7 @@ static buffer *wfs_retrieve_sql_request_select(ows * o, wfs_request * wr, buffer
           buffer_add_str(select, "\",");
         }
 
-        if ((wr->srs && !wr->srs->is_degree) ||
+        if ((wr->srs && !wr->srs->is_geographic) ||
             (!wr->srs && ows_srs_meter_units(o, layer_name)))
           buffer_add_int(select, o->meter_precision);
         else
@@ -738,6 +742,8 @@ static mlist *wfs_retrieve_sql_request_list(ows * o, wfs_request * wr)
 
     buffer_copy(sql, where);
 
+    /* fprintf(stderr, "sql = %s\n", sql->buf); */
+
     list_add(sql_req, sql);
     list_add(where_list, where);
     list_add_by_copy(from_list, layer_uri);
diff --git a/src/wfs/wfs_request.c b/src/wfs/wfs_request.c
index 1e935be..8b69d3e 100644
--- a/src/wfs/wfs_request.c
+++ b/src/wfs/wfs_request.c
@@ -399,15 +399,9 @@ static void wfs_request_check_srs(ows * o, wfs_request * wr, list * layer_name)
       return;
     }
 
-    if ((wr->format == WFS_GML311 || wr->format == WFS_GML321) && wr->srs->is_degree) {
-      wr->srs->is_reverse_axis = true;
-      wr->srs->is_long = true;
-    } else if (wr->format == WFS_GML311 || wr->format == WFS_GML321) {
-      wr->srs->is_long = true;
-    } else if (ows_version_get(o->request->version) == 110 && wr->srs->is_degree) {
-      wr->srs->is_reverse_axis = true;
-      wr->srs->is_long = true;
-    } else if (ows_version_get(o->request->version) == 110) {
+    if (wr->format == WFS_GML311 || wr->format == WFS_GML321 ||
+        ows_version_get(o->request->version) == 110) {
+      wr->srs->honours_authority_axis_order = true;
       wr->srs->is_long = true;
     }
 
@@ -429,6 +423,7 @@ static void wfs_request_check_bbox(ows * o, wfs_request * wr, list * layer_name)
 {
   buffer *b;
   int srid = 4326; /* Default srid if not srs is provided since WFS 1.1.0 */
+  bool honours_authority_axis_order_if_no_explicit_srs = false;
 
   assert(o && wr && layer_name && wr->srs);
 
@@ -437,18 +432,16 @@ static void wfs_request_check_bbox(ows * o, wfs_request * wr, list * layer_name)
   b = array_get(o->cgi, "bbox");
   wr->bbox = ows_bbox_init();
 
-  if (ows_version_get(o->request->version) == 100) srid = wr->srs->srid;
+  if (ows_version_get(o->request->version) == 100)
+      srid = wr->srs->srid;
+  else
+      honours_authority_axis_order_if_no_explicit_srs = true;
 
-  if (!ows_bbox_set_from_str(o, wr->bbox, b->buf, srid)) {
+  if (!ows_bbox_set_from_str(o, wr->bbox, b->buf, srid, honours_authority_axis_order_if_no_explicit_srs)) {
     ows_error(o, OWS_ERROR_INVALID_PARAMETER_VALUE,
               "Bad parameters for Bbox, must be Xmin,Ymin,Xmax,Ymax[,crsuri]", "NULL");
     return;
   }
-
-  /* related to BBOX with crsuri and srsName issue like:
-     bbox=34.94,-10.52,71.96,32.19,urn:ogc:def:crs:EPSG::4326
-  */
-  if (wr->srs->is_reverse_axis) wr->bbox->srs->is_reverse_axis = true;
 }
 
 

From 63136ab48a545cbd7f167285cf1d139e1d30d360 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Fri, 27 Nov 2020 01:05:19 +0100
Subject: [PATCH 27/30] Add tests for GetFeature BBOX and SRSNAME

---
 .../wfs10_getfeatures_france_bbox.txt         | 28 +++++++++++++++++++
 ...fs11_getfeatures_france_bboxwithcrsuri.txt | 27 ++++++++++++++++++
 ...features_france_bboxwithcrsuri_srsname.txt | 27 ++++++++++++++++++
 ...1_getfeatures_france_bboxwithoutcrsuri.txt | 27 ++++++++++++++++++
 .../input/wfs10_getfeatures_france_bbox.txt   |  1 +
 ...fs11_getfeatures_france_bboxwithcrsuri.txt |  1 +
 ...features_france_bboxwithcrsuri_srsname.txt |  1 +
 ...1_getfeatures_france_bboxwithoutcrsuri.txt |  1 +
 8 files changed, 113 insertions(+)
 create mode 100644 demo/tests/expected/wfs10_getfeatures_france_bbox.txt
 create mode 100644 demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri.txt
 create mode 100644 demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt
 create mode 100644 demo/tests/expected/wfs11_getfeatures_france_bboxwithoutcrsuri.txt
 create mode 100644 demo/tests/input/wfs10_getfeatures_france_bbox.txt
 create mode 100644 demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri.txt
 create mode 100644 demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt
 create mode 100644 demo/tests/input/wfs11_getfeatures_france_bboxwithoutcrsuri.txt

diff --git a/demo/tests/expected/wfs10_getfeatures_france_bbox.txt b/demo/tests/expected/wfs10_getfeatures_france_bbox.txt
new file mode 100644
index 0000000..55aee10
--- /dev/null
+++ b/demo/tests/expected/wfs10_getfeatures_france_bbox.txt
@@ -0,0 +1,28 @@
+Content-Type: text/xml; subtype=gml/2.1.2
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.0.0&amp;request=DescribeFeatureType&amp;Typename=tows:world   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/2.1.2/feature.xsd'
+>
+<gml:boundedBy><gml:null>missing</gml:null></gml:boundedBy>
+  <gml:featureMember>
+   <tows:world fid="world.62">
+   <tows:name>France</tows:name>
+   <tows:gmi_cntry>FRA</tows:gmi_cntry>
+   <tows:region>Europe</tows:region>
+   <tows:geom><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>9.219166,41.366379 9.0975,41.392769 9.080555,41.474709 8.882221,41.506649 8.779999,41.588871 8.794722,41.632488 8.913887,41.67638 8.878887,41.69804 8.680275,41.751659 8.724722,41.776932 8.802219,41.894428 8.754164,41.93166 8.614721,41.89777 8.589441,41.966099 8.658609,41.978039 8.726387,42.040821 8.696665,42.10944 8.561943,42.14888 8.572777,42.214161 8.641109,42.25499 8.688055,42.27026 8.612221,42.349991 8.555832,42.376659 8.672222,42.461929 8.663332,42.507771 8.937498,42.636379 9.053053,42.6586 9.083887,42.710819 9.210554,42.73082 9.290833,42.673321 9.34111,42.73415 9.320833,42.894989 9.346388,42.958881 9.344721,43.00082 9.430277,43.005821 9.465832,42.927212 9.489443,42.81443 9.459999,42.6036 9.502857,42.56636 9.497221,42.600819 9.543055,42.429989 9.508055,42.06554 9.406944,41.906651 9.348888,41.618881 9.282776,41.607769 9.355276,41.59388 9.25083,41.41193 9.219166,41.366379</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2.901285,50.697048 3.035277,50.773869 3.113055,50.79332 3.193333,50.741371 3.281388,50.594151 3.28,50.538319 3.367222,50.495541 3.602222,50.497211 3.668889,50.444149 3.671944,50.346371 3.725277,50.313599 3.763611,50.351929 4.090833,50.31443 4.21611,50.26527 4.137777,50.13776 4.226388,50.0811 4.15,49.98637 4.168332,49.981369 4.458333,49.938591 4.67361,49.99638 4.7575,50.129429 4.876388,50.15498 4.851943,50.07943 4.800832,49.97776 4.88111,49.9147 4.858054,49.796379 5.097777,49.768589 5.216944,49.69054 5.276111,49.698589 5.329721,49.659981 5.307221,49.63081 5.423332,49.60915 5.473055,49.5061 5.705208,49.535229 5.783038,49.527271 5.963333,49.488319 5.981388,49.448318 6.165277,49.504711 6.362221,49.45998 6.493888,49.447201 6.594722,49.363041 6.589722,49.320271 6.78722,49.162479 6.838888,49.15498 6.847499,49.21526 7.026666,49.188869 7.038332,49.11832 7.088332,49.125259 7.361388,49.14777 7.375277,49.171928 7.486943,49.16415 7.539999,49.088871 7.74111,49.04166 7.93861,49.04887 8.192221,48.968868 8.227394,48.963711 8.133333,48.88554 7.921515,48.690029 7.801943,48.59248 7.807499,48.513321 7.771666,48.49165 7.750833,48.336651 7.604999,48.156929 7.571666,48.037209 7.615832,48.002769 7.513333,47.686932 7.588799,47.58456 7.521388,47.525822 7.452777,47.469978 7.39561,47.439671 7.178332,47.44582 7.198054,47.495258 6.990555,47.497211 7.007777,47.45499 6.978333,47.444149 6.88111,47.35693 7.023055,47.371651 7.061665,47.345539 7.010833,47.30526 6.948332,47.291931 6.694443,47.068321 6.702777,47.038601 6.587221,46.987759 6.434721,46.926929 6.452777,46.774429 6.325022,46.704479 6.129999,46.593319 6.078055,46.460819 6.124443,46.40192 6.114444,46.257771 6.060832,46.250542 5.96611,46.205261 6,46.17416 5.965833,46.14027 6.152222,46.153591 6.305554,46.252491 6.242221,46.297771 6.243931,46.322392 6.246387,46.357769 6.328333,46.406929 6.633611,46.464149 6.79611,46.432491 6.808887,46.411091 6.804937,46.405499 6.767499,46.352489 6.844443,46.27137 6.795277,46.217758 6.788054,46.142208 6.884444,46.126091 6.871387,46.051929 6.929166,46.065262 7.038747,45.931721 6.808887,45.831379 6.799166,45.780819 6.824166,45.714989 6.990832,45.63998 6.999443,45.518318 7.181388,45.411652 7.133054,45.355549 7.122776,45.301929 6.850277,45.136101 6.760833,45.16832 6.620172,45.110661 6.746666,45.02026 6.743332,44.947762 7.009999,44.848591 7.068889,44.689152 7.000833,44.69915 6.950832,44.6647 6.960278,44.628868 6.852777,44.540821 6.857222,44.507771 6.934999,44.443039 6.88611,44.415821 6.935832,44.323318 7.279444,44.156651 7.672776,44.182758 7.704166,44.072208 7.492221,43.869431 7.534765,43.783451 7.457388,43.758652 7.4407,43.757824 7.4383,43.7603 7.4358,43.7631 7.4342,43.766102 7.4325,43.769199 7.4294,43.7714 7.4247,43.773102 7.42,43.772499 7.4161,43.770599 7.4128,43.768299 7.4097,43.7658 7.4064,43.763599 7.4031,43.761398 7.4003,43.758598 7.3972,43.7561 7.3939,43.753899 7.3906,43.7514 7.3878,43.7486 7.3864,43.745602 7.3864,43.741901 7.3883,43.738899 7.39,43.735802 7.3908,43.732201 7.391187,43.728031 7.349536,43.721825 7.345833,43.720539 7.15861,43.663052 7.133888,43.564159 7.005278,43.558319 6.854444,43.427212 6.748055,43.434711 6.669722,43.31554 6.589444,43.29221 6.681389,43.22443 6.615,43.16943 6.593888,43.197491 6.375278,43.149712 6.368055,43.09277 6.201943,43.12999 6.166666,43.115551 6.18111,43.056381 6.088611,43.05249 6.126943,43.07555 6.117499,43.098049 5.934722,43.133598 5.911111,43.099991 5.862222,43.057491 5.781111,43.082489 5.780555,43.139149 5.431944,43.220829 5.36361,43.221931 5.361666,43.33527 5.322222,43.36665 5.063611,43.34082 5.012777,43.3736 5.018332,43.400829 5.230555,43.464161 5.227221,43.496101 5.162222,43.47694 5.031388,43.55666 5.016109,43.496658 5.060833,43.465549 5.06111,43.430538 4.957777,43.424992 4.876111,43.42387 4.87361,43.373322 4.756944,43.41943 4.741666,43.417488 4.816388,43.37999 4.821666,43.359989 4.606944,43.361931 4.573333,43.37999 4.601666,43.424992 4.537837,43.451408 4.399444,43.455818 4.321111,43.458321 4.312499,43.509708 4.247222,43.49194 4.240555,43.471661 4.195276,43.46138 4.124722,43.498322 4.133055,43.536652 4.062222,43.56332 3.860555,43.484711 3.471389,43.278599 3.341111,43.271099 3.102222,43.084148 3.043333,43.10693 3.030278,43.069149 3.085278,43.05027 3.037777,42.940269 3.036944,42.897209 2.963889,42.84832 2.975277,42.809429 3.012222,42.798038 3.052499,42.878601 3.049444,42.553879 3.176962,42.437611 3.150833,42.433319 3.038333,42.474979 2.678333,42.401649 2.671111,42.338322 2.476666,42.35165 2.254167,42.434711 2.086944,42.363319 1.976666,42.374699 1.953055,42.437199 1.7875,42.490261 1.710967,42.473499 1.781667,42.581661 1.541111,42.65387 1.435247,42.597149 1.383611,42.689701 0.815833,42.841091 0.667778,42.839149 0.668055,42.748039 0.676111,42.689152 0.4125,42.695259 0.291111,42.675819 0.261944,42.71748 -0.0575,42.694149 -0.123889,42.757488 -0.187778,42.78582 -0.306667,42.849152 -0.392222,42.796379 -0.500833,42.822208 -0.519167,42.790821 -0.656111,42.863602 -0.746944,42.965542 -0.818889,42.946091 -1.300556,43.071659 -1.288333,43.106091 -1.360278,43.031651 -1.440556,43.048321 -1.472778,43.091091 -1.381945,43.196651 -1.409167,43.273041 -1.62,43.256378 -1.655833,43.309429 -1.810488,43.385891 -1.652223,43.399429 -1.493333,43.561378 -1.424445,43.758881 -1.294167,44.259708 -1.208611,44.62582 -1.192222,44.66193 -1.054445,44.659988 -1.037222,44.683041 -1.134444,44.763599 -1.168889,44.7761 -1.248889,44.630821 -1.259167,44.691929 -1.194722,45.1236 -1.095278,45.552761 -1.058333,45.571381 -1.057778,45.520821 -0.808333,45.36721 -0.735833,45.24749 -0.714722,45.13055 -0.661667,45.0536 -0.560556,44.98666 -0.589167,45.021648 -0.495,44.998878 -0.519445,45.030819 -0.62,45.060261 -0.668333,45.124149 -0.737778,45.400269 -0.85,45.519161 -1.245326,45.70779 -1.230834,45.788052 -1.146111,45.803322 -0.985278,45.71526 -1.138056,45.839989 -1.071944,45.958881 -1.111389,46.006649 -1.055556,46.008598 -1.103889,46.100269 -1.152222,46.15527 -1.2025,46.15527 -1.193889,46.21526 -1.105834,46.258598 -1.112222,46.313599 -1.195,46.319149 -1.214445,46.273319 -1.405556,46.346661 -1.448611,46.338039 -1.472222,46.395821 -1.511945,46.419159 -1.673889,46.451931 -1.799445,46.486931 -1.914167,46.688599 -2.108056,46.813599 -2.13389,46.887211 -2.011049,47.020031 -1.984445,47.034431 -2.051667,47.09721 -2.239722,47.135818 -2.163611,47.165272 -2.165556,47.264992 -2.025,47.29694 -1.815834,47.237209 -1.998889,47.31749 -2.159445,47.30999 -2.273334,47.24165 -2.495833,47.29137 -2.4425,47.2911 -2.448612,47.322491 -2.553611,47.37693 -2.396111,47.40527 -2.434167,47.421101 -2.488889,47.48138 -2.361389,47.504162 -2.662222,47.5261 -2.736111,47.504162 -2.809722,47.49165 -2.912222,47.551659 -2.877223,47.564709 -2.736945,47.54388 -2.680556,47.613041 -2.768611,47.620541 -2.88,47.606098 -2.936667,47.59721 -2.960556,47.56443 -3.125278,47.59943 -3.120278,47.500542 -3.149167,47.521381 -3.132223,47.576649 -3.200556,47.659431 -3.148056,47.741379 -3.212778,47.652489 -3.354445,47.706661 -3.281389,47.78249 -3.441389,47.701382 -3.712778,47.811939 -3.847778,47.793598 -3.951111,47.89888 -4.085556,47.86832 -4.182778,47.881378 -4.155556,47.831928 -4.209723,47.799431 -4.361945,47.802761 -4.343889,47.8536 -4.419723,47.960819 -4.529445,48.022491 -4.613056,48.020821 -4.725613,48.040989 -4.662223,48.073601 -4.295,48.098881 -4.297501,48.178322 -4.43139,48.240551 -4.493056,48.236099 -4.537223,48.176102 -4.563612,48.233601 -4.623889,48.28194 -4.513056,48.30027 -4.235001,48.303879 -4.323611,48.319988 -4.318334,48.357769 -4.448611,48.33054 -4.405556,48.381939 -4.293334,48.427212 -4.763889,48.33527 -4.790556,48.421379 -4.744167,48.545818 -4.631945,48.579708 -4.428334,48.650539 -4.314167,48.670818 -4.222778,48.648319 -4.176667,48.6861 -3.968056,48.73193 -3.953333,48.65221 -3.900278,48.67638 -3.854167,48.629162 -3.810833,48.726101 -3.596111,48.675819 -3.571111,48.6861 -3.582778,48.72665 -3.532222,48.739159 -3.580834,48.76693 -3.512778,48.837212 -3.263056,48.8386 -3.220834,48.870541 -3.224167,48.79388 -3.101667,48.872211 -3.079167,48.826931 -2.948611,48.768879 -2.883611,48.68082 -2.824722,48.654991 -2.765556,48.572208 -2.653334,48.53054 -2.464723,48.62999 -2.314336,48.6926 -2.284445,48.669159 -2.329167,48.62471 -2.226389,48.61137 -2.176389,48.57943 -2.105834,48.646099 -2.0025,48.58305 -1.9825,48.514149 -1.956944,48.550819 -2.03,48.650829 -1.849167,48.709148 -1.87,48.64999 -1.840556,48.615551 -1.638056,48.61665 -1.433889,48.663601 -1.560833,48.744709 -1.605834,48.841099 -1.549167,48.922771 -1.556667,49.01582 -1.585278,49.008881 -1.610278,49.097759 -1.549445,49.219711 -1.629445,49.215549 -1.774167,49.381649 -1.8125,49.377769 -1.845834,49.49971 -1.884444,49.529148 -1.84,49.57832 -1.851944,49.642769 -1.945833,49.675541 -1.941945,49.723881 -1.482778,49.675541 -1.410833,49.70499 -1.258333,49.694439 -1.259722,49.586102 -1.299445,49.57888 -1.301667,49.54388 -1.142222,49.34388 -1.013889,49.394711 -0.436389,49.341099 -0.218333,49.274712 0.218333,49.426659 0.393055,49.458881 0.143611,49.47694 0.078056,49.511662 0.184444,49.70277 0.611944,49.857491 1.131111,49.948879 1.435555,50.09832 1.505555,50.201931 1.555,50.21944 1.656944,50.184158 1.645,50.217209 1.548055,50.266651 1.534167,50.288601 1.552778,50.359989 1.610278,50.36832 1.558889,50.402489 1.576944,50.612209 1.576111,50.864429 1.943333,50.99527 2.472777,51.070541 2.541667,51.091099 2.6125,50.887211 2.629444,50.824711 2.781944,50.75555 2.901285,50.697048</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></tows:geom>
+   </tows:world>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri.txt b/demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri.txt
new file mode 100644
index 0000000..4e0e0cb
--- /dev/null
+++ b/demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri.txt
@@ -0,0 +1,27 @@
+Content-Type: text/xml; subtype=gml/3.1.1
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;Typename=tows:world   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.1.0/wfs.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/3.1.1/base/gml.xsd'
+>
+  <gml:featureMember>
+   <tows:world gml:id="world.62">
+   <tows:name>France</tows:name>
+   <tows:gmi_cntry>FRA</tows:gmi_cntry>
+   <tows:region>Europe</tows:region>
+   <tows:geom><gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::4326"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>41.366379 9.219166 41.392769 9.0975 41.474709 9.080555 41.506649 8.882221 41.588871 8.779999 41.632488 8.794722 41.67638 8.913887 41.69804 8.878887 41.751659 8.680275 41.776932 8.724722 41.894428 8.802219 41.93166 8.754164 41.89777 8.614721 41.966099 8.589441 41.978039 8.658609 42.040821 8.726387 42.10944 8.696665 42.14888 8.561943 42.214161 8.572777 42.25499 8.641109 42.27026 8.688055 42.349991 8.612221 42.376659 8.555832 42.461929 8.672222 42.507771 8.663332 42.636379 8.937498 42.6586 9.053053 42.710819 9.083887 42.73082 9.210554 42.673321 9.290833 42.73415 9.34111 42.894989 9.320833 42.958881 9.346388 43.00082 9.344721 43.005821 9.430277 42.927212 9.465832 42.81443 9.489443 42.6036 9.459999 42.56636 9.502857 42.600819 9.497221 42.429989 9.543055 42.06554 9.508055 41.906651 9.406944 41.618881 9.348888 41.607769 9.282776 41.59388 9.355276 41.41193 9.25083 41.366379 9.219166</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>50.697048 2.901285 50.773869 3.035277 50.79332 3.113055 50.741371 3.193333 50.594151 3.281388 50.538319 3.28 50.495541 3.367222 50.497211 3.602222 50.444149 3.668889 50.346371 3.671944 50.313599 3.725277 50.351929 3.763611 50.31443 4.090833 50.26527 4.21611 50.13776 4.137777 50.0811 4.226388 49.98637 4.15 49.981369 4.168332 49.938591 4.458333 49.99638 4.67361 50.129429 4.7575 50.15498 4.876388 50.07943 4.851943 49.97776 4.800832 49.9147 4.88111 49.796379 4.858054 49.768589 5.097777 49.69054 5.216944 49.698589 5.276111 49.659981 5.329721 49.63081 5.307221 49.60915 5.423332 49.5061 5.473055 49.535229 5.705208 49.527271 5.783038 49.488319 5.963333 49.448318 5.981388 49.504711 6.165277 49.45998 6.362221 49.447201 6.493888 49.363041 6.594722 49.320271 6.589722 49.162479 6.78722 49.15498 6.838888 49.21526 6.847499 49.188869 7.026666 49.11832 7.038332 49.125259 7.088332 49.14777 7.361388 49.171928 7.375277 49.16415 7.486943 49.088871 7.539999 49.04166 7.74111 49.04887 7.93861 48.968868 8.192221 48.963711 8.227394 48.88554 8.133333 48.690029 7.921515 48.59248 7.801943 48.513321 7.807499 48.49165 7.771666 48.336651 7.750833 48.156929 7.604999 48.037209 7.571666 48.002769 7.615832 47.686932 7.513333 47.58456 7.588799 47.525822 7.521388 47.469978 7.452777 47.439671 7.39561 47.44582 7.178332 47.495258 7.198054 47.497211 6.990555 47.45499 7.007777 47.444149 6.978333 47.35693 6.88111 47.371651 7.023055 47.345539 7.061665 47.30526 7.010833 47.291931 6.948332 47.068321 6.694443 47.038601 6.702777 46.987759 6.587221 46.926929 6.434721 46.774429 6.452777 46.704479 6.325022 46.593319 6.129999 46.460819 6.078055 46.40192 6.124443 46.257771 6.114444 46.250542 6.060832 46.205261 5.96611 46.17416 6 46.14027 5.965833 46.153591 6.152222 46.252491 6.305554 46.297771 6.242221 46.322392 6.243931 46.357769 6.246387 46.406929 6.328333 46.464149 6.633611 46.432491 6.79611 46.411091 6.808887 46.405499 6.804937 46.352489 6.767499 46.27137 6.844443 46.217758 6.795277 46.142208 6.788054 46.126091 6.884444 46.051929 6.871387 46.065262 6.929166 45.931721 7.038747 45.831379 6.808887 45.780819 6.799166 45.714989 6.824166 45.63998 6.990832 45.518318 6.999443 45.411652 7.181388 45.355549 7.133054 45.301929 7.122776 45.136101 6.850277 45.16832 6.760833 45.110661 6.620172 45.02026 6.746666 44.947762 6.743332 44.848591 7.009999 44.689152 7.068889 44.69915 7.000833 44.6647 6.950832 44.628868 6.960278 44.540821 6.852777 44.507771 6.857222 44.443039 6.934999 44.415821 6.88611 44.323318 6.935832 44.156651 7.279444 44.182758 7.672776 44.072208 7.704166 43.869431 7.492221 43.783451 7.534765 43.758652 7.457388 43.757824 7.4407 43.7603 7.4383 43.7631 7.4358 43.766102 7.4342 43.769199 7.4325 43.7714 7.4294 43.773102 7.4247 43.772499 7.42 43.770599 7.4161 43.768299 7.4128 43.7658 7.4097 43.763599 7.4064 43.761398 7.4031 43.758598 7.4003 43.7561 7.3972 43.753899 7.3939 43.7514 7.3906 43.7486 7.3878 43.745602 7.3864 43.741901 7.3864 43.738899 7.3883 43.735802 7.39 43.732201 7.3908 43.728031 7.391187 43.721825 7.349536 43.720539 7.345833 43.663052 7.15861 43.564159 7.133888 43.558319 7.005278 43.427212 6.854444 43.434711 6.748055 43.31554 6.669722 43.29221 6.589444 43.22443 6.681389 43.16943 6.615 43.197491 6.593888 43.149712 6.375278 43.09277 6.368055 43.12999 6.201943 43.115551 6.166666 43.056381 6.18111 43.05249 6.088611 43.07555 6.126943 43.098049 6.117499 43.133598 5.934722 43.099991 5.911111 43.057491 5.862222 43.082489 5.781111 43.139149 5.780555 43.220829 5.431944 43.221931 5.36361 43.33527 5.361666 43.36665 5.322222 43.34082 5.063611 43.3736 5.012777 43.400829 5.018332 43.464161 5.230555 43.496101 5.227221 43.47694 5.162222 43.55666 5.031388 43.496658 5.016109 43.465549 5.060833 43.430538 5.06111 43.424992 4.957777 43.42387 4.876111 43.373322 4.87361 43.41943 4.756944 43.417488 4.741666 43.37999 4.816388 43.359989 4.821666 43.361931 4.606944 43.37999 4.573333 43.424992 4.601666 43.451408 4.537837 43.455818 4.399444 43.458321 4.321111 43.509708 4.312499 43.49194 4.247222 43.471661 4.240555 43.46138 4.195276 43.498322 4.124722 43.536652 4.133055 43.56332 4.062222 43.484711 3.860555 43.278599 3.471389 43.271099 3.341111 43.084148 3.102222 43.10693 3.043333 43.069149 3.030278 43.05027 3.085278 42.940269 3.037777 42.897209 3.036944 42.84832 2.963889 42.809429 2.975277 42.798038 3.012222 42.878601 3.052499 42.553879 3.049444 42.437611 3.176962 42.433319 3.150833 42.474979 3.038333 42.401649 2.678333 42.338322 2.671111 42.35165 2.476666 42.434711 2.254167 42.363319 2.086944 42.374699 1.976666 42.437199 1.953055 42.490261 1.7875 42.473499 1.710967 42.581661 1.781667 42.65387 1.541111 42.597149 1.435247 42.689701 1.383611 42.841091 0.815833 42.839149 0.667778 42.748039 0.668055 42.689152 0.676111 42.695259 0.4125 42.675819 0.291111 42.71748 0.261944 42.694149 -0.0575 42.757488 -0.123889 42.78582 -0.187778 42.849152 -0.306667 42.796379 -0.392222 42.822208 -0.500833 42.790821 -0.519167 42.863602 -0.656111 42.965542 -0.746944 42.946091 -0.818889 43.071659 -1.300556 43.106091 -1.288333 43.031651 -1.360278 43.048321 -1.440556 43.091091 -1.472778 43.196651 -1.381945 43.273041 -1.409167 43.256378 -1.62 43.309429 -1.655833 43.385891 -1.810488 43.399429 -1.652223 43.561378 -1.493333 43.758881 -1.424445 44.259708 -1.294167 44.62582 -1.208611 44.66193 -1.192222 44.659988 -1.054445 44.683041 -1.037222 44.763599 -1.134444 44.7761 -1.168889 44.630821 -1.248889 44.691929 -1.259167 45.1236 -1.194722 45.552761 -1.095278 45.571381 -1.058333 45.520821 -1.057778 45.36721 -0.808333 45.24749 -0.735833 45.13055 -0.714722 45.0536 -0.661667 44.98666 -0.560556 45.021648 -0.589167 44.998878 -0.495 45.030819 -0.519445 45.060261 -0.62 45.124149 -0.668333 45.400269 -0.737778 45.519161 -0.85 45.70779 -1.245326 45.788052 -1.230834 45.803322 -1.146111 45.71526 -0.985278 45.839989 -1.138056 45.958881 -1.071944 46.006649 -1.111389 46.008598 -1.055556 46.100269 -1.103889 46.15527 -1.152222 46.15527 -1.2025 46.21526 -1.193889 46.258598 -1.105834 46.313599 -1.112222 46.319149 -1.195 46.273319 -1.214445 46.346661 -1.405556 46.338039 -1.448611 46.395821 -1.472222 46.419159 -1.511945 46.451931 -1.673889 46.486931 -1.799445 46.688599 -1.914167 46.813599 -2.108056 46.887211 -2.13389 47.020031 -2.011049 47.034431 -1.984445 47.09721 -2.051667 47.135818 -2.239722 47.165272 -2.163611 47.264992 -2.165556 47.29694 -2.025 47.237209 -1.815834 47.31749 -1.998889 47.30999 -2.159445 47.24165 -2.273334 47.29137 -2.495833 47.2911 -2.4425 47.322491 -2.448612 47.37693 -2.553611 47.40527 -2.396111 47.421101 -2.434167 47.48138 -2.488889 47.504162 -2.361389 47.5261 -2.662222 47.504162 -2.736111 47.49165 -2.809722 47.551659 -2.912222 47.564709 -2.877223 47.54388 -2.736945 47.613041 -2.680556 47.620541 -2.768611 47.606098 -2.88 47.59721 -2.936667 47.56443 -2.960556 47.59943 -3.125278 47.500542 -3.120278 47.521381 -3.149167 47.576649 -3.132223 47.659431 -3.200556 47.741379 -3.148056 47.652489 -3.212778 47.706661 -3.354445 47.78249 -3.281389 47.701382 -3.441389 47.811939 -3.712778 47.793598 -3.847778 47.89888 -3.951111 47.86832 -4.085556 47.881378 -4.182778 47.831928 -4.155556 47.799431 -4.209723 47.802761 -4.361945 47.8536 -4.343889 47.960819 -4.419723 48.022491 -4.529445 48.020821 -4.613056 48.040989 -4.725613 48.073601 -4.662223 48.098881 -4.295 48.178322 -4.297501 48.240551 -4.43139 48.236099 -4.493056 48.176102 -4.537223 48.233601 -4.563612 48.28194 -4.623889 48.30027 -4.513056 48.303879 -4.235001 48.319988 -4.323611 48.357769 -4.318334 48.33054 -4.448611 48.381939 -4.405556 48.427212 -4.293334 48.33527 -4.763889 48.421379 -4.790556 48.545818 -4.744167 48.579708 -4.631945 48.650539 -4.428334 48.670818 -4.314167 48.648319 -4.222778 48.6861 -4.176667 48.73193 -3.968056 48.65221 -3.953333 48.67638 -3.900278 48.629162 -3.854167 48.726101 -3.810833 48.675819 -3.596111 48.6861 -3.571111 48.72665 -3.582778 48.739159 -3.532222 48.76693 -3.580834 48.837212 -3.512778 48.8386 -3.263056 48.870541 -3.220834 48.79388 -3.224167 48.872211 -3.101667 48.826931 -3.079167 48.768879 -2.948611 48.68082 -2.883611 48.654991 -2.824722 48.572208 -2.765556 48.53054 -2.653334 48.62999 -2.464723 48.6926 -2.314336 48.669159 -2.284445 48.62471 -2.329167 48.61137 -2.226389 48.57943 -2.176389 48.646099 -2.105834 48.58305 -2.0025 48.514149 -1.9825 48.550819 -1.956944 48.650829 -2.03 48.709148 -1.849167 48.64999 -1.87 48.615551 -1.840556 48.61665 -1.638056 48.663601 -1.433889 48.744709 -1.560833 48.841099 -1.605834 48.922771 -1.549167 49.01582 -1.556667 49.008881 -1.585278 49.097759 -1.610278 49.219711 -1.549445 49.215549 -1.629445 49.381649 -1.774167 49.377769 -1.8125 49.49971 -1.845834 49.529148 -1.884444 49.57832 -1.84 49.642769 -1.851944 49.675541 -1.945833 49.723881 -1.941945 49.675541 -1.482778 49.70499 -1.410833 49.694439 -1.258333 49.586102 -1.259722 49.57888 -1.299445 49.54388 -1.301667 49.34388 -1.142222 49.394711 -1.013889 49.341099 -0.436389 49.274712 -0.218333 49.426659 0.218333 49.458881 0.393055 49.47694 0.143611 49.511662 0.078056 49.70277 0.184444 49.857491 0.611944 49.948879 1.131111 50.09832 1.435555 50.201931 1.505555 50.21944 1.555 50.184158 1.656944 50.217209 1.645 50.266651 1.548055 50.288601 1.534167 50.359989 1.552778 50.36832 1.610278 50.402489 1.558889 50.612209 1.576944 50.864429 1.576111 50.99527 1.943333 51.070541 2.472777 51.091099 2.541667 50.887211 2.6125 50.824711 2.629444 50.75555 2.781944 50.697048 2.901285</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></tows:geom>
+   </tows:world>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt b/demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt
new file mode 100644
index 0000000..bdfe616
--- /dev/null
+++ b/demo/tests/expected/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt
@@ -0,0 +1,27 @@
+Content-Type: text/xml; subtype=gml/3.1.1
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;Typename=tows:world   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.1.0/wfs.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/3.1.1/base/gml.xsd'
+>
+  <gml:featureMember>
+   <tows:world gml:id="world.62">
+   <tows:name>France</tows:name>
+   <tows:gmi_cntry>FRA</tows:gmi_cntry>
+   <tows:region>Europe</tows:region>
+   <tows:geom><gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::3857"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>1026273 5066534 1012729 5070449 1010843 5082615 988764 5087362 977385 5099592 979024 5106086 992289 5112625 988393 5115854 966284 5123852 971232 5127623 979859 5145178 974509 5150748 958986 5145678 956172 5155903 963872 5157690 971417 5167096 968108 5177387 953111 5183307 954317 5193114 961924 5199253 967150 5201549 958708 5213551 952431 5217569 965387 5230427 964398 5237347 994918 5256788 1007781 5260151 1011214 5268059 1025314 5271089 1034251 5262379 1039848 5271594 1037590 5296002 1040435 5305715 1040250 5312097 1049774 5312858 1053732 5300899 1056360 5283769 1053082 5251829 1057853 5246199 1057226 5251408 1062328 5225609 1058432 5170802 1047176 5147006 1040713 5104060 1033354 5102405 1041425 5100337 1029798 5073292 1026273 5066534</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>322970 6567879 337885 6581391 346544 6584815 355480 6575672 365282 6549815 365128 6540030 374837 6532541 400998 6532834 408419 6523553 408759 6506479 414696 6500764 418963 6507448 455389 6500909 469335 6492343 460615 6470168 470479 6460333 461976 6443916 464017 6443050 496299 6435648 520264 6445649 529602 6468721 542837 6473159 540116 6460043 534426 6442425 543363 6431516 540796 6411087 567482 6406296 580748 6392854 587334 6394240 593302 6387597 590797 6382582 603723 6378861 609258 6361176 635101 6366171 643765 6364807 663835 6358129 665845 6351277 686315 6360938 708239 6353274 722896 6351085 734121 6336688 733565 6329380 755550 6302476 761302 6301199 762260 6311466 782205 6306970 783504 6294962 789070 6296142 819466 6299972 821012 6304085 833443 6302760 839349 6289954 861736 6281933 883722 6283158 911954 6269581 915869 6268706 905399 6255462 881819 6222429 868508 6205995 869127 6192682 865138 6189041 862819 6163045 846585 6133002 842874 6113047 847791 6107316 836380 6054929 844781 6038017 837277 6028328 829639 6019127 823276 6014137 799088 6015149 801284 6023291 778185 6023613 780102 6016659 776824 6014874 766002 6000530 781803 6002949 786101 5998658 780442 5992043 773485 5989856 745222 5953233 746150 5948377 733286 5940076 716310 5930155 718320 5905333 704098 5893970 682388 5875944 676606 5854506 681770 5844993 680657 5821754 674689 5820590 664144 5813304 667917 5808303 664114 5802856 684862 5804997 701931 5820904 694881 5828196 695071 5832164 695345 5837868 704467 5845801 738450 5855044 756540 5849929 757962 5846473 757522 5845570 753355 5837017 761920 5823944 756447 5815314 755643 5803168 766373 5800578 764919 5788675 771351 5790814 783550 5769414 757962 5753369 756880 5745295 759663 5734793 778216 5722842 779174 5703493 799428 5686562 794048 5677670 792904 5669180 762569 5642973 752612 5648059 736954 5638960 751035 5624712 750664 5613301 780349 5597717 786905 5572717 779329 5574283 773763 5568889 774815 5563282 762848 5549521 763342 5544360 772001 5534261 766558 5530019 772093 5515614 810344 5489716 854130 5493768 857624 5476623 834030 5445258 838766 5431992 830153 5428169 828295 5428041 828028 5428423 827749 5428854 827571 5429317 827382 5429794 827037 5430134 826514 5430396 825991 5430303 825556 5430010 825189 5429656 824844 5429271 824477 5428931 824109 5428592 823798 5428160 823453 5427775 823085 5427436 822718 5427051 822406 5426620 822250 5426157 822250 5425587 822462 5425125 822651 5424648 822740 5424093 822783 5423450 818147 5422494 817734 5422296 796893 5413446 794141 5398241 779824 5397344 763033 5377226 751190 5378375 742470 5360124 733534 5356555 743769 5346195 736378 5337796 734028 5342080 709693 5334787 708889 5326103 690397 5331779 686470 5329576 688078 5320558 677781 5319965 682048 5323478 680997 5326908 660650 5332329 658022 5327204 652580 5320727 643550 5324536 643488 5333176 604681 5345645 597074 5345813 596858 5363143 592467 5367947 563679 5363993 558020 5369012 558638 5373183 582263 5382891 581892 5387791 574656 5384851 560092 5397089 558391 5387876 563369 5383104 563400 5377735 551897 5376885 542806 5376713 542528 5368969 529541 5376033 527840 5375735 536158 5369990 536745 5366927 512843 5367225 509101 5369990 512255 5376885 505150 5380935 489744 5381611 481024 5381995 480065 5389879 472799 5387152 472056 5384041 467016 5382464 459162 5388132 460090 5394016 452204 5398112 429755 5386043 386433 5354474 371931 5353327 345338 5324789 338782 5328262 337329 5322503 343452 5319627 338164 5302885 338071 5296339 329939 5288913 331206 5283010 335319 5281282 339803 5293512 339463 5244312 353658 5226758 350749 5226111 338226 5232397 298151 5221336 297347 5211794 275701 5213801 250933 5226321 232318 5215559 220041 5217274 217413 5226696 198984 5234703 190464 5232173 198334 5248512 171556 5259435 159771 5250853 154023 5264860 90818 5287815 74337 5287521 74368 5273699 75264 5264777 45919 5265702 32406 5262758 29160 5269068 -6401 5265533 -13791 5275132 -20903 5279428 -34138 5289039 -43662 5281030 -55753 5284949 -57793 5280187 -73038 5291234 -83149 5306728 -91158 5303770 -144777 5322885 -143417 5328134 -151425 5316791 -160362 5319330 -163949 5325847 -153837 5341952 -156868 5353624 -180338 5351077 -184326 5359189 -201543 5370894 -183925 5372968 -166237 5397814 -158568 5428204 -144066 5505721 -134542 5562806 -132718 5568455 -117380 5568152 -115463 5571760 -126286 5584382 -130120 5586342 -139026 5563588 -140170 5573152 -132996 5641001 -121926 5708966 -117813 5711927 -117751 5703890 -89983 5679518 -81913 5660568 -79563 5642097 -73656 5629964 -62401 5619422 -65586 5624930 -55103 5621345 -57824 5626375 -69018 5631013 -74399 5641087 -82129 5684757 -94622 5703626 -138629 5733645 -137016 5746449 -127584 5748887 -109681 5734836 -126688 5754744 -119328 5773762 -123719 5781415 -117504 5781727 -122884 5796432 -128265 5805266 -133862 5805266 -132903 5814912 -123101 5821887 -123812 5830747 -133027 5831641 -135191 5824258 -156466 5836077 -161259 5834687 -163887 5844008 -168309 5847776 -186336 5853070 -200313 5858727 -213084 5891393 -234668 5911702 -237544 5923683 -223869 5945344 -220907 5947696 -228391 5957956 -249325 5964271 -240852 5969092 -241069 5985435 -225422 5990678 -202138 5980879 -222515 5994051 -240388 5992820 -253066 5981607 -277835 5989763 -271898 5989719 -272578 5994873 -284267 6003817 -266734 6008477 -270970 6011081 -277062 6021005 -262869 6024758 -296357 6028374 -304582 6024758 -312777 6022696 -324187 6032588 -320291 6034741 -304675 6031305 -298398 6042718 -308200 6043957 -320600 6041572 -326908 6040105 -329568 6034695 -347904 6040471 -347348 6024161 -350564 6027596 -348677 6036711 -356284 6050382 -350440 6063937 -357645 6049235 -373415 6058192 -365283 6070745 -383094 6057318 -413305 6075625 -428333 6072585 -439836 6090049 -454802 6084976 -465625 6087143 -462594 6078939 -468624 6073552 -485570 6074104 -483560 6082533 -492001 6100339 -504216 6110597 -513523 6110319 -526053 6113677 -518996 6119108 -478117 6123321 -478396 6136573 -493300 6146968 -500165 6146224 -505081 6136202 -508019 6145806 -514729 6153889 -502391 6156955 -471438 6157559 -481302 6160256 -480715 6166583 -495217 6162022 -490424 6170633 -477932 6178224 -530314 6162814 -533282 6177246 -528118 6198145 -515626 6203845 -492960 6215772 -480251 6219190 -470077 6215398 -464944 6221766 -441722 6229497 -440083 6216053 -434177 6220127 -429044 6212171 -424220 6228514 -400317 6220033 -397534 6221766 -398833 6228606 -393205 6230717 -398617 6235406 -391041 6247285 -363242 6247519 -358542 6252923 -358913 6239959 -345276 6253206 -342771 6245546 -328238 6235736 -321002 6220876 -314447 6216522 -307860 6202583 -295368 6195576 -274372 6212310 -257631 6222862 -254303 6218910 -259282 6211421 -247840 6209174 -242275 6203798 -234420 6215024 -222917 6204408 -220691 6192821 -217846 6198986 -225979 6215821 -205848 6225653 -208167 6215679 -204890 6209878 -182348 6210063 -159620 6217973 -173751 6231654 -178761 6247942 -172452 6261767 -173287 6277546 -176472 6276368 -179255 6291465 -172483 6312224 -181389 6311515 -197499 6339869 -201767 6339206 -205477 6360081 -209775 6365128 -204828 6373566 -206157 6384638 -216609 6390274 -216176 6398593 -165062 6390274 -157053 6395341 -140077 6393525 -140232 6374902 -144654 6373662 -144901 6367656 -127152 6333413 -112866 6342103 -48579 6332938 -24305 6321603 24305 6347569 43755 6353086 15987 6356179 8689 6362130 20532 6394959 68121 6421632 125915 6437427 159805 6463321 167598 6481320 173102 6484366 184450 6478230 183121 6483978 172329 6492584 170783 6496407 172854 6508855 179255 6510308 173535 6516274 175545 6552983 175452 6597348 216331 6620457 275268 6633781 282937 6637424 290822 6601367 292708 6590345 309685 6578167 322970 6567879</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></tows:geom>
+   </tows:world>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/expected/wfs11_getfeatures_france_bboxwithoutcrsuri.txt b/demo/tests/expected/wfs11_getfeatures_france_bboxwithoutcrsuri.txt
new file mode 100644
index 0000000..4e0e0cb
--- /dev/null
+++ b/demo/tests/expected/wfs11_getfeatures_france_bboxwithoutcrsuri.txt
@@ -0,0 +1,27 @@
+Content-Type: text/xml; subtype=gml/3.1.1
+
+<?xml version='1.0' encoding='UTF-8'?>
+<wfs:FeatureCollection
+ xmlns:tows='http://www.tinyows.org/'
+ xmlns:wfs='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:gml='http://www.opengis.net/gml'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ xmlns:ows='http://www.opengis.net/ows'
+ xsi:schemaLocation='http://www.tinyows.org/
+    http://127.0.0.1/cgi-bin/tinyows?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;Typename=tows:world   http://www.opengis.net/wfs
+   http://schemas.opengis.net/wfs/1.1.0/wfs.xsd
+   http://www.opengis.net/gml
+   http://schemas.opengis.net/gml/3.1.1/base/gml.xsd'
+>
+  <gml:featureMember>
+   <tows:world gml:id="world.62">
+   <tows:name>France</tows:name>
+   <tows:gmi_cntry>FRA</tows:gmi_cntry>
+   <tows:region>Europe</tows:region>
+   <tows:geom><gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::4326"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>41.366379 9.219166 41.392769 9.0975 41.474709 9.080555 41.506649 8.882221 41.588871 8.779999 41.632488 8.794722 41.67638 8.913887 41.69804 8.878887 41.751659 8.680275 41.776932 8.724722 41.894428 8.802219 41.93166 8.754164 41.89777 8.614721 41.966099 8.589441 41.978039 8.658609 42.040821 8.726387 42.10944 8.696665 42.14888 8.561943 42.214161 8.572777 42.25499 8.641109 42.27026 8.688055 42.349991 8.612221 42.376659 8.555832 42.461929 8.672222 42.507771 8.663332 42.636379 8.937498 42.6586 9.053053 42.710819 9.083887 42.73082 9.210554 42.673321 9.290833 42.73415 9.34111 42.894989 9.320833 42.958881 9.346388 43.00082 9.344721 43.005821 9.430277 42.927212 9.465832 42.81443 9.489443 42.6036 9.459999 42.56636 9.502857 42.600819 9.497221 42.429989 9.543055 42.06554 9.508055 41.906651 9.406944 41.618881 9.348888 41.607769 9.282776 41.59388 9.355276 41.41193 9.25083 41.366379 9.219166</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>50.697048 2.901285 50.773869 3.035277 50.79332 3.113055 50.741371 3.193333 50.594151 3.281388 50.538319 3.28 50.495541 3.367222 50.497211 3.602222 50.444149 3.668889 50.346371 3.671944 50.313599 3.725277 50.351929 3.763611 50.31443 4.090833 50.26527 4.21611 50.13776 4.137777 50.0811 4.226388 49.98637 4.15 49.981369 4.168332 49.938591 4.458333 49.99638 4.67361 50.129429 4.7575 50.15498 4.876388 50.07943 4.851943 49.97776 4.800832 49.9147 4.88111 49.796379 4.858054 49.768589 5.097777 49.69054 5.216944 49.698589 5.276111 49.659981 5.329721 49.63081 5.307221 49.60915 5.423332 49.5061 5.473055 49.535229 5.705208 49.527271 5.783038 49.488319 5.963333 49.448318 5.981388 49.504711 6.165277 49.45998 6.362221 49.447201 6.493888 49.363041 6.594722 49.320271 6.589722 49.162479 6.78722 49.15498 6.838888 49.21526 6.847499 49.188869 7.026666 49.11832 7.038332 49.125259 7.088332 49.14777 7.361388 49.171928 7.375277 49.16415 7.486943 49.088871 7.539999 49.04166 7.74111 49.04887 7.93861 48.968868 8.192221 48.963711 8.227394 48.88554 8.133333 48.690029 7.921515 48.59248 7.801943 48.513321 7.807499 48.49165 7.771666 48.336651 7.750833 48.156929 7.604999 48.037209 7.571666 48.002769 7.615832 47.686932 7.513333 47.58456 7.588799 47.525822 7.521388 47.469978 7.452777 47.439671 7.39561 47.44582 7.178332 47.495258 7.198054 47.497211 6.990555 47.45499 7.007777 47.444149 6.978333 47.35693 6.88111 47.371651 7.023055 47.345539 7.061665 47.30526 7.010833 47.291931 6.948332 47.068321 6.694443 47.038601 6.702777 46.987759 6.587221 46.926929 6.434721 46.774429 6.452777 46.704479 6.325022 46.593319 6.129999 46.460819 6.078055 46.40192 6.124443 46.257771 6.114444 46.250542 6.060832 46.205261 5.96611 46.17416 6 46.14027 5.965833 46.153591 6.152222 46.252491 6.305554 46.297771 6.242221 46.322392 6.243931 46.357769 6.246387 46.406929 6.328333 46.464149 6.633611 46.432491 6.79611 46.411091 6.808887 46.405499 6.804937 46.352489 6.767499 46.27137 6.844443 46.217758 6.795277 46.142208 6.788054 46.126091 6.884444 46.051929 6.871387 46.065262 6.929166 45.931721 7.038747 45.831379 6.808887 45.780819 6.799166 45.714989 6.824166 45.63998 6.990832 45.518318 6.999443 45.411652 7.181388 45.355549 7.133054 45.301929 7.122776 45.136101 6.850277 45.16832 6.760833 45.110661 6.620172 45.02026 6.746666 44.947762 6.743332 44.848591 7.009999 44.689152 7.068889 44.69915 7.000833 44.6647 6.950832 44.628868 6.960278 44.540821 6.852777 44.507771 6.857222 44.443039 6.934999 44.415821 6.88611 44.323318 6.935832 44.156651 7.279444 44.182758 7.672776 44.072208 7.704166 43.869431 7.492221 43.783451 7.534765 43.758652 7.457388 43.757824 7.4407 43.7603 7.4383 43.7631 7.4358 43.766102 7.4342 43.769199 7.4325 43.7714 7.4294 43.773102 7.4247 43.772499 7.42 43.770599 7.4161 43.768299 7.4128 43.7658 7.4097 43.763599 7.4064 43.761398 7.4031 43.758598 7.4003 43.7561 7.3972 43.753899 7.3939 43.7514 7.3906 43.7486 7.3878 43.745602 7.3864 43.741901 7.3864 43.738899 7.3883 43.735802 7.39 43.732201 7.3908 43.728031 7.391187 43.721825 7.349536 43.720539 7.345833 43.663052 7.15861 43.564159 7.133888 43.558319 7.005278 43.427212 6.854444 43.434711 6.748055 43.31554 6.669722 43.29221 6.589444 43.22443 6.681389 43.16943 6.615 43.197491 6.593888 43.149712 6.375278 43.09277 6.368055 43.12999 6.201943 43.115551 6.166666 43.056381 6.18111 43.05249 6.088611 43.07555 6.126943 43.098049 6.117499 43.133598 5.934722 43.099991 5.911111 43.057491 5.862222 43.082489 5.781111 43.139149 5.780555 43.220829 5.431944 43.221931 5.36361 43.33527 5.361666 43.36665 5.322222 43.34082 5.063611 43.3736 5.012777 43.400829 5.018332 43.464161 5.230555 43.496101 5.227221 43.47694 5.162222 43.55666 5.031388 43.496658 5.016109 43.465549 5.060833 43.430538 5.06111 43.424992 4.957777 43.42387 4.876111 43.373322 4.87361 43.41943 4.756944 43.417488 4.741666 43.37999 4.816388 43.359989 4.821666 43.361931 4.606944 43.37999 4.573333 43.424992 4.601666 43.451408 4.537837 43.455818 4.399444 43.458321 4.321111 43.509708 4.312499 43.49194 4.247222 43.471661 4.240555 43.46138 4.195276 43.498322 4.124722 43.536652 4.133055 43.56332 4.062222 43.484711 3.860555 43.278599 3.471389 43.271099 3.341111 43.084148 3.102222 43.10693 3.043333 43.069149 3.030278 43.05027 3.085278 42.940269 3.037777 42.897209 3.036944 42.84832 2.963889 42.809429 2.975277 42.798038 3.012222 42.878601 3.052499 42.553879 3.049444 42.437611 3.176962 42.433319 3.150833 42.474979 3.038333 42.401649 2.678333 42.338322 2.671111 42.35165 2.476666 42.434711 2.254167 42.363319 2.086944 42.374699 1.976666 42.437199 1.953055 42.490261 1.7875 42.473499 1.710967 42.581661 1.781667 42.65387 1.541111 42.597149 1.435247 42.689701 1.383611 42.841091 0.815833 42.839149 0.667778 42.748039 0.668055 42.689152 0.676111 42.695259 0.4125 42.675819 0.291111 42.71748 0.261944 42.694149 -0.0575 42.757488 -0.123889 42.78582 -0.187778 42.849152 -0.306667 42.796379 -0.392222 42.822208 -0.500833 42.790821 -0.519167 42.863602 -0.656111 42.965542 -0.746944 42.946091 -0.818889 43.071659 -1.300556 43.106091 -1.288333 43.031651 -1.360278 43.048321 -1.440556 43.091091 -1.472778 43.196651 -1.381945 43.273041 -1.409167 43.256378 -1.62 43.309429 -1.655833 43.385891 -1.810488 43.399429 -1.652223 43.561378 -1.493333 43.758881 -1.424445 44.259708 -1.294167 44.62582 -1.208611 44.66193 -1.192222 44.659988 -1.054445 44.683041 -1.037222 44.763599 -1.134444 44.7761 -1.168889 44.630821 -1.248889 44.691929 -1.259167 45.1236 -1.194722 45.552761 -1.095278 45.571381 -1.058333 45.520821 -1.057778 45.36721 -0.808333 45.24749 -0.735833 45.13055 -0.714722 45.0536 -0.661667 44.98666 -0.560556 45.021648 -0.589167 44.998878 -0.495 45.030819 -0.519445 45.060261 -0.62 45.124149 -0.668333 45.400269 -0.737778 45.519161 -0.85 45.70779 -1.245326 45.788052 -1.230834 45.803322 -1.146111 45.71526 -0.985278 45.839989 -1.138056 45.958881 -1.071944 46.006649 -1.111389 46.008598 -1.055556 46.100269 -1.103889 46.15527 -1.152222 46.15527 -1.2025 46.21526 -1.193889 46.258598 -1.105834 46.313599 -1.112222 46.319149 -1.195 46.273319 -1.214445 46.346661 -1.405556 46.338039 -1.448611 46.395821 -1.472222 46.419159 -1.511945 46.451931 -1.673889 46.486931 -1.799445 46.688599 -1.914167 46.813599 -2.108056 46.887211 -2.13389 47.020031 -2.011049 47.034431 -1.984445 47.09721 -2.051667 47.135818 -2.239722 47.165272 -2.163611 47.264992 -2.165556 47.29694 -2.025 47.237209 -1.815834 47.31749 -1.998889 47.30999 -2.159445 47.24165 -2.273334 47.29137 -2.495833 47.2911 -2.4425 47.322491 -2.448612 47.37693 -2.553611 47.40527 -2.396111 47.421101 -2.434167 47.48138 -2.488889 47.504162 -2.361389 47.5261 -2.662222 47.504162 -2.736111 47.49165 -2.809722 47.551659 -2.912222 47.564709 -2.877223 47.54388 -2.736945 47.613041 -2.680556 47.620541 -2.768611 47.606098 -2.88 47.59721 -2.936667 47.56443 -2.960556 47.59943 -3.125278 47.500542 -3.120278 47.521381 -3.149167 47.576649 -3.132223 47.659431 -3.200556 47.741379 -3.148056 47.652489 -3.212778 47.706661 -3.354445 47.78249 -3.281389 47.701382 -3.441389 47.811939 -3.712778 47.793598 -3.847778 47.89888 -3.951111 47.86832 -4.085556 47.881378 -4.182778 47.831928 -4.155556 47.799431 -4.209723 47.802761 -4.361945 47.8536 -4.343889 47.960819 -4.419723 48.022491 -4.529445 48.020821 -4.613056 48.040989 -4.725613 48.073601 -4.662223 48.098881 -4.295 48.178322 -4.297501 48.240551 -4.43139 48.236099 -4.493056 48.176102 -4.537223 48.233601 -4.563612 48.28194 -4.623889 48.30027 -4.513056 48.303879 -4.235001 48.319988 -4.323611 48.357769 -4.318334 48.33054 -4.448611 48.381939 -4.405556 48.427212 -4.293334 48.33527 -4.763889 48.421379 -4.790556 48.545818 -4.744167 48.579708 -4.631945 48.650539 -4.428334 48.670818 -4.314167 48.648319 -4.222778 48.6861 -4.176667 48.73193 -3.968056 48.65221 -3.953333 48.67638 -3.900278 48.629162 -3.854167 48.726101 -3.810833 48.675819 -3.596111 48.6861 -3.571111 48.72665 -3.582778 48.739159 -3.532222 48.76693 -3.580834 48.837212 -3.512778 48.8386 -3.263056 48.870541 -3.220834 48.79388 -3.224167 48.872211 -3.101667 48.826931 -3.079167 48.768879 -2.948611 48.68082 -2.883611 48.654991 -2.824722 48.572208 -2.765556 48.53054 -2.653334 48.62999 -2.464723 48.6926 -2.314336 48.669159 -2.284445 48.62471 -2.329167 48.61137 -2.226389 48.57943 -2.176389 48.646099 -2.105834 48.58305 -2.0025 48.514149 -1.9825 48.550819 -1.956944 48.650829 -2.03 48.709148 -1.849167 48.64999 -1.87 48.615551 -1.840556 48.61665 -1.638056 48.663601 -1.433889 48.744709 -1.560833 48.841099 -1.605834 48.922771 -1.549167 49.01582 -1.556667 49.008881 -1.585278 49.097759 -1.610278 49.219711 -1.549445 49.215549 -1.629445 49.381649 -1.774167 49.377769 -1.8125 49.49971 -1.845834 49.529148 -1.884444 49.57832 -1.84 49.642769 -1.851944 49.675541 -1.945833 49.723881 -1.941945 49.675541 -1.482778 49.70499 -1.410833 49.694439 -1.258333 49.586102 -1.259722 49.57888 -1.299445 49.54388 -1.301667 49.34388 -1.142222 49.394711 -1.013889 49.341099 -0.436389 49.274712 -0.218333 49.426659 0.218333 49.458881 0.393055 49.47694 0.143611 49.511662 0.078056 49.70277 0.184444 49.857491 0.611944 49.948879 1.131111 50.09832 1.435555 50.201931 1.505555 50.21944 1.555 50.184158 1.656944 50.217209 1.645 50.266651 1.548055 50.288601 1.534167 50.359989 1.552778 50.36832 1.610278 50.402489 1.558889 50.612209 1.576944 50.864429 1.576111 50.99527 1.943333 51.070541 2.472777 51.091099 2.541667 50.887211 2.6125 50.824711 2.629444 50.75555 2.781944 50.697048 2.901285</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></tows:geom>
+   </tows:world>
+  </gml:featureMember>
+</wfs:FeatureCollection>
diff --git a/demo/tests/input/wfs10_getfeatures_france_bbox.txt b/demo/tests/input/wfs10_getfeatures_france_bbox.txt
new file mode 100644
index 0000000..7da50bf
--- /dev/null
+++ b/demo/tests/input/wfs10_getfeatures_france_bbox.txt
@@ -0,0 +1 @@
+SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=tows:world&bbox=2,49,3,50
diff --git a/demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri.txt b/demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri.txt
new file mode 100644
index 0000000..9ce1b08
--- /dev/null
+++ b/demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri.txt
@@ -0,0 +1 @@
+SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=tows:world&bbox=222638,6274861,333958,6446275,urn:ogc:def:crs:EPSG::3857
diff --git a/demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt b/demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt
new file mode 100644
index 0000000..15e5023
--- /dev/null
+++ b/demo/tests/input/wfs11_getfeatures_france_bboxwithcrsuri_srsname.txt
@@ -0,0 +1 @@
+SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=tows:world&SRSNAME=urn:ogc:def:crs:EPSG::3857&bbox=222638,6274861,333958,6446275,urn:ogc:def:crs:EPSG::3857
diff --git a/demo/tests/input/wfs11_getfeatures_france_bboxwithoutcrsuri.txt b/demo/tests/input/wfs11_getfeatures_france_bboxwithoutcrsuri.txt
new file mode 100644
index 0000000..ce6d231
--- /dev/null
+++ b/demo/tests/input/wfs11_getfeatures_france_bboxwithoutcrsuri.txt
@@ -0,0 +1 @@
+SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=tows:world&bbox=49,2,50,3

From f40765ac3ade9a2d722d4228b271cce32455519e Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Fri, 27 Nov 2020 17:07:57 +0100
Subject: [PATCH 28/30] Fix build with -DOWS_DEBUG

---
 src/ows/ows_layer.c   | 4 ++--
 src/wfs/wfs_request.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ows/ows_layer.c b/src/ows/ows_layer.c
index 582bb39..4f881db 100644
--- a/src/ows/ows_layer.c
+++ b/src/ows/ows_layer.c
@@ -672,13 +672,13 @@ void ows_layer_flush(ows_layer * l, FILE * output)
 
   if(l->pkey) {
     fprintf(output, "pkey: ");
-    list_flush(l->pkey, output);
+    buffer_flush(l->pkey, output);
     fprintf(output, "\n");
   }
 
   if(l->pkey_sequence) {
     fprintf(output, "pkey_sequence: ");
-    list_flush(l->pkey_sequence, output);
+    buffer_flush(l->pkey_sequence, output);
     fprintf(output, "\n");
   }
 }
diff --git a/src/wfs/wfs_request.c b/src/wfs/wfs_request.c
index 8b69d3e..001fd52 100644
--- a/src/wfs/wfs_request.c
+++ b/src/wfs/wfs_request.c
@@ -153,7 +153,7 @@ void wfs_request_flush(wfs_request * wr, FILE * output)
 
   if (wr->callback) {
     fprintf(output, " callback -> ");
-    list_flush(wr->callback, output);
+    buffer_flush(wr->callback, output);
     fprintf(output, "\n");
   }
 

From 99e30478cee16062de563f6411cf7acc805f9451 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Fri, 27 Nov 2020 18:18:59 +0100
Subject: [PATCH 29/30] Transaction support: handle srsName in wfs:Insert w.r.t
 axis swapping

---
 .github/workflows/linux.sh                    |  1 +
 demo/check.sh                                 | 43 ++++++++++++++++++-
 .../input/wfst10_france_insert.xml            | 30 +++++++++++++
 .../input/wfst10_world_insert.xml             | 30 +++++++++++++
 .../input/wfst11_france_insert.xml            | 30 +++++++++++++
 .../input/wfst11_world_insert.xml             | 30 +++++++++++++
 ...st11_world_insert_srsname_in_wfsinsert.xml | 30 +++++++++++++
 demo/tinyows_no_checkschema.xml               | 24 +++++++++++
 src/fe/fe_spatial_ops.c                       | 28 +++++++++---
 src/ows/ows_psql.c                            | 39 +++++++++++++++--
 src/ows_api.h                                 |  2 +-
 src/wfs/wfs_transaction.c                     | 25 ++++++-----
 12 files changed, 290 insertions(+), 22 deletions(-)
 create mode 100644 demo/tests/transactions/input/wfst10_france_insert.xml
 create mode 100644 demo/tests/transactions/input/wfst10_world_insert.xml
 create mode 100644 demo/tests/transactions/input/wfst11_france_insert.xml
 create mode 100644 demo/tests/transactions/input/wfst11_world_insert.xml
 create mode 100644 demo/tests/transactions/input/wfst11_world_insert_srsname_in_wfsinsert.xml
 create mode 100644 demo/tinyows_no_checkschema.xml

diff --git a/.github/workflows/linux.sh b/.github/workflows/linux.sh
index fc1e38c..3258446 100755
--- a/.github/workflows/linux.sh
+++ b/.github/workflows/linux.sh
@@ -22,6 +22,7 @@ echo "host all all 127.0.0.1/32 trust" |  cat - /etc/postgresql/12/main/pg_hba.c
 /etc/init.d/postgresql start
 
 make install-demo
+cp -f demo/tinyows_no_checkschema.xml /etc/tinyows.xml
 make check
 
 # wget https://github.com/MapServer/tinyows/commit/633ca487113d032e261a4a5c8b5f3b7850580f4f.patch
diff --git a/demo/check.sh b/demo/check.sh
index be80d00..6cd38ad 100755
--- a/demo/check.sh
+++ b/demo/check.sh
@@ -4,6 +4,9 @@ set -eu
 
 RET=0
 
+PGUSER=postgres
+DB=tinyows_demo
+
 for i in demo/tests/input/*; do
     echo "Running $i"
     QUERY_STRING="$(cat $i)" ./tinyows > /tmp/output.txt
@@ -19,6 +22,44 @@ if test "$RET" -eq "0"; then
     echo "Tests OK !"
 else
     echo "Tests failed !"
+    exit $RET
 fi
 
-exit $RET
\ No newline at end of file
+i=demo/tests/transactions/input/wfst10_france_insert.xml
+echo "Running $i"
+QUERY_STRING="$(cat $i)" ./tinyows > /tmp/output.txt || (cat /tmp/output.txt && /bin/false)
+cat /tmp/output.txt | grep SUCCESS || (cat /tmp/output.txt && /bin/false)
+echo "select st_astext(geom) from france where id_geofla = -1234;" | su $PGUSER -c "psql -t $DB" | grep "MULTIPOLYGON(((2171610 802820,2171611 802820,2171611 802821,2171610 802820)))"
+echo "delete from france where id_geofla = -1234" | su $PGUSER -c "psql $DB"
+
+
+i=demo/tests/transactions/input/wfst10_world_insert.xml
+echo "Running $i"
+QUERY_STRING="$(cat $i)" ./tinyows > /tmp/output.txt || (cat /tmp/output.txt && /bin/false)
+cat /tmp/output.txt | grep SUCCESS || (cat /tmp/output.txt && /bin/false)
+echo "select st_astext(geom) from world where name = '-1234';" | su $PGUSER -c "psql -t $DB" | grep "MULTIPOLYGON(((2 49,2 50,3 50,2 49)))"
+echo "delete from world where name = '-1234'" | su $PGUSER -c "psql $DB"
+
+
+i=demo/tests/transactions/input/wfst11_france_insert.xml
+echo "Running $i"
+QUERY_STRING="$(cat $i)" ./tinyows > /tmp/output.txt || (cat /tmp/output.txt && /bin/false)
+cat /tmp/output.txt | grep "<wfs:totalInserted>1</wfs:totalInserted>" || (cat /tmp/output.txt && /bin/false)
+echo "select st_astext(geom) from france where id_geofla = -1234;" | su $PGUSER -c "psql -t $DB" | grep "MULTIPOLYGON(((2171610 802820,2171611 802820,2171611 802821,2171610 802820)))"
+echo "delete from france where id_geofla = -1234" | su $PGUSER -c "psql $DB"
+
+
+i=demo/tests/transactions/input/wfst11_world_insert.xml
+echo "Running $i"
+QUERY_STRING="$(cat $i)" ./tinyows > /tmp/output.txt || (cat /tmp/output.txt && /bin/false)
+cat /tmp/output.txt | grep "<wfs:totalInserted>1</wfs:totalInserted>" || (cat /tmp/output.txt && /bin/false)
+echo "select st_astext(geom) from world where name = '-1234';" | su $PGUSER -c "psql -t $DB" | grep "MULTIPOLYGON(((2 49,2 50,3 50,2 49)))"
+echo "delete from world where name = '-1234'" | su $PGUSER -c "psql $DB"
+
+
+i=demo/tests/transactions/input/wfst11_world_insert_srsname_in_wfsinsert.xml
+echo "Running $i"
+QUERY_STRING="$(cat $i)" ./tinyows > /tmp/output.txt || (cat /tmp/output.txt && /bin/false)
+cat /tmp/output.txt | grep "<wfs:totalInserted>1</wfs:totalInserted>" || (cat /tmp/output.txt && /bin/false)
+echo "select st_astext(geom) from world where name = '-1234';" | su $PGUSER -c "psql -t $DB" | grep "MULTIPOLYGON(((2 49,2 50,3 50,2 49)))"
+echo "delete from world where name = '-1234'" | su $PGUSER -c "psql $DB"
diff --git a/demo/tests/transactions/input/wfst10_france_insert.xml b/demo/tests/transactions/input/wfst10_france_insert.xml
new file mode 100644
index 0000000..3d1a81b
--- /dev/null
+++ b/demo/tests/transactions/input/wfst10_france_insert.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"
+                 xmlns:tows="http://www.tinyows.org/"
+                 xmlns:xlink="http://www.w3.org/1999/xlink"
+                 xmlns:gml="http://www.opengis.net/gml"
+                 xmlns:ogc="http://www.opengis.net/ogc"
+                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                 xsi:schemaLocation="http://www.tinyows.org/ http://127.0.0.1/cgi-bin/tinyows?service=wfs&amp;version=1.0.0&amp;request=describefeaturetype&amp;typename=tows:france"
+                 service="WFS"
+                 version="1.0.0">
+  <wfs:Insert>
+    <tows:france>
+      <tows:id_geofla>-1234</tows:id_geofla>
+      <tows:geom>
+        <gml:MultiPolygon srsName="EPSG:27582">
+          <gml:polygonMember>
+            <gml:Polygon>
+              <gml:outerBoundaryIs>
+                <gml:LinearRing>
+                  <gml:coordinates>2171610,802820 2171611,802820 2171611,802821 2171610,802820</gml:coordinates>
+                </gml:LinearRing>
+              </gml:outerBoundaryIs>
+            </gml:Polygon>
+          </gml:polygonMember>
+        </gml:MultiPolygon>
+      </tows:geom>
+    </tows:france>
+  </wfs:Insert>
+</wfs:Transaction>
diff --git a/demo/tests/transactions/input/wfst10_world_insert.xml b/demo/tests/transactions/input/wfst10_world_insert.xml
new file mode 100644
index 0000000..939df53
--- /dev/null
+++ b/demo/tests/transactions/input/wfst10_world_insert.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"
+                 xmlns:tows="http://www.tinyows.org/"
+                 xmlns:xlink="http://www.w3.org/1999/xlink"
+                 xmlns:gml="http://www.opengis.net/gml"
+                 xmlns:ogc="http://www.opengis.net/ogc"
+                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                 xsi:schemaLocation="http://www.tinyows.org/ http://127.0.0.1/cgi-bin/tinyows?service=wfs&amp;version=1.0.0&amp;request=describefeaturetype&amp;typename=tows:world"
+                 service="WFS"
+                 version="1.0.0">
+  <wfs:Insert>
+    <tows:world>
+      <tows:name>-1234</tows:name>
+      <tows:geom>
+        <gml:MultiPolygon srsName="EPSG:4326">
+          <gml:polygonMember>
+            <gml:Polygon>
+              <gml:outerBoundaryIs>
+                <gml:LinearRing>
+                  <gml:coordinates>2,49 2,50 3,50 2,49</gml:coordinates>
+                </gml:LinearRing>
+              </gml:outerBoundaryIs>
+            </gml:Polygon>
+          </gml:polygonMember>
+        </gml:MultiPolygon>
+      </tows:geom>
+    </tows:world>
+  </wfs:Insert>
+</wfs:Transaction>
diff --git a/demo/tests/transactions/input/wfst11_france_insert.xml b/demo/tests/transactions/input/wfst11_france_insert.xml
new file mode 100644
index 0000000..519afc5
--- /dev/null
+++ b/demo/tests/transactions/input/wfst11_france_insert.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"
+                 xmlns:tows="http://www.tinyows.org/"
+                 xmlns:xlink="http://www.w3.org/1999/xlink"
+                 xmlns:gml="http://www.opengis.net/gml"
+                 xmlns:ogc="http://www.opengis.net/ogc"
+                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                 xsi:schemaLocation="http://www.tinyows.org/ http://127.0.0.1/cgi-bin/tinyows?service=wfs&amp;version=1.1.0&amp;request=describefeaturetype&amp;typename=tows:france"
+                 service="WFS"
+                 version="1.1.0">
+  <wfs:Insert>
+    <tows:france>
+      <tows:id_geofla>-1234</tows:id_geofla>
+      <tows:geom>
+        <gml:MultiPolygon srsName="urn:ogc:def:crs:EPSG::27582">
+          <gml:polygonMember>
+            <gml:Polygon>
+              <gml:outerBoundaryIs>
+                <gml:LinearRing>
+                  <gml:coordinates>2171610,802820 2171611,802820 2171611,802821 2171610,802820</gml:coordinates>
+                </gml:LinearRing>
+              </gml:outerBoundaryIs>
+            </gml:Polygon>
+          </gml:polygonMember>
+        </gml:MultiPolygon>
+      </tows:geom>
+    </tows:france>
+  </wfs:Insert>
+</wfs:Transaction>
diff --git a/demo/tests/transactions/input/wfst11_world_insert.xml b/demo/tests/transactions/input/wfst11_world_insert.xml
new file mode 100644
index 0000000..2577f11
--- /dev/null
+++ b/demo/tests/transactions/input/wfst11_world_insert.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"
+                 xmlns:tows="http://www.tinyows.org/"
+                 xmlns:xlink="http://www.w3.org/1999/xlink"
+                 xmlns:gml="http://www.opengis.net/gml"
+                 xmlns:ogc="http://www.opengis.net/ogc"
+                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                 xsi:schemaLocation="http://www.tinyows.org/ http://127.0.0.1/cgi-bin/tinyows?service=wfs&amp;version=1.1.0&amp;request=describefeaturetype&amp;typename=tows:world"
+                 service="WFS"
+                 version="1.1.0">
+  <wfs:Insert>
+    <tows:world>
+      <tows:name>-1234</tows:name>
+      <tows:geom>
+        <gml:MultiPolygon srsName="urn:ogc:def:crs:EPSG::4326">
+          <gml:polygonMember>
+            <gml:Polygon>
+              <gml:outerBoundaryIs>
+                <gml:LinearRing>
+                  <gml:coordinates>49,2 50,2 50,3 49,2</gml:coordinates>
+                </gml:LinearRing>
+              </gml:outerBoundaryIs>
+            </gml:Polygon>
+          </gml:polygonMember>
+        </gml:MultiPolygon>
+      </tows:geom>
+    </tows:world>
+  </wfs:Insert>
+</wfs:Transaction>
diff --git a/demo/tests/transactions/input/wfst11_world_insert_srsname_in_wfsinsert.xml b/demo/tests/transactions/input/wfst11_world_insert_srsname_in_wfsinsert.xml
new file mode 100644
index 0000000..66866f3
--- /dev/null
+++ b/demo/tests/transactions/input/wfst11_world_insert_srsname_in_wfsinsert.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"
+                 xmlns:tows="http://www.tinyows.org/"
+                 xmlns:xlink="http://www.w3.org/1999/xlink"
+                 xmlns:gml="http://www.opengis.net/gml"
+                 xmlns:ogc="http://www.opengis.net/ogc"
+                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                 xsi:schemaLocation="http://www.tinyows.org/ http://127.0.0.1/cgi-bin/tinyows?service=wfs&amp;version=1.1.0&amp;request=describefeaturetype&amp;typename=tows:world"
+                 service="WFS"
+                 version="1.1.0">
+  <wfs:Insert srsName="urn:ogc:def:crs:EPSG::4326">
+    <tows:world>
+      <tows:name>-1234</tows:name>
+      <tows:geom>
+        <gml:MultiPolygon>
+          <gml:polygonMember>
+            <gml:Polygon>
+              <gml:outerBoundaryIs>
+                <gml:LinearRing>
+                  <gml:coordinates>49,2 50,2 50,3 49,2</gml:coordinates>
+                </gml:LinearRing>
+              </gml:outerBoundaryIs>
+            </gml:Polygon>
+          </gml:polygonMember>
+        </gml:MultiPolygon>
+      </tows:geom>
+    </tows:world>
+  </wfs:Insert>
+</wfs:Transaction>
diff --git a/demo/tinyows_no_checkschema.xml b/demo/tinyows_no_checkschema.xml
new file mode 100644
index 0000000..1ec6237
--- /dev/null
+++ b/demo/tinyows_no_checkschema.xml
@@ -0,0 +1,24 @@
+<tinyows online_resource="http://127.0.0.1/cgi-bin/tinyows"
+	 schema_dir="/usr/local/share/tinyows/schema/"
+	 check_schema="0">
+
+  <pg host="127.0.0.1" user="postgres" password="postgres" dbname="tinyows_demo" port="5432"/>
+
+  <metadata name="TinyOWS Server"
+	    title="TinyOWS Server - Demo Service" />
+
+  <layer retrievable="1"
+	 writable="1"
+	 ns_prefix="tows"
+	 ns_uri="http://www.tinyows.org/"
+         name="world"
+         title="World Administrative Boundaries" />
+
+  <layer retrievable="1"
+	 writable="1"
+	 ns_prefix="tows"
+	 ns_uri="http://www.tinyows.org/"
+         name="france"
+         title="French Administrative Sub Boundaries (IGN - GeoFLA Departements)" />
+
+</tinyows>
diff --git a/src/fe/fe_spatial_ops.c b/src/fe/fe_spatial_ops.c
index 6e4f10b..e981192 100644
--- a/src/fe/fe_spatial_ops.c
+++ b/src/fe/fe_spatial_ops.c
@@ -233,7 +233,8 @@ static buffer *fe_spatial_functions(ows * o, buffer * typename, filter_encoding
   buffer *geom, *layer_name;
   xmlNodePtr p;
   xmlChar *srsname;
-  int srid = -1;
+  ows_srs* parent_srs = NULL;
+  bool free_parent_srs = false;
 
   assert(typename);
   assert(fe);
@@ -260,11 +261,20 @@ static buffer *fe_spatial_functions(ows * o, buffer * typename, filter_encoding
   /* jump to the next element if there are spaces */
   while (n->type != XML_ELEMENT_NODE) n = n->next;
 
-  if (o->request->request.wfs->srs) srid = o->request->request.wfs->srs->srid;
-  else srid = ows_srs_get_srid_from_layer(o, layer_name);
+  if (o->request->request.wfs->srs) {
+    parent_srs = o->request->request.wfs->srs;
+  }
+  else {
+    int srid = ows_srs_get_srid_from_layer(o, layer_name);
+    if (srid > 0) {
+      parent_srs = ows_srs_init();
+      ows_srs_set_from_srid(o, parent_srs, srid);
+      free_parent_srs = true;
+    }
+  }
 
   if (!strcmp((char *) n->name, "Box") || !strcmp((char *) n->name, "Envelope")) {
-
+    int srid = -1;
     srsname = xmlGetProp(n, (xmlChar *) "srsName");
     if (srsname) {
       s = ows_srs_init();
@@ -287,9 +297,12 @@ static buffer *fe_spatial_functions(ows * o, buffer * typename, filter_encoding
     } else fe->sql = fe_envelope(o, typename, fe, fe->sql, n);
 
   } else  {
-    geom = ows_psql_gml_to_sql(o, n, srid);
+    int srid;
+    geom = ows_psql_gml_to_sql(o, n, parent_srs);
     if (!geom) {
       fe->error_code = FE_ERROR_GEOMETRY;
+      if (free_parent_srs)
+        ows_srs_free(parent_srs);
       return fe->sql;
     }
 
@@ -319,6 +332,9 @@ static buffer *fe_spatial_functions(ows * o, buffer * typename, filter_encoding
 
   buffer_add(fe->sql, ')');
 
+  if (free_parent_srs)
+    ows_srs_free(parent_srs);
+
   return fe->sql;
 }
 
@@ -370,7 +386,7 @@ static buffer *fe_distance_functions(ows * o, buffer * typename, filter_encoding
     buffer_add_str(fe->sql, "ST_Transform(");
 
   /* display the geometry */
-  sql = ows_psql_gml_to_sql(o, n, 0);
+  sql = ows_psql_gml_to_sql(o, n, NULL);
   if (sql) {
     buffer_copy(fe->sql, sql);
     buffer_free(sql);
diff --git a/src/ows/ows_psql.c b/src/ows/ows_psql.c
index ebc6dae..cc6076c 100644
--- a/src/ows/ows_psql.c
+++ b/src/ows/ows_psql.c
@@ -752,11 +752,12 @@ static xmlNodePtr ows_psql_recursive_parse_gml(ows * o, xmlNodePtr n, xmlNodePtr
  * Transform a GML geometry to PostGIS EWKT
  * Return NULL on error
  */
-buffer * ows_psql_gml_to_sql(ows * o, xmlNodePtr n, int srid)
+buffer * ows_psql_gml_to_sql(ows * o, xmlNodePtr n, const ows_srs* parent_srs)
 {
   PGresult *res;
   xmlNodePtr g;
   buffer *result, *sql, *gml;
+  ows_srs* srs_geom = NULL;
 
   assert(o);
   assert(n);
@@ -764,22 +765,52 @@ buffer * ows_psql_gml_to_sql(ows * o, xmlNodePtr n, int srid)
   g = ows_psql_recursive_parse_gml(o, n, NULL);
   if (!g) return NULL;    /* No Geometry founded in GML doc */
 
+  /* Look for a srsName attribute on the geometry itself */
+  if (xmlHasProp(g, (xmlChar *) "srsName")) {
+    xmlChar* attr =  xmlGetProp(g, (xmlChar *) "srsName");
+    srs_geom = ows_srs_init();
+
+    if (!ows_srs_set_from_srsname(o, srs_geom, (char *) attr)) {
+      ows_srs_free(srs_geom);
+      xmlFree(attr);
+      return NULL;
+    }
+
+    xmlFree(attr);
+  }
+
   /* Retrieve the sub doc and launch GML parse via PostGIS */
   gml = buffer_init();
   cgi_add_xml_into_buffer(gml, g);
 
   sql = buffer_init();
-  buffer_add_str(sql, "SELECT ST_GeomFromGML('");
+  buffer_add_str(sql, "SELECT ");
+  if (srs_geom == NULL && parent_srs != NULL &&
+      parent_srs->honours_authority_axis_order &&
+      !parent_srs->is_axis_order_gis_friendly) {
+      buffer_add_str(sql, "ST_FlipCoordinates(");
+  }
+  /* ST_GeomFromGML handles the axis swapping if the geometry has a srsName */
+  buffer_add_str(sql, "ST_GeomFromGML('");
   buffer_add_str(sql, gml->buf);
 
-  if (ows_version_get(o->postgis_version) >= 200) {
+  if (ows_version_get(o->postgis_version) >= 200 &&
+                        (srs_geom != NULL || parent_srs != NULL)) {
     buffer_add_str(sql, "',");
-    buffer_add_int(sql, srid);
+    buffer_add_int(sql, srs_geom ? srs_geom->srid : parent_srs->srid);
     buffer_add_str(sql, ")");
   } else {
     /* Means PostGIS 1.5 */
     buffer_add_str(sql, "')");
   }
+  if (srs_geom == NULL && parent_srs != NULL &&
+      parent_srs->honours_authority_axis_order &&
+      !parent_srs->is_axis_order_gis_friendly) {
+      /* Close ST_FlipCoordinates */
+      buffer_add_str(sql, ")");
+  }
+
+  if (srs_geom) ows_srs_free(srs_geom);
 
   res = ows_psql_exec(o, sql->buf);
   buffer_free(gml);
diff --git a/src/ows_api.h b/src/ows_api.h
index f887844..01e21db 100644
--- a/src/ows_api.h
+++ b/src/ows_api.h
@@ -195,7 +195,7 @@ bool ows_psql_is_numeric(buffer * type);
 buffer *ows_psql_type (ows * o, buffer * layer_name, buffer * property);
 buffer *ows_psql_generate_id (ows * o, buffer * layer_name);
 int ows_psql_number_features(ows * o, list * from, list * where);
-buffer * ows_psql_gml_to_sql(ows * o, xmlNodePtr n, int srid);
+buffer * ows_psql_gml_to_sql(ows * o, xmlNodePtr n, const ows_srs* parent_srs);
 char *ows_psql_escape_string(ows *o, const char *content);
 int ows_psql_geometry_srid(ows *o, const char *geom);
 void ows_request_check (ows * o, ows_request * or, const array * cgi, const char *query);
diff --git a/src/wfs/wfs_transaction.c b/src/wfs/wfs_transaction.c
index a777e4f..0fc570d 100644
--- a/src/wfs/wfs_transaction.c
+++ b/src/wfs/wfs_transaction.c
@@ -324,8 +324,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
   array * table;
   char *escaped;
   list *l;
-  ows_srs * srs_root;
-  int srid_root = 0;
+  ows_srs * srs_root = NULL;
   xmlChar *attr = NULL;
   enum wfs_insert_idgen idgen = WFS_GENERATE_NEW;
   enum wfs_insert_idgen handle_idgen = WFS_GENERATE_NEW;
@@ -377,8 +376,6 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
       return result;
     }
 
-    srid_root = srs_root->srid;
-    ows_srs_free(srs_root);
     xmlFree(attr);
     attr = NULL;
   }
@@ -407,6 +404,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
       buffer_free(values);
       buffer_free(handle);
       if (layer_name) buffer_free(layer_name);
+      if (srs_root) ows_srs_free(srs_root);
       result = buffer_from_str("Error unknown or not writable Layer Name");
       return result;
     }
@@ -433,6 +431,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
       buffer_free(sql);
       buffer_free(values);
       buffer_free(layer_name);
+      if (srs_root) ows_srs_free(srs_root);
       result = buffer_from_str("Error unknown Layer Name or not id column available");
       return result;
     }
@@ -556,6 +555,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
                 buffer_free(column);
                 buffer_free(id);
                 filter_encoding_free(fe);
+                if (srs_root) ows_srs_free(srs_root);
                 return result;
               }
               buffer_copy(values, fe->sql);
@@ -564,7 +564,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
             } else if (!strcmp((char *) elemt->name, "Null")) {
               buffer_add_str(values, "''");
             } else {
-              gml = ows_psql_gml_to_sql(o, elemt, srid_root);
+              gml = ows_psql_gml_to_sql(o, elemt, srs_root);
               if (gml) {
                 buffer_add_str(values, "'");
                 buffer_copy(values, gml);
@@ -576,6 +576,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
                 buffer_free(column);
                 buffer_free(id);
                 buffer_free(layer_name);
+                if (srs_root) ows_srs_free(srs_root);
 
                 result = buffer_from_str("Error invalid Geometry");
                 return result;
@@ -613,6 +614,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
     result = wfs_execute_transaction_request(o, wr, sql);
     if (!buffer_cmp(result, "PGRES_COMMAND_OK")) {
       buffer_free(sql);
+      if (srs_root) ows_srs_free(srs_root);
       return result;
     }
     buffer_empty(sql);
@@ -620,6 +622,7 @@ static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
   }
 
   buffer_free(sql);
+  if (srs_root) ows_srs_free(srs_root);
 
   return result;
 }
@@ -828,8 +831,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
   xmlChar *content;
   char *escaped;
   array *table;
-  ows_srs *srs_root;
-  int srid_root = 0;
+  ows_srs *srs_root = NULL;
   xmlChar *attr = NULL;
   list *l;
 
@@ -857,8 +859,6 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
       return result;
     }
 
-    srid_root = srs_root->srid;
-    ows_srs_free(srs_root);
     xmlFree(attr);
     attr = NULL;
   }
@@ -874,6 +874,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
   if (!layer_name || !s || !t) {
     if (typename) buffer_free(typename);
     buffer_free(sql);
+    if (srs_root) ows_srs_free(srs_root);
     result = buffer_from_str("Typename provided is unknown or not writable");
     return result;
   }
@@ -958,6 +959,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
                 buffer_free(typename);
                 buffer_free(property_name);
                 filter_encoding_free(fe);
+                if (srs_root) ows_srs_free(srs_root);
                 return result;
               }
 
@@ -967,7 +969,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
             } else if (!strcmp((char *) elemt->name, "Null")) {
               buffer_add_str(values, "''");
             } else {
-              gml = ows_psql_gml_to_sql(o, elemt, srid_root);
+              gml = ows_psql_gml_to_sql(o, elemt, srs_root);
               if (gml) {
                 buffer_add_str(values, "'");
                 buffer_copy(values, gml);
@@ -978,6 +980,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
                 buffer_free(typename);
                 buffer_free(property_name);
                 buffer_free(sql);
+                if (srs_root) ows_srs_free(srs_root);
                 result = buffer_from_str("Invalid GML Geometry");
                 return result;
               }
@@ -1005,6 +1008,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
           buffer_free(values);
           buffer_free(sql);
           buffer_free(typename);
+          if (srs_root) ows_srs_free(srs_root);
           return result;
 
         } else {
@@ -1026,6 +1030,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
 
   buffer_free(typename);
   buffer_free(sql);
+  if (srs_root) ows_srs_free(srs_root);
 
   return result;
 }

From 2852676ba5f485d8ac73be4814a5decf9ac770d5 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Sun, 29 Nov 2020 18:50:52 +0100
Subject: [PATCH 30/30] 
 ows_srs_set_is_geographic_and_is_axis_order_gis_friendly_from_def(): improve
 tests

---
 src/ows/ows_srs.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/ows/ows_srs.c b/src/ows/ows_srs.c
index 6daea4c..0361182 100644
--- a/src/ows/ows_srs.c
+++ b/src/ows/ows_srs.c
@@ -140,19 +140,31 @@ static void ows_srs_set_is_geographic_and_is_axis_order_gis_friendly_from_def(
             *ptr = '\0';
 
         s->is_axis_order_gis_friendly = true;
-        s->is_geographic = strstr(srtext, "PROJCS[") == NULL &&
-                           strstr(srtext, "GEOCCS[") == NULL;
+        s->is_geographic = (strstr(srtext, "PROJCS[") == NULL &&
+                            strstr(srtext, "GEOCCS[") == NULL &&
+                            strstr(srtext, "BOUNDCRS[") == NULL) ||
+                           strstr(srtext, "BOUNDCRS[SOURCECRS[GEOGCRS") != NULL;
 
-        if( strstr(srtext_horizontal, "AXIS[") == NULL )
+        if( strstr(srtext_horizontal, "AXIS[") == NULL &&
+            strstr(srtext_horizontal, "GEOCCS[") == NULL )
         {
             /* If there is no axis definition, then due to how GDAL < 3
-             * generated the WKT, this means that the axis order is not
-             * GIS friendly */
+            * generated the WKT, this means that the axis order is not
+            * GIS friendly */
             s->is_axis_order_gis_friendly = false;
         }
-        /* In case PostGIS incorporates full WKT output some day... */
         else if( strstr(srtext_horizontal,
-                   "AXIS[\"Northing\",NORTH],AXIS[\"Easting\",EAST]") != NULL )
+                    "AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST]") != NULL )
+        {
+            s->is_axis_order_gis_friendly = false;
+        }
+        else if( strstr(srtext_horizontal,
+                    "AXIS[\"Northing\",NORTH],AXIS[\"Easting\",EAST]") != NULL )
+        {
+            s->is_axis_order_gis_friendly = false;
+        }
+        else if( strstr(srtext_horizontal,
+                    "AXIS[\"geodetic latitude (Lat)\",north,ORDER[1]") != NULL )
         {
             s->is_axis_order_gis_friendly = false;
         }
openSUSE Build Service is sponsored by