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

BBOX is not re-projected properly in MapServer query statement #5202

Open
marionb opened this Issue Dec 1, 2015 · 7 comments

Comments

Projects
None yet
7 participants
@marionb

marionb commented Dec 1, 2015

While using MapServer I came across some strange behaviour when doing a POST request on a BBox. From the client the following request is sent:

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" maxFeatures="200" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <wfs:Query typeName="feature:cameras" xmlns:feature="http://mapserver.gis.umn.edu/mapserver">
        <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:BBOX>
                <ogc:PropertyName>geom</ogc:PropertyName>
                <gml:Envelope xmlns:gml="http://www.opengis.net/gml">
                    <gml:lowerCorner>565240 5735152.5</gml:lowerCorner>
                    <gml:upperCorner>565895 5735602.5</gml:upperCorner>
                </gml:Envelope>
            </ogc:BBOX>
        </ogc:Filter>
    </wfs:Query>
</wfs:GetFeature>

The returned xml contains no information (<gml:Null>missing</gml:Null>) also if srsName="EPSG::3857" is sent with the request.

When checking the query log from PostQGIS the following query I can find the reason for the empty gml:

SELECT ...
FROM
  (SELECT cam.*
   FROM shema.cameras cam
   WHERE (etage = '+0'
          OR etage IS NULL)) AS foo
WHERE geom && ST_GeomFromText('POLYGON((250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029))',27562)
  AND (st_intersects(geom,ST_GeomFromText('POLYGON ((813376.7942609430756420 83142.7202183806366520, 813359.1764772359747440 83647.8472906547685852, 813645.7609626927878708 83657.8494853072916158, 813663.4024164262227714 83152.7232393100421177, 813376.7942609430756420 83142.7202183806366520))',27562)) = TRUE)

In this query the first polygon is not properly transformed from projection 3857 back in to 27562 such that the WHERE clause always returns FALSE.

The following Configurations are used:

Mapserver (using version 7.0.0) is configured to use data from a PostGIS database with data in the projection EPSG:27562. In the browser the features are shown using projection EPSG:3857. In the Mapfile on the map level the projection is set to:

PROJECTION
        "init=epsg:3857"
END

The layers are configured as follows:

LAYER
    NAME "cameras"
    TYPE POINT
    STATUS ON
    TEMPLATE fooOnlyForWMSGetFeatureInfo
    CONNECTIONTYPE postgis
    PROCESSING "CLOSE_CONNECTION=DEFER"
    CONNECTION "user=user password=user_pw dbname=example_db host=localhost"
    DATA "geom FROM (SELECT cam.* FROM shema.cameras cam) AS foo USING UNIQUE id USING srid=27562"
    PROJECTION
        "init=epsg:27562"
    END
    METADATA
        "wms_srs" "epsg:3857"
        "ows_include_items" "all"
        "ows_geom_type" "point"
        "ows_geometries" "geom"

        "wms_title" "cameras"
        "gml_include_items" "all"
        "ows_srs" "EPSG:3857"
        "gml_types" "auto"
        "gml_featureid" "id"
        "gml_geometries" "geom"
        "gml_geom_type" "point"
        "wfs_enable_request" "*"
    END
END
@tbonfort

This comment has been minimized.

Member

tbonfort commented Dec 1, 2015

Does mapserver 6.4 exhibit the same issue ?

@jratike80

This comment has been minimized.

jratike80 commented Dec 1, 2015

Hi,

I as a Mapserver user would rather read these questions first from the mapserver-users mailing list. You might get helped and most important, users would get informed about possible bug.

I suppose that the first polygon is taken from the map extent, what do you have there?

There seems to be a smaller error also in the selection polygon. You had this in filter:
gml:lowerCorner565240 5735152.5/gml:lowerCorner
gml:upperCorner565895 5735602.5/gml:upperCorner

Which was converted into this in PostGIS
POLYGON ((813376.7942609430756420 83142.7202183806366520, 813359.1764772359747440 83647.8472906547685852, 813645.7609626927878708 83657.8494853072916158, 813663.4024164262227714 83152.7232393100421177, 813376.7942609430756420 83142.7202183806366520))

And that converted back into EPSG:3857 is
POLYGON ((
565220.000421019 5734817.500022685,
565220.0004210512 5735542.500022758,
565630.000420927 5735542.500022737,
565630.0004208948 5734817.500022668,
565220.000421019 5734817.500022685
))

By comparing the rightmost coordinates 5735602.5 (filter) and 5735542.500022737 (PostGIS query) some data would be missing.

-Jukka Rahkonen-

Lähettäjä: Marion Baumgartner [mailto:notifications@github.com]
Lähetetty: 1. joulukuuta 2015 6:48
Vastaanottaja: mapserver/mapserver
Aihe: [mapserver] BBOX is not re-projected properly in MapServer query statement (#5202)

While using MapServer I came across some strange behaviour when doing a POST request on a BBox. From the client the following request is sent:

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" maxFeatures="200" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsdhttp://www.opengis.net/wfs%20http:/schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<wfs:Query typeName="feature:cameras" xmlns:feature="http://mapserver.gis.umn.edu/mapserver">

    <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">

        <ogc:BBOX>

            <ogc:PropertyName>geom</ogc:PropertyName>

            <gml:Envelope xmlns:gml="http://www.opengis.net/gml">

                <gml:lowerCorner>565240 5735152.5</gml:lowerCorner>

                <gml:upperCorner>565895 5735602.5</gml:upperCorner>

            </gml:Envelope>

        </ogc:BBOX>

    </ogc:Filter>

</wfs:Query>

/wfs:GetFeature

The returned xml contains no information (gml:Nullmissing/gml:Null) also if srsName="EPSG::3857" is sent with the request.

When checking the query log from PostQGIS the following query I can find the reason for the empty gml:

SELECT ...

FROM

(SELECT cam.*

FROM shema.cameras cam

WHERE (etage = '+0'

      OR etage IS NULL)) AS foo

WHERE geom && ST_GeomFromText('POLYGON((250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029,250840.933537713 -5541337.97732029))',27562)

AND (st_intersects(geom,ST_GeomFromText('POLYGON ((813376.7942609430756420 83142.7202183806366520, 813359.1764772359747440 83647.8472906547685852, 813645.7609626927878708 83657.8494853072916158, 813663.4024164262227714 83152.7232393100421177, 813376.7942609430756420 83142.7202183806366520))',27562)) = TRUE)

In this query the first polygon is not properly transformed from projection 3857 back in to 27562 such that the WHERE clause always returns FALSE.

The following Configurations are used:

Mapserver (using version 7.0.0) is configured to use data from a PostGIS database with data in the projection EPSG:27562. In the browser the features are shown using projection EPSG:3857. In the Mapfile on the map level the projection is set to:

PROJECTION

    "init=epsg:3857"

END

The layers are configured as follows:

LAYER

NAME "cameras"

TYPE POINT

STATUS ON

TEMPLATE fooOnlyForWMSGetFeatureInfo

CONNECTIONTYPE postgis

PROCESSING "CLOSE_CONNECTION=DEFER"

CONNECTION "user=user password=user_pw dbname=example_db host=localhost"

DATA "geom FROM (SELECT cam.* FROM shema.cameras cam) AS foo USING UNIQUE id USING srid=27562"

PROJECTION

    "init=epsg:27562"

END

METADATA

    "wms_srs" "epsg:3857"

    "ows_include_items" "all"

    "ows_geom_type" "point"

    "ows_geometries" "geom"



    "wms_title" "cameras"

    "gml_include_items" "all"

    "ows_srs" "EPSG:3857"

    "gml_types" "auto"

    "gml_featureid" "id"

    "gml_geometries" "geom"

    "gml_geom_type" "point"

    "wfs_enable_request" "*"

END

END


Reply to this email directly or view it on GitHubhttps://github.com//issues/5202.

@pvalsecc

This comment has been minimized.

Contributor

pvalsecc commented Dec 3, 2015

Jukka,

Marion's problem is not because of a slight imprecision in the coordinate transformation, but because of a lack of consistency in the projections used in the Postgres query.

She does her WFS query in epsg:3857 and the data in postgres is stored in epsg:27562.

From what I understand, mapserver does the BBOX filtering using two where clauses:

where geom && ST_GeomFromText(...) and st_intersects(geom,ST_GeomFromText(...))

If my memory is good, the first one is to leverage the geography index, the second one is for having accurate results.
The two polygons are supposed to be the same, but for some reason, only the second one has been transformed into the correct projection. The first one is left in the WFS query projection.

CU

@bpjetursson

This comment has been minimized.

bpjetursson commented Oct 4, 2016

Could the function msPostGISLayerWhichShapes be missing a projection parameter when calling msPostGISBuildSQL?

Version 7.0.2, file mappostgis.c, line 2656:
strSQL = msPostGISBuildSQL(layer, &rect, NULL);

The third parameter should be the SRID for the &rect, no?

@gignacnic

This comment has been minimized.

gignacnic commented Nov 1, 2016

Is there any update on fixing this issue? We do have the same problem with MapServer 7.0.2.
Thanks.

@bpjetursson

This comment has been minimized.

bpjetursson commented Nov 2, 2016

Made a workaround by adding an IF to the native PostGIS function like this:
If projection is missing from geom2, use the projection from geom1 for both.

@juliensam

This comment has been minimized.

Contributor

juliensam commented May 14, 2017

Looking at the code, the only way I see this can happen is when the Mapfile extent does not cover the WFS Filter coordinates. I added 2 tests in msautotest to cover this case.

MapServer succesfully reprojects the filter passed to it, but also filter on the EXTENT of the map. To see the request sent to PostGIS, simply add a DEBUG statement in your layer.

Does your mapfile extent intersects with you WFS filter?

rouault added a commit that referenced this issue Nov 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment