WFS, Map Layer as REST Source and Oracle APEX

Photo by Kyle Glenn on Unsplash

WFS, Map Layer as REST Source and Oracle APEX

In the previous article, I demonstrated how to display a map background using WMS. Today, I will focus on WFS. Like WMS, Web Feature Service is a standard protocol developed by the Open Geospatial Consortium (OGC) for serving geospatial data over the internet. The key difference is that while WMS provides rendered map images, WFS offers vector data - features with geometry and attributes.

Our primary goal will be to create a new layer using WFS. Where can we find an example WFS? There are many open data portals available, such as GeoServer or OpenStreetMap, so finding one should not be difficult. However, it's important to ensure that the WFS returns data in GeoJSON format, as this is the format supported by the Oracle APEX Map region.

💡
The Oracle APEX Map region allows you to display a layer based on three different data types: SDO_GEOMETRY, GeoJSON (stored in VARCHAR2 or CLOB), or Longitude and Latitude (two NUMBER columns).

MapServer

MapServer is an open-source platform for publishing spatial data and interactive mapping applications on the web. It was originally developed by the University of Minnesota and has since evolved into a robust tool, now supported by the Open Source Geospatial Foundation (OSGeo).

The website https://demo.mapserver.org/ provides several sample services, including WFS, which I will use in my Oracle APEX app.

WFS step by step

My WFS URL looks like this:

https://demo.mapserver.org/cgi-bin/wfs?

To use WFS correctly and retrieve data in GeoJSON format, I need to define the following parameters:

  • SERVICE

  • VERSION

  • REQUEST

  • TYPENAMES

  • OUTPUTFORMAT

Where can I find the values for these parameters? I can use a GetCapabilities request, which provides detailed metadata about the service (similar to WMS).

https://demo.mapserver.org/cgi-bin/wfs?
service=WFS
&request=getCapabilities

The URL above will return information about the WFS in XML format (you can simply open it in your browser). In the appropriate sections, I can find the values for my parameters (TYPENAMES → FeatureType - Name and OUTPUTFORMAT → OutputFormats - Format).

<FeatureType>
    <Name>ms:continents</Name>
    <Title>World continents</Title>
    <DefaultCRS>urn:ogc:def:crs:EPSG::4326</DefaultCRS>
    <OtherCRS>urn:ogc:def:crs:EPSG::4269</OtherCRS>
    <OtherCRS>urn:ogc:def:crs:EPSG::3978</OtherCRS>
    <OtherCRS>urn:ogc:def:crs:EPSG::3857</OtherCRS>
    <OutputFormats>
        <Format>application/gml+xml; version=3.2</Format>
        <Format>text/xml; subtype=gml/3.2.1</Format>
        <Format>text/xml; subtype=gml/3.1.1</Format>
        <Format>text/xml; subtype=gml/2.1.2</Format>
        <Format>application/json; subtype=geojson</Format>
    </OutputFormats>
        <ows:WGS84BoundingBox dimensions="2">
        <ows:LowerCorner>-180.000000 -90.000000</ows:LowerCorner>
        <ows:UpperCorner>180.000000 83.627419</ows:UpperCorner>
        </ows:WGS84BoundingBox>
    <MetadataURL xlink:href="https://demo.mapserver.org/cgi-bin/wfs?request=GetMetadata&layer=continents"/>
</FeatureType>

Based on the above XML, my WFS URL for the new map layer should look like this:

https://demo.mapserver.org/cgi-bin/wfs?
service=WFS
&version=2.0.0
&request=GetFeature
&typeNames=ms:continents
&outputFormat=geojson

REST Data Sources

To define the source of our map, I will use the REST Data Sources functionality, which provides a way to integrate external RESTful web services directly into APEX applications.

How to do it? As usual, by following the plan :)

  1. Go to Shared Components and choose REST Data Sources (under the Data Sources section).

  2. Create a new REST Data Source from scratch.

  3. On the Create REST Data Source screen, complete the fields as follows:

    1. REST Data Source Type: Simple HTTP

    2. Name: DEMO (feel free to use your own, more creative layer name here)

    3. URL Endpoint: https://demo.mapserver.org/cgi-bin/wfs?service=WFS &version=2.0.0&request=GetFeature&typeNames=ms:continents&outputFormat=geojson

  4. On the Create REST Data Source - Remote Server screen, APEX will split the URL Endpoint into Base URL and Service URL Path. Simply click Next.

  5. On the Create REST Data Source - Settings screen, leave the No Pagination option selected and click Next.

  6. For Authentication, none is needed in this case, so click Discover.

  7. On the REST Data Source Discovery screen, you will see the data returned by our WFS. Check the Data Profile (which shows what columns the service returns) and the Response Body, which is usually too large to display correctly :)

  8. In the final step, click Create REST Data Source!

New Map Layer as REST Source

Now, we can display a new layer based on WFS.

  1. Go to your Map region and create a new layer.

  2. Choose Layer Type: Polygons (because our WFS returns a list of all countries).

  3. In the Source section, complete the fields as follows:

    1. Location: REST Source

    2. REST Source: DEMO (the previously created REST Data Source)

  4. In the Column Mapping section, complete the fields as follows:

    1. Geometry Column Data Type: GeoJSON

    2. GeoJSON Column: GEOMETRY (the column returned by WFS)

  5. Click Save and run the page.

Now, my Map region looks like this:

Conclusions

Thanks to WFS, we can access a lot of useful information about spatial data. Additionally, if the geometry is returned in GeoJSON format, we can easily visualize this data as a new layer in the Oracle APEX Map region.