2

Is it possible for MapServer to read GeoJSON file and serve it as a layer in the .map file? Like how it can be done with shapefiles as shown below:

LAYER
    Name 'land'
    TYPE POLYGON
    DATA 'path/to/shapefile'
END

In MapServer documentation, seems like OGR connection can read GeoJSON files but I couldn't find any example online.

2
  • and serve it as a layer ~ certainly MapServer can serve GeoJSON, it doesn't have to be the input, as a WFS output ~ here's an example ogc2.bgs.ac.uk/cgi-bin/UGA_ARGI/… Input in this example is a postgresql database
    – nmtoken
    Commented Mar 20, 2019 at 12:07
  • The example you give doesn't tell us anything about the output, only the input for the layer. The output could be an image (if we have a WMS configured) as part of a GetMap request, or GeoJSON (if we have a WFS configured).
    – nmtoken
    Commented Mar 20, 2019 at 12:13

2 Answers 2

2

tl;dr;

Is it possible for MapServer to read GeoJSON file and serve it as a layer

Yes, the below requests use a GeoJSON input (taken from my example comment).

MapServer WFS output in GeoJSON with GeoJSON as input

MapServer WFS output in GML with GeoJSON as input

For configuring input you need in your map file LAYER:

    CONNECTION "data/ows.json"
    CONNECTIONTYPE OGR

For layer projection I used:

    PROJECTION
        # https://mapserver.org/mapfile/projection.html#projection
        # The following syntax may be used in LAYERs that are OGR connections, shapefile layers or raster layers:
        AUTO
    END

I also have:

    CLASSITEM "Status_1"
    LABELITEM "Status_1"

    METADATA
        "GML_FEATUREID" "fid"
        "GML_INCLUDE_ITEMS" "all"
        "GML_TYPES" "auto"
        "OWS_TITLE" "Energy generation status (2016)"
    END

    STATUS ON
    TYPE POINT

and for outputting GeoJSON as part of a WFS, irrespective of what the input vector data is, you need something like:

MAP
    OUTPUTFORMAT
        NAME "JSON"
        DRIVER "OGR/GEOJSON"
        EXTENSION "json"
        FORMATOPTION "FORM=SIMPLE"
        FORMATOPTION "LCO:COORDINATE_PRECISION=8"
        FORMATOPTION "LCO:DESCRIPTION=This should be GeoJSON 2008; the projection may not be in CRS:84, but if not, there should be a crs: member telling you what projection has been used"
        FORMATOPTION "LCO:NATIVE_DATA=YES"
        FORMATOPTION "LCO:WRITE_BBOX=YES"
        FORMATOPTION "STORAGE=stream"
        MIMETYPE "application/json; subtype=geojson"
    END
    WEB
        METADATA
            "OWS_ABSTRACT" "This is a test web service"
            "OWS_ACCESSCONSTRAINTS" ""
            "WFS_enable_request" "*"
            "OWS_FEES" "none"
            "OWS_KEYWORDLIST" "test,testing,123"
            "OWS_SERVICE_ONLINERESOURCE" ""
            "OWS_TITLE" "Testing capabilities"
            "WFS_GETFEATURE_FORMATLIST" "JSON"
        END
    END
    LAYER
        # your input vector data
    END
...
END
2
  • Thank you, managed to get it working with your example. Just another question, what if the GeoJSON contains multiple geometry types?
    – ssaga
    Commented Mar 22, 2019 at 2:21
  • @ssaga I don't know. Possibly you'd need to set up more than one layer for your input geojson one for each geometry type
    – nmtoken
    Commented Mar 22, 2019 at 8:39
0

according to https://georezo.net/forum/viewtopic.php?id=106527

the mapfile syntax is

  CONNECTIONTYPE OGR
  CONNECTION "/path/to/file.json"
  DATA "OGRGeoJSON"

not tested but seems correct (OGRGeoJSON is the geomtery name provided by ogrinfo )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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