Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CRS in WMS GetFeatureInfo when info_format is in json Fixes #32326 #32386

Merged
merged 11 commits into from
Oct 31, 2019

Conversation

pblottiere
Copy link
Member

Description

Fixes #32326

src/core/qgsjsonutils.h Outdated Show resolved Hide resolved
@pblottiere pblottiere added Bug Either a bug report, or a bug fix. Let's hope for the latter! Server Related to QGIS server labels Oct 24, 2019
@nyalldawson nyalldawson added this to the 3.12.0 milestone Oct 27, 2019
@jgrocha
Copy link
Member

jgrocha commented Oct 27, 2019

Good work @pblottiere

The good news

Tested locally and it works perfectly with INFO_FORMAT=application/json and CRS=EPSG:3763. The project was in CRS=EPSG:3763.

Not so good news

It is odd, but the same project, if I request INFO_FORMAT=application/json and CRS=EPSG:3857 the result goes to the north pole. If I request INFO_FORMAT=text/xml the result is fine.

To reproduce

Using the previous project stored in the gfi.gpkg (and running with your PR):

export QGIS_PROJECT_FILE="geopackage:/home/qgis/projects/gfi.gpkg?projectName=testgfi"
export QUERY_STRING="SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image/png&TRANSPARENT=true&tiled=false&STYLES=default&LAYERS=freguesias&CRS=EPSG:3857&WIDTH=512&HEIGHT=512&BBOX=-953087.8,4973324.9,-952748.9,4973612.8&QUERY_LAYERS=freguesias&INFO_FORMAT=application/json&FEATURE_COUNT=50&WITH_GEOMETRY=True&I=222&J=127"
./build-QGIS-Desktop-Debug/output/bin/qgis_mapserv.fcgi

The request uses EPSG:3857 coordinates, around -953 087, 4 973 324.

The coordinates in JSON are around -7 194 793, 15 428 040.

{
  "features": [
    {
      "bbox": [
        -7202100.975262,
        15370117.593422,
        -7179015.488842,
        15428040.830143001
      ],
      "geometry": {
        "coordinates": [
          [
            [
              [
                -7194793.711287,
                15428040.830143001
              ],
              [
                -7194757.735689,
                15428031.546399
              ],

I've attached the resulting file x.json. If you open it with QGIS (and assign the EPSG:3857), it goes to the north pole.

Unless it is a local issue (or my mistake), when the output is json, the conversion might not work as expected.

@pblottiere
Copy link
Member Author

Hi @jgrocha,

It is odd, but the same project, if I request INFO_FORMAT=application/json and CRS=EPSG:3857 the result goes to the north pole. If I request INFO_FORMAT=text/xml the result is fine.

Ah yes, I forgot the second part of your issue, sorry for that.

The request uses EPSG:3857 coordinates, around -953 087, 4 973 324.
The coordinates in JSON are around -7 194 793, 15 428 040.

I think it's fixed now. In both cases we have the same coordinates (excepted for the precision which is slightly different).

INFO_FORMAT=text/xml and CRS=EPSG:3857

value="MultiPolygon (((-949439.66200299 4977488.4941173, -949437.44500259 4977482.21731793, -949437.14610265 4977465.63576632, ....

INFO_FORMAT=application/json and CRS=EPSG:3857

"geometry":{"coordinates":[[[[-949439.662003,4977488.494117],[-949437.445003,4977482.217318],[-949437.146103,4977465.635766],

Can you take a look locally with your own project to make sure that everything is OK please?

@jgrocha
Copy link
Member

jgrocha commented Oct 28, 2019

Hi @pblottiere,

Thanks for keeping working on this PR. The example with EPSG:3857 is working now. Nice work!

But... but we still have issues with CRS transformations. I've made a request with EPSG:4326 coordinates and the result is an empty image. The GetMap fails (and GetFeatureInfo as well).

Please test it, because it might be my fault.

For the very same project:

export QUERY_STRING="SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&tiled=false&STYLES=default&LAYERS=freguesias&CRS=EPSG:4326&WIDTH=512&HEIGHT=512&BBOX=-8.61,40.70,-8.53,40.77"
./build-QGIS-Desktop-Debug/output/bin/qgis_mapserv.fcgi > image.png

The image is empty!

export QUERY_STRING="SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image/png&TRANSPARENT=true&tiled=false&STYLES=default&LAYERS=freguesias&CRS=EPSG:4326&WIDTH=512&HEIGHT=512&BBOX=-8.61,40.70,-8.53,40.77&QUERY_LAYERS=freguesias&INFO_FORMAT=application/json&FEATURE_COUNT=50&WITH_GEOMETRY=True&I=222&J=127"
./build-QGIS-Desktop-Debug/output/bin/qgis_mapserv.fcgi

The output is empty.

Please confirm that you also get an empty map when using EPSG:4326 against the very same project.

I'll prepare another project, based on EPSG:4258 (used all over Europe) to use for these tests.

@pblottiere
Copy link
Member Author

Hi @jgrocha,

The image is empty!

Actually, the axis order for EPSG:3857 and EPSG:4326 is different:

>>> crs = QgsCoordinateReferenceSystem.fromOgcWmsCrs("EPSG:4326")
>>> crs.hasAxisInverted()
True
>>> crs = QgsCoordinateReferenceSystem.fromOgcWmsCrs("EPSG:3857")
>>> crs.hasAxisInverted()
False

And according to the WMS 1.3.0 specification:

minx, miny, maxx, maxy indicate the limits of the bounding box using the axis units and order of the specified CRS. 

So you have to invert the axis within the BBOX parameter in case of the EPSG:4326:

BBOX=40.70,-8.61,40.77,-8.53

@jgrocha
Copy link
Member

jgrocha commented Oct 30, 2019

Hi @jgrocha,

The image is empty!

Actually, the axis order for EPSG:3857 and EPSG:4326 is different:

>>> crs = QgsCoordinateReferenceSystem.fromOgcWmsCrs("EPSG:4326")
>>> crs.hasAxisInverted()
True
>>> crs = QgsCoordinateReferenceSystem.fromOgcWmsCrs("EPSG:3857")
>>> crs.hasAxisInverted()
False

And according to the WMS 1.3.0 specification:

minx, miny, maxx, maxy indicate the limits of the bounding box using the axis units and order of the specified CRS. 

So you have to invert the axis within the BBOX parameter in case of the EPSG:4326:

BBOX=40.70,-8.61,40.77,-8.53

@pblottiere Thank you for testing. I don't trust my self :-) I've tested once more and everything is running file.

I think this PR is good to merge.

@pblottiere pblottiere merged commit 292008f into qgis:master Oct 31, 2019
@elpaso
Copy link
Contributor

elpaso commented Nov 3, 2019

@pblottiere how do you feel about backporting to 3.10?
I need exporter.setTransformGeometries( false ); for #32596

@elpaso
Copy link
Contributor

elpaso commented Nov 3, 2019

@pblottiere nevermind, I've found a workaround to trick the JSON exporter.

@pblottiere
Copy link
Member Author

Hi @elpaso,

how do you feel about backporting to 3.10?
nevermind, I've found a workaround to trick the JSON exporter.

I had planned to backport this bugfix anyway. I'm probably going to do it early next week.

elpaso added a commit to elpaso/QGIS that referenced this pull request Nov 6, 2019
This is required because of a missing API
that was added with

qgis#32386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Server Related to QGIS server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QGIS Server GetFeatureInfo request: if INFO_FORMAT=application/json CRS is not respected
4 participants