[Feature]: A mask for tile layers (WMS, XYZ…), as layer.mask gives feature and raster layers

Open
#2,530 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, web-dev

Research direction

Start by tracing map.setTiles, map.addTiles, and service.add, then compare how feature and raster layers implement masking. Follow the tile drawing, project save and removal, properties UI, identify, render, and export paths named in the proposal. Done means all listed commands and UI support masks, outside pixels are omitted in view and export, clearing and removing a mask behave as specified, and the tests pass.

Written by the indexing model from the issue text.

Description

Before you start
What problem does this solve?

A tile layer (XYZ, WMS, WMTS, ArcGIS map service) can't be cut to a polygon. layer.mask takes a polygon layer and masks a feature or raster layer, but a tile layer isn't a layer it can be given (map.addTiles and map.setTiles have no mask), so a WMS map of a country or of the world always draws everywhere.

A study area's map then shows the service's picture outside the area too, while every other layer of the area is cut to it. There is no workaround inside RustGIS:

  • A WMS GetMap picture can't be opened as a raster, so it can't be clipped. layer.addUrl on a PNG GetMap address answers "not a data format RustGIS reads".
  • Many services offer no GeoTIFF GetMap, and no WCS of the same product.
Proposed solution

A mask on a tile layer, as feature and raster layers have: the tile layer draws only inside the polygons of a polygon layer.

Choices in this proposal
  • Commands:
    • map.setTiles takes "mask": polygon layer | null, as layer.mask does;
    • map.addTiles and service.add take it too, so a layer can be added already cut.
  • Drawing: the same as layer.mask for a raster, applied to the tile layer's drawn picture: its pixels outside the mask's polygons are left out. Map view, layouts and exports all draw it this way.
  • Saved: the mask is kept in the project with the tile layer, by the mask layer's id, and handled as a feature or raster layer's mask is when that layer is removed.
  • UI: the tile layer's properties get the Masking choice that feature and raster layers have.
  • Identify: a click outside the mask doesn't ask a WMS layer for its feature info.
  • Tests:
    • a tile layer masked by a polygon draws nothing outside it, both in a render and in an export;
    • "mask": null removes the mask;
    • removing the mask layer leaves the tile layer as a raster's mask leaves its layer.
Alternatives considered
  • Veil: a polygon with a hole for the area, drawn over the tiles in the paper's colour. It also hides the basemap and other layers outside the area, and it has to be kept above the tiles by hand.
  • Clip the service's data: only possible where the service offers a GeoTIFF or a WCS, which the drought maps of the Copernicus Global Drought Observatory, for one, don't (their WCS gives colour classes, and not every product).
Additional context

This came up in the BrasilData plugin, which adds the Copernicus Global Drought Observatory's drought maps (WMS) over a study area. Every other BrasilData layer is clipped to the area, and the drought map is not.

Dominant language
Rust
Stars
1.9k
Forks
268
Avg merge
11h 1m
Merged PRs (30d)
942

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opengeos/RustGIS

All issues in opengeos/RustGIS

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.