MapServer / mapcache

MapCache source code directory. Please submit pull requests to the 'main' branch.
https://mapserver.org/mapcache
Other
136 stars 96 forks source link

Creating tiles with the time dimension stores wrong tile #246

Closed jankovicgd closed 3 years ago

jankovicgd commented 3 years ago

Hey all, I have an issue where the same overlapping images gets stored as a tile for different time slices when time is provided as a dimension.

Example request:

https://data-access.192.168.49.2.nip.io/cache/ows/wmts?layer=S2L2A__TRUE_COLOR&style=default&tilematrixset=WGS84&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image/png&TileMatrix=9&TileCol=554&TileRow=119&time=2019-09-08T10:07:18Z/2019-09-08T10:07:36Z

The resulting image is expected and received, an assembly of two images: Screenshot from 2021-03-30 15-11-34

The request sends two requests to the WMS and these two requests have the full intervals in the time parameter. The time parameter is wrong in this case and it should be the timestamp, not the full interval:

[30/Mar/2021 13:17:50] "GET /ows?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&STYLES=&BBOX=14.765625%2c47.812500%2c15.117188%2c48.164063&WIDTH=256&HEIGHT=256&FORMAT=image%2fpng&SRS=EPSG%3a4326&LAYERS=S2L2A__TRUE_COLOR&TRANSPARENT=true&time=2019-09-08T10%3a07%3a18Z%2f2019-09-08T10%3a07%3a36Z HTTP/1.1" 200 67191
[30/Mar/2021 13:17:53] "GET /ows?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&STYLES=&BBOX=14.765625%2c47.812500%2c15.117188%2c48.164063&WIDTH=256&HEIGHT=256&FORMAT=image%2fpng&SRS=EPSG%3a4326&LAYERS=S2L2A__TRUE_COLOR&TRANSPARENT=true&time=2019-09-08T10%3a07%3a18Z%2f2019-09-08T10%3a07%3a36Z HTTP/1.1" 200 67191

When looking in the cache db the image above gets stored for both dimensions. Screenshot from 2021-03-30 15-22-31 Screenshot from 2021-03-30 15-22-45

I am able to get the proper images if I cache them manually one by one:

https://data-access.192.168.49.2.nip.io//ows?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&STYLES=&BBOX=14.765625,47.812500,15.117188,48.164063&WIDTH=256&HEIGHT=256&FORMAT=image/png&SRS=EPSG:4326&LAYERS=S2L2A__TRUE_COLOR&TRANSPARENT=true&time=2019-09-08T10:07:18Z/2019-09-08T10:07:18Z
https://data-access.192.168.49.2.nip.io//ows?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&STYLES=&BBOX=14.765625,47.812500,15.117188,48.164063&WIDTH=256&HEIGHT=256&FORMAT=image/png&SRS=EPSG:4326&LAYERS=S2L2A__TRUE_COLOR&TRANSPARENT=true&time=2019-09-08T10:07:36Z/2019-09-08T10:07:36Z

Screenshot from 2021-03-30 15-26-40 Screenshot from 2021-03-30 15-31-57

The dimensions config file is below. Tried tinkering with many values here but ultimately it doesn't change the result. The store_assemblies is seemingly not enforced here.

<dimensions>
          <assembly_type>stack</assembly_type>
          <store_assemblies>false</store_assemblies>
          <subdimensions_read_only>false</subdimensions_read_only>
          <dimension type="postgresql" name="time" default="2017/2019" time="true" unit="ISO8601">
            <connection>host=s2l2a-test-database user=dbuser password=dbpw dbname=dbname port=5432</connection>
            <list_query>SELECT to_char(MIN(mapcache_items.begin_time), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') || '/' || to_char(MAX(mapcache_items.end_time), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') FROM mapcache_items WHERE mapcache_items.collection = '{{ $collection_name }}';</list_query>
            <validate_query>SELECT * FROM (SELECT to_char(mapcache_items.begin_time, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') || '/' || to_char(mapcache_items.end_time, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') AS "interval" FROM mapcache_items WHERE (mapcache_items.collection = 'S2L2A' AND ((mapcache_items."begin_time" &lt; to_timestamp(:end_timestamp) AND mapcache_items."end_time" &gt; to_timestamp(:start_timestamp)) or (mapcache_items."begin_time" = mapcache_items."end_time" AND mapcache_items."begin_time" &lt;= to_timestamp(:end_timestamp) AND mapcache_items."end_time" &gt;= to_timestamp(:start_timestamp)))) AND mapcache_items."footprint" &amp;&amp; ST_MakeEnvelope(:minx, :miny, :maxx, :maxy, 4326) ORDER BY mapcache_items."end_time" DESC LIMIT 20) AS sub ORDER BY interval ASC;</validate_query>
          </dimension>
 </dimensions>

In the client consuming this, a single time slice is selected and shown but as you can see the other pieces from the other timeslice also render which is outside of the bbox.

Screenshot from 2021-03-30 15-51-45

Tested with mapcache 1.10.0-1

constantinius commented 3 years ago

I found the issue to be this commit: https://github.com/MapServer/mapcache/commit/a118e919b8b2ceef00f0a92c5742a75a3dc888fd

In source_wms for GetMap the dimension value was changed from cached_value (the time value of the actual tile) to requested_value (the full timespan from the incoming request). I see that it makes sense to do that for GetFeatureInfo, as I guess only a single request is sent to the source WMS, but for GetMap this introduces the aforementioned bug.