1

I have MapServer serving up a whole bunch of data, and everything is working good. One area I am stuck is getting the WMS GetFeatureInfo request to return GeoJSON. Regardless of what I try, I just get plain text back.

The applicable pieces of my mapfile are below. My understanding is that the OGR/GEOJSON driver (in OUTPUTFORMAT) makes it so that I dont need to use a template. Is that correct? I've found that if I dont include some dummy TEMPLATE in the LAYER - the layer is not queryable. With the below configuration - regardless of what I set info_format (or outputformat) to - I just get plain text response back.

Example response:

GetFeatureInfo results:

Layer 'treecrowns' Feature 42342:

OUTPUTFORMAT
        NAME "geojson"
        DRIVER "OGR/GEOJSON"
        MIMETYPE "application/json; subtype=geojson"
        FORMATOPTION "STORAGE=stream"
        FORMATOPTION "FORM=SIMPLE"
END

 WEB
        QUERYFORMAT "geojson"
        METADATA
            "wms_title" "DAM WMS"
            "wms_abstract" "DAM WMS"
            #"wms_onlineresource" "http://mapserver//mapserv"
            "wms_srs" "EPSG:4326"
            "wms_encoding" "UTF-8"
            "wms_enable_request" "*"
            "wfs_enable_request" "!*"
            "wfs_encoding" "UTF-8"
            "wfs_getfeature_formatlist" "gml,geojson"
        END
END

LAYER
    NAME "treecrowns"
    TYPE POLYGON
    TEMPLATE fooOnlyForWMSGetFeatureInfo # For GetFeatureInfo
    EXTENT -180 -90 180 90
    CONNECTIONTYPE postgis
    PROCESSING "CLOSE_CONNECTION=DEFER" # For performance
    CONNECTION "host=x.x.x.x port=5432 dbname=x user=x password=x"
    DATA "geom from treecrowns"
    METADATA
        "wms_title" "treecrowns" # For WMS
        "wms_srs" "EPSG:4326 EPSG:3857 EPSG:4978" # For WMS

        "wfs_enable_request" "*" # Enable WFS for this layer
        "gml_include_items" "all" # For GetFeatureInfo and WFS GetFeature (QueryBuilder)
        "ows_geom_type" "Polygon" # For returning geometries in GetFeatureInfo
        "ows_geometries" "geom" # For returning geometries in GetFeatureInfo
        "wfs_featureid" "name"

        "wms_metadataurl_href" "http://www.example.com/bar" # For metadata URL
        "wms_metadataurl_format" "text/html" # For metadata URL
        "wms_metadataurl_type" "TC211" # For metadata URL
        "wfs_getfeature_formatlist" "gml,geojson"
    END
    STATUS ON
    PROJECTION
    "init=epsg:4326"
    END
    CLASS
        NAME "treecrowns"
        STYLE
            OUTLINECOLOR 0 0 255
            WIDTH 2
        END
        STYLE
            COLOR 0 0 255
            OPACITY 40
        END
    END
END
2
  • You'll need to specify wanted formats in the "WMS_FEATURE_INFO_MIME_TYPE" – nmtoken Apr 8 '20 at 12:57
  • @nmtoken. that did the trick! if you post as an answer - i will give you credit – user890 Apr 8 '20 at 13:24
1

You'll need to specify wanted formats in the "WMS_FEATURE_INFO_MIME_TYPE"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.