geopython / pygeoapi

pygeoapi is a Python server implementation of the OGC API suite of standards. The project emerged as part of the next generation OGC API efforts in 2018 and provides the capability for organizations to deploy a RESTful OGC API endpoint using OpenAPI, GeoJSON, and HTML. pygeoapi is open source and released under an MIT license.
https://pygeoapi.io
MIT License
503 stars 265 forks source link

Add Support for OGC API - Styles #1809

Open doublebyte1 opened 2 months ago

doublebyte1 commented 2 months ago

The OGC API - Styles Draft Standard enables map servers, clients as well as visual style editors, to manage and fetch styles. The styles consist of symbolizing instructions that can be applied by a rendering engine on features and/or coverages. The API implements the conceptual model for style encodings and style metadata.

tomkralidis commented 2 months ago

As discussed, an initial iteration could be listing/access of styles via /styles. Future iterations would include association of a style to a resource and transaction interfaces.

Youssef-Harby commented 2 months ago

I have a question regarding how styles should be configured in the pygeoapi configuration YAML file. Specifically, how should styles be associated with a collection?

For example, should the style be configured under the providers section of a collection, and how would this work for both Mapbox and SLD 1.1 styles? Could you provide a sample configuration for both vector tiles (Mapbox style) and GeoJSON (SLD 1.1)?

Here are two example configurations I'm trying to achieve:

resources:
    bathingwater-estonia:
        type: collection
        title: Bathing water sources
        description: Data of bathing water sources used by water supply systems under the supervision of the Health Board from the Water Health Information System.
        keywords:
            - Water
            - Water bodies
            - Drilled wells
            - Surface water
            - Groundwater
            - Environmental health
            - Health
            - Bathing water
        links:
            - type: text/html
              rel: canonical
              title: information
              href: https://avaandmed.eesti.ee/api/datasets/slug/supluskohad
              hreflang: en-US
        extents:
            spatial:
                bbox:
                    [
                        22.2290936066586440,
                        57.6912449743385451,
                        28.2024877654160555,
                        59.6097269178904412,
                    ]
                crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
            temporal:
                begin: null
                end: null # or empty
        providers:
            - type: feature
              name: GeoJSON
              data: tests/data/tartu/bathingwater-estonia.geojson
              id_field: id
              styles:
                  - name: water-bodies
                    title: Water Bodies SLD Style
                    style:
                        type: sld
                        version: 1.1
                        data: tests/styles/bathing_water_sources.sld
            - type: tile
              name: MVT-tippecanoe
              data: tests/data/tiles_es/ # local directory tree
              options:
                  zoom:
                      min: 0
                      max: 16
              format:
                  name: pbf
                  mimetype: application/vnd.mapbox-vector-tile
              styles:
                  - name: mapbox style test
                    title: style title
                    style:
                        type: mapbox
                        data: tests/styles/bathing_water_sources.json

Could you confirm if this is the right way to configure the styles, and if there's anything else that should be included for proper style support?

Additionally, I'm curious about the compatibility of certain style types with specific providers (assuming that it will be under providers). From what I understand, it's possible to define a GeoJSON source (either inline or as a remote URL) within a Mapbox style JSON, but it's not possible to define an SLD style for a vector tiles (PBF) provider. Could you clarify if this assumption is correct?

If there are limitations on which style types (e.g., Mapbox vs. SLD) can be applied to specific providers (e.g., GeoJSON vs. PBF), it would be helpful to understand how pygeoapi handles this, and whether these limitations are enforced in the configuration.

Youssef-Harby commented 2 months ago

Should we add XML support in https://github.com/geopython/pygeoapi/blob/master/pygeoapi/api/__init__.py#L81-L101 for SLD ? Or it will be a different query parameter like ?f=mbsor ?f=sld for example ?

doublebyte1 commented 1 month ago

I have a question regarding how styles should be configured in the pygeoapi configuration YAML file. Specifically, how should styles be associated with a collection?

For example, should the style be configured under the providers section of a collection, and how would this work for both Mapbox and SLD 1.1 styles? Could you provide a sample configuration for both vector tiles (Mapbox style) and GeoJSON (SLD 1.1)?

Here are two example configurations I'm trying to achieve:

resources:
    bathingwater-estonia:
        type: collection
        title: Bathing water sources
        description: Data of bathing water sources used by water supply systems under the supervision of the Health Board from the Water Health Information System.
        keywords:
            - Water
            - Water bodies
            - Drilled wells
            - Surface water
            - Groundwater
            - Environmental health
            - Health
            - Bathing water
        links:
            - type: text/html
              rel: canonical
              title: information
              href: https://avaandmed.eesti.ee/api/datasets/slug/supluskohad
              hreflang: en-US
        extents:
            spatial:
                bbox:
                    [
                        22.2290936066586440,
                        57.6912449743385451,
                        28.2024877654160555,
                        59.6097269178904412,
                    ]
                crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
            temporal:
                begin: null
                end: null # or empty
        providers:
            - type: feature
              name: GeoJSON
              data: tests/data/tartu/bathingwater-estonia.geojson
              id_field: id
              styles:
                  - name: water-bodies
                    title: Water Bodies SLD Style
                    style:
                        type: sld
                        version: 1.1
                        data: tests/styles/bathing_water_sources.sld
            - type: tile
              name: MVT-tippecanoe
              data: tests/data/tiles_es/ # local directory tree
              options:
                  zoom:
                      min: 0
                      max: 16
              format:
                  name: pbf
                  mimetype: application/vnd.mapbox-vector-tile
              styles:
                  - name: mapbox style test
                    title: style title
                    style:
                        type: mapbox
                        data: tests/styles/bathing_water_sources.json

Could you confirm if this is the right way to configure the styles, and if there's anything else that should be included for proper style support?

Additionally, I'm curious about the compatibility of certain style types with specific providers (assuming that it will be under providers). From what I understand, it's possible to define a GeoJSON source (either inline or as a remote URL) within a Mapbox style JSON, but it's not possible to define an SLD style for a vector tiles (PBF) provider. Could you clarify if this assumption is correct?

If there are limitations on which style types (e.g., Mapbox vs. SLD) can be applied to specific providers (e.g., GeoJSON vs. PBF), it would be helpful to understand how pygeoapi handles this, and whether these limitations are enforced in the configuration.

Hi @Youssef-Harby these are all valid questions, but they regard the application of styles in other Standards (e.g: tiles) and we may be stepping ourselves ahead a bit, as we do not have any support for serving the actual style, yet (:

The PR I am working on aims for support for publishing styles, starting from a very simple case (e.g.: SLDs on a folder). Once we are able to provide a list of styles and styles metadata, we can start thinking about calling these styles from other APIs (:

If you have some sample style files that you can provide, as examples, I would be very grateful! ☺️

Youssef-Harby commented 1 month ago

Thanks, @doublebyte1 . I am using the exercise data from https://dive.pygeoapi.io/setup/ (bathingwater-estonia) to generate a very simple style using QGIS for SLD 1.1 and Maputnik for Mapbox GL style.

tests/styles/bathing_water_sources.json:

{
  "version": 8,
  "name": "Empty Style",
  "metadata": {"maputnik:renderer": "mlgljs"},
  "sources": {
    "earth": {
      "type": "raster",
      "tiles": ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"],
      "minzoom": 0,
      "maxzoom": 16
    },
    "pygeoapi": {
      "type": "vector",
      "tiles": [
        "https://localhost/collections/bathingwater-estonia/tiles/WebMercatorQuad/{z}/{x}/{y}?f=pbf"
      ],
      "minzoom": 0,
      "maxzoom": 16
    }
  },
  "sprite": "",
  "glyphs": "https://orangemug.github.io/font-glyphs/glyphs/{fontstack}/{range}.pbf",
  "layers": [
    {"id": "earth", "type": "raster", "source": "earth"},
    {
      "id": "bathingwaterestonia",
      "type": "circle",
      "source": "pygeoapi",
      "source-layer": "bathingwaterestonia",
      "paint": {"circle-color": "rgba(255, 0, 0, 1)", "circle-radius": 10}
    }
  ],
  "id": "oi0gcaa"
}

tests/styles/bathing_water_sources.sld:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" version="1.1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:se="http://www.opengis.net/se" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd">
  <NamedLayer>
    <se:Name>bathingwater-estonia</se:Name>
    <UserStyle>
      <se:Name>bathingwater-estonia</se:Name>
      <se:FeatureTypeStyle>
        <se:Rule>
          <se:Name>Single symbol</se:Name>
          <se:PointSymbolizer>
            <se:Graphic>
              <se:Mark>
                <se:WellKnownName>star</se:WellKnownName>
                <se:Fill>
                  <se:SvgParameter name="fill">#b80808</se:SvgParameter>
                </se:Fill>
                <se:Stroke>
                  <se:SvgParameter name="stroke">#b80808</se:SvgParameter>
                  <se:SvgParameter name="stroke-width">1</se:SvgParameter>
                </se:Stroke>
              </se:Mark>
              <se:Size>24</se:Size>
            </se:Graphic>
          </se:PointSymbolizer>
          <se:PointSymbolizer>
            <se:Graphic>
              <se:Mark>
                <se:WellKnownName>star</se:WellKnownName>
                <se:Fill>
                  <se:SvgParameter name="fill">#ff0000</se:SvgParameter>
                </se:Fill>
                <se:Stroke>
                  <se:SvgParameter name="stroke">#ff0000</se:SvgParameter>
                  <se:SvgParameter name="stroke-width">1</se:SvgParameter>
                </se:Stroke>
              </se:Mark>
              <se:Size>26</se:Size>
              <se:Rotation>
                <ogc:Literal>34</ogc:Literal>
              </se:Rotation>
            </se:Graphic>
          </se:PointSymbolizer>
        </se:Rule>
      </se:FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Also, I have started working on https://github.com/Youssef-Harby/pygeoapi/tree/styles , incorporating your changes/boilerplate, and began drafting from that point. However, since your plan involves serving only simple SLDs from a directory, I would like to ask if you could provide an example configuration YAML showing how you would prefer the SLD to be defined, so we're aligned on the same page.

doublebyte1 commented 1 month ago

@Youssef-Harby: sure, based on your example, I was thinking of something like this (but open to feedback!): 😁

          bathingwater-estonia:
              type: collection
              title: Bathing water sources
              description: Data of bathing water sources used by water supply systems under the supervision of the Health Board from the Water Health Information System.
              keywords:
                  - Water
                  - Water bodies
                  - Drilled wells
                  - Surface water
                  - Groundwater
                  - Environmental health
                  - Health
                  - Bathing water
              links:
                  - type: text/html
                    rel: canonical
                    title: information
                    href: https://avaandmed.eesti.ee/api/datasets/slug/supluskohad
                    hreflang: en-US
              extents:
                  spatial:
                      bbox:
                          [
                              22.2290936066586440,
                              57.6912449743385451,
                              28.2024877654160555,
                              59.6097269178904412,
                          ]
                      crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
                  temporal:
                      begin: null
                      end: null # or empty
              providers:
                  - type: feature
                    name: GeoJSON
                    data: tests/data/tartu/bathingwater-estonia.geojson
                    id_field: id
                  - type: tile
                    name: MVT-tippecanoe
                    data: tests/data/tiles_es/ # local directory tree
                    options:
                        zoom:
                            min: 0
                            max: 16
                    format:
                        name: pbf
                        mimetype: application/vnd.mapbox-vector-tile
                  - type: style
                    name: style-file
                    options:
                        format: mbs
                    data: tests/styles/bathing_water_sources.json # local directory tree

In summary, the type would be the new type, style and we would have to implement one provider to load the style from a file on disk. Ultimately, this plugin should have as option the style format, but for now, we could even remove the options and just assume a default format (e.g.: mapbox or sld).

doublebyte1 commented 1 month ago

@tomkralidis what do you think? :-)