OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.8k stars 2.52k forks source link

gml writer: FeatureCollection's envelope SRS (3.9.1 regression) #10332

Closed cyril1929 closed 2 months ago

cyril1929 commented 3 months ago

What is the bug?

When we produce a GML from a GeoJson with a SQL dialect, the gml:Envelope in the response no longer contains SRS.

The srs is however always present if no sql query is put.

By the way, not having srs reverses the axes.

I don't think this change in behavior was intentional?

Steps to reproduce the issue

ogr2ogr -sql "SELECT * FROM input" -dialect sqlite -f GML output.gml input.json

return :

...
<gml:boundedBy>
    <gml:Envelope>
        <gml:lowerCorner>0 -1369</gml:lowerCorner>
        <gml:upperCorner>1138 -1</gml:upperCorner>
    </gml:Envelope>
</gml:boundedBy>
...

while :

ogr2ogr -sql "" -dialect sqlite -f GML output.gml input.json

return :

...
<gml:boundedBy>
    <gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326">
        <gml:lowerCorner>-1369 0</gml:lowerCorner>
        <gml:upperCorner>-1 1138</gml:upperCorner>
    </gml:Envelope>
</gml:boundedBy>
...

Versions and provenance

The regression appeared in version 3.9.1. No worries in version 3.9.0 and earlier.

Additional context

No response

jratike80 commented 3 months ago

I can confirm with GDAL 3.10.0dev-a44e40295c, released 2024/06/21 (OSGeo4W).

Also the name of the geometry has changed. Was: <ogr:geometryProperty> Is now: <ogr:GEOMETRY>

This srsName drop affects the FeatureCollection level Envelope. The featureMembers still have Envelopes with srsName - and with Lat-Lon axis order.

<ogr:FeatureCollection
     gml:id="aFeatureCollection"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ogr.maptools.org/ srs3.xsd"
     xmlns:ogr="http://ogr.maptools.org/"
     xmlns:gml="http://www.opengis.net/gml/3.2">
  <gml:boundedBy><gml:Envelope><gml:lowerCorner>23.5343338 63.1870744</gml:lowerCorner><gml:upperCorner>23.5511729 63.1915115</gml:upperCorner></gml:Envelope></gml:boundedBy>

  <ogr:featureMember>
    <ogr:SELECT gml:id="SELECT.0">
      <gml:boundedBy><gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326"><gml:lowerCorner>63.1870744 23.5454641</gml:lowerCorner><gml:upperCorner>63.1871252 23.5455768</gml:upperCorner></gml:Envelope></gml:boundedBy>
rouault commented 3 months ago

Also the name of the geometry has changed.

That's expected ant not an issue, and not a new behaviour. This is due to SQL SQLite layer reporting a name GEOMETRY geometry field. Direct translation from GeoJSON which has a unnamed/empty geometry field fallbacks to using "geometryProperty" in the GML writer.

For the SRS issue, fix in #10334

A workaround is to do a ogr2ogr to a format like GeoJSON (or shapefile, but not GeoPackage, PostGIS, etc) that has not a named geometry field using the -sql clause, and then ogr2ogr that temporary GeoJSON file to GML

cyril1929 commented 2 months ago

Thanks !