Repository navigation
Description
Before you start
- I searched the existing issues and did not find a duplicate.
- This is a bug report, not a usage question.
What happened?
On a layer read in place, layer.symbology says when its classes come from a view that isn't the whole layer (#2715). It decides by comparing the features read with the source's count (SourceLayer::exact_count, crates/map/src/source.rs). Since #2859, a GeoPackage's count is the one kept in gpkg_ogr_contents, when its two triggers are there. The comment on kept_count already says it can be high after an INSERT OR REPLACE. The sampler and the progress bar don't rely on it (count_kept); this notice does, because the two PRs were written apart. #2715 is mine.
Three files of 40 points, with both triggers, differing only in the stored count:
| Stored count | View | Read | Notice | Expected |
|---|---|---|---|---|
| 40 (right) | the whole layer | 40 | none | none |
| 40 (right) | part of it | 10 | said | said |
| 50 (high) | the whole layer | 40 | said | none |
| 50 (high) | part of it | 10 | said | said |
| 10 (low) | the whole layer | 40 | said | none |
| 10 (low) | part of it | 10 | none | said |
- High is the case to expect: a program writing with
INSERT OR REPLACEthrough plain SQLite leaves it. (The same statement through GDAL 3.13.3'sExecuteSQLleft the count right.) The notice then appears every time, even with the whole layer in view. - Low I wrote by hand, and I know no common program that leaves it. The notice is missing only when the features read happen to equal the stored count.
Only this notice is wrong. The classes and the drawing are the same either way.
Steps to reproduce
Make the high one (the file comes from GDAL, without a spatial index so that plain SQLite can write to it):
import sqlite3
from osgeo import ogr, osr
s = osr.SpatialReference(); s.ImportFromEPSG(4326)
s.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
ds = ogr.GetDriverByName("GPKG").CreateDataSource("high.gpkg")
l = ds.CreateLayer("pts", s, ogr.wkbPoint, ["SPATIAL_INDEX=NO"])
l.CreateField(ogr.FieldDefn("n", ogr.OFTInteger))
for i in range(40):
f = ogr.Feature(l.GetLayerDefn()); f["n"] = i
f.SetGeometry(ogr.CreateGeometryFromWkt(f"POINT({i % 10} {i // 10 * 20})"))
l.CreateFeature(f)
ds = l = f = None
c = sqlite3.connect("high.gpkg")
c.execute("INSERT OR REPLACE INTO pts SELECT * FROM pts WHERE n < 10"); c.commit()
print(c.execute("SELECT feature_count FROM gpkg_ogr_contents").fetchone()) # (50,)For the low one, leave out the INSERT and run UPDATE gpkg_ogr_contents SET feature_count = 10.
Then, in one session (I used rustgis-cli mcp --yes; a view has to be drawn before the symbology):
layer.addDatawith{"path": "high.gpkg", "stream": true}map.zoomToExtentwith{"extent": [-1, -5, 10, 65]}(the whole layer) or[-1, -3, 10, 3](part of it)view_maplayer.symbologywith{"layer": 1, "type": "graduated", "field": "n", "classes": 3}
Output with the whole layer in view:
pts: its symbology is worked out from the 40 features of the view read so far, not the whole layer read in place; …
Expected behavior
No notice when the view holds the whole layer, and the notice when it doesn't, whatever count the file states.
Taking a stored count as "not known exactly", as a database's is, isn't enough: the notice would then appear with the whole layer in view on every GeoPackage with GDAL's count and triggers.
I propose to ask the file whether it has more rows than the n read, for a stored count only:
SELECT EXISTS(SELECT 1 FROM t LIMIT 1 OFFSET n)SQLite stops at row n + 1, and n is at most VIEW_LIMIT (250,000), so a large table isn't scanned. On a 1 GB SQLite file of a million rows, made for this and read by Python's sqlite3, it took 0.13 s with n = 50,000, against 1.4 s for COUNT(*). Every other source is answered as today. No dependency is needed. The count shown when the layer is added stays as #2859 made it.
I can open the pull request: the question to the source, its use in the notice, and the six rows above as a test.
How are you running RustGIS?
Command line (rustgis-cli)
Version
main at 2342a2c (neither #2859 nor #2715 is in 0.8.0).
Operating system, browser and graphics
Windows 11
Sample data
The script above makes it.
Screenshots or logs
None. I ran the commands only, not the window.
Activity
fix(symbology): the "not the whole layer" notice asks a GeoPackage fo…