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

Empty response is returned for GeoJSON when no features #5208

Merged
merged 1 commit into from Feb 23, 2016
Merged

Empty response is returned for GeoJSON when no features #5208

merged 1 commit into from Feb 23, 2016

Conversation

tbonfort
Copy link
Member

@tbonfort tbonfort commented Feb 23, 2016

When using GeoJSON as output format with the OGR GeoJSON driver, an empty response (Content-Length: 0) is returned when no features match a query.

For GML an empty feature collection is returned, I would expect the same for GeoJSON. GeoServer does it this way and OpenLayers 3 also expects an empty feature collection.

@tbonfort
Copy link
Member

tbonfort commented Feb 23, 2016

This is an OGR bug, mapserver itself does not create geojson. cc @rouault for confirmation

@dmorissette
Copy link
Contributor

dmorissette commented Feb 23, 2016

Actually, @juliensam came across this issue as well with geojson and investigated a bit further. He will provide us more info on what a valid 0-result GeoJSON response should contain and we can make the fix in OGR (if the bug is indeed in OGR).

@juliensam
Copy link
Contributor

juliensam commented Feb 23, 2016

According to the GeoJSON spec, a valid GeoJSON is a JSON document containing at least a geometry, a feature or an empty feature collection:
http://geojson.org/geojson-spec.html#geojson-objects

So according to the spec the minimal valid result for an empty response should be:

{
    "type": "FeatureCollection",
    "features": [
    ]
}

I'll let you decide if it's an OGR bug or a MapServer bug.

Here's a test mapfile with the test URL to reproduce the issue:

MAP

    # GetMap URL
    # &service=WMS&request=GetMap&version=1.3.0&CRS=EPSG:3857&width=200&height=200&layers=geojson&bbox=-20,-20,20,20&format=image/png

    # GetFeatureInfo URL (Working)
    # &service=WMS&request=GetFeatureInfo&version=1.3.0&CRS=EPSG:3857&width=200&height=200&layers=geojson&bbox=-20,-20,20,20&format=image/png&query_layers=geojson&i=100&j=100&&info_format=geojson
    IMAGETYPE png

    # GetFeatureInfo URL (Not Working)
    # &service=WMS&request=GetFeatureInfo&version=1.3.0&CRS=EPSG:3857&width=200&height=200&layers=geojson&bbox=-20,-20,20,20&format=image/png&query_layers=geojson&i=0&j=0&&info_format=geojson

    SIZE 100 100
    EXTENT -20 -20 20 20
    IMAGECOLOR '#ffffff'
    WEB
        METADATA
            "ows_enable_request" "*"
            "ows_srs" "EPSG:3857 EPSG:900913 EPSG:4326"
            "ows_title" "GeoJSON test"
            "wms_getfeatureinfo_formatlist" "gml,geojson"
            "wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=mymap.map"
        END
        IMAGEPATH '/tmp/ms_tmp/'
        IMAGEURL '/ms_tmp/'
    END
    PROJECTION
        "init=epsg:3857"
    END

    OUTPUTFORMAT
      NAME "geojson"
      DRIVER "OGR/GEOJSON"
      MIMETYPE "application/json; subtype=geojson; charset=utf-8"
      FORMATOPTION "STORAGE=stream"
      FORMATOPTION "FORM=SIMPLE"
      FORMATOPTION "LCO:COORDINATE_PRECISION=5"
    END

    LAYER
        NAME "geojson"
        TYPE POLYGON
        STATUS DEFAULT
        PROJECTION
            'init=epsg:3857'
        END
        METADATA
            "wms_title" "Testing layer"
            "ows_srs" "EPSG:3857 EPSG:900913 EPSG:4326"
        END
        TEMPLATE 'blank.html'

        FEATURE
            POINTS
                -10 -10
                -10  10
                 10  10
                 10 -10
                -10 -10
            END
            TEXT "Polygon"
        END

        CLASS
            NAME 'class'

            STYLE
                COLOR '#ff0000'
            END
        END
    END

END

@juliensam juliensam reopened this Feb 23, 2016
@tbonfort tbonfort added this to the 7.0.1 milestone Feb 23, 2016
@tbonfort tbonfort removed the Invalid label Feb 23, 2016
@tbonfort
Copy link
Member

tbonfort commented Feb 23, 2016

The proposed patch fixes the issue, it now emits the layer even if the query returned no features. @sdlime: ok?

@sdlime
Copy link
Member

sdlime commented Feb 23, 2016

Looks ok to me... --Steve

@juliensam
Copy link
Contributor

juliensam commented Feb 23, 2016

With the test mapfile above, I get the following response:

{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::3857" } },
"features": [

]
}

Merging

juliensam added a commit that referenced this pull request Feb 23, 2016
@juliensam juliensam merged commit 2e8c128 into MapServer:branch-7-0 Feb 23, 2016
@rouault
Copy link
Contributor

rouault commented Feb 24, 2016

I hope all drivers generate valid files with 0 feature written in the layer... I guess most should behave OK.

@sdlime
Copy link
Member

sdlime commented Feb 24, 2016

All OGR drivers, correct?

@rouault
Copy link
Contributor

rouault commented Feb 24, 2016

Yes OGR drivers. But anyway the change should be OK.

tbonfort added a commit to MapServer/msautotest_DEPRECATED that referenced this pull request Feb 24, 2016
@tbonfort
Copy link
Member

tbonfort commented Feb 24, 2016

autotests added. @juliensam please don't merge pull-requests before discussions concerning the implications have happened.

@juliensam
Copy link
Contributor

juliensam commented Feb 24, 2016

sorry about this. Noted for the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants