Repository navigation
perf(render): read a streamed Shapefile's view in its own units on a map in its system #2796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a1a6739
f4055bc
115ade7
d6677ad
ff92ba7
eb01419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -233,6 +233,12 @@ impl Request { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// A box over the whole plane: as [`Request::own`], every feature in the source's own system, | ||||||||||||
| /// those longitude/latitude can't place included (a map in that system draws them as they are). | ||||||||||||
| pub fn whole_plane() -> Extent { | ||||||||||||
| Extent::new(f64::NEG_INFINITY, f64::NEG_INFINITY, f64::INFINITY, f64::INFINITY) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// Refuses an unknown count rather than reporting an unbounded view as empty. A zero-limit | ||||||||||||
| /// request does not start the full geometry scan needed to determine its matches. | ||||||||||||
| pub(crate) fn unbounded_count() -> DataError { | ||||||||||||
|
|
@@ -419,6 +425,17 @@ pub trait FeatureSource: Send + Sync { | |||||||||||
| fn visit_chunks(&self, _extent: Option<Extent>, _bytes: usize, _visit: &mut dyn FnMut(Vec<Feature>) -> Result<()>) -> Result<Batch> { | ||||||||||||
| Err(DataError::Unsupported("a source that can't be read a chunk at a time".into())) | ||||||||||||
| } | ||||||||||||
| /// [`FeatureSource::visit_chunks`] for a whole request, its box in the source's own system | ||||||||||||
| /// ([`Request::own`]) too (one over the whole plane, [`whole_plane`], reads every feature as a | ||||||||||||
| /// map in that system draws them): a source that reads one this way tests each feature's own box | ||||||||||||
| /// against it, converting nothing. One that doesn't visits every feature when given a box in | ||||||||||||
| /// its own system, never fewer than it holds (its extent, in longitude/latitude, may hold | ||||||||||||
| /// less), and reads the extent otherwise (no box, or one in another system). | ||||||||||||
| fn visit_request_chunks(&self, req: &Request, bytes: usize, visit: &mut dyn FnMut(Vec<Feature>) -> Result<()>) -> Result<Batch> { | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default ignores
Suggested change
Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in eb01419: the default reads the extent when the own box is in another system, and visits every feature only for a box in its own system it can't use; the doc says so. |
||||||||||||
| // A box in another system is read as if absent, as `Request::own` has it. | ||||||||||||
| let in_own = req.own.is_some_and(|(crs, _)| crs == self.coord_crs()); | ||||||||||||
| self.visit_chunks(if in_own { None } else { req.extent }, bytes, visit) | ||||||||||||
| } | ||||||||||||
| fn info(&self) -> &SourceInfo; | ||||||||||||
| /// The coordinate system of the features it gives: a file read in place gives them as the file | ||||||||||||
| /// holds them, in its own system (Shapefile, GeoPackage, FlatGeobuf, GeoParquet, GeoJSON); a | ||||||||||||
|
|
@@ -429,9 +446,10 @@ pub trait FeatureSource: Send + Sync { | |||||||||||
| crate::raster::Crs::LonLat | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// Whether a read given its box in the source's own system ([`Request::own`]) tests its | ||||||||||||
| /// features against that box (a file read in place, PostGIS), so a map in that system keeps | ||||||||||||
| /// its window in map units for it. A source that reads by the longitude/latitude extent | ||||||||||||
| /// Whether a read ([`FeatureSource::read`]) given its box in the source's own system | ||||||||||||
| /// ([`Request::own`]) tests its features against that box (a file read in place, PostGIS), so | ||||||||||||
| /// a map in that system keeps its window in map units for it. A complete visit does so only | ||||||||||||
| /// where the source says so through [`FeatureSource::visit_request_chunks`]. A source that reads by the longitude/latitude extent | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this doc paragraph was re-wrapped unevenly. Line 452 runs to about 170 characters, and the sentence that follows starts on a new line at a different width. Re-wrap the paragraph to the surrounding width, with no change of wording. Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left for the release quality pass. |
||||||||||||
| /// whatever it is given (another database, a service, a converted copy) says no: its window is | ||||||||||||
| /// kept in longitude/latitude, as it reads. | ||||||||||||
| fn reads_own_box(&self) -> bool { | ||||||||||||
|
|
@@ -1014,7 +1032,8 @@ impl Reproject { | |||||||||||
| if !g.is_finite() { | ||||||||||||
| return None; | ||||||||||||
| } | ||||||||||||
| let inside = g.extent().intersects(&own); | ||||||||||||
| // A box over the whole plane holds every shape, one with no place (an empty part) too. | ||||||||||||
| let inside = own == whole_plane() || g.extent().intersects(&own); | ||||||||||||
| return Some(Fitted { geometry: g, inside }); | ||||||||||||
| } | ||||||||||||
| let Placed { geometry, lonlat } = self.read(g)?; | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -425,10 +425,20 @@ impl FeatureSource for ShpSource { | |
| /// Visits located shapes in a spatial request; geometry-less rows belong only to whole reads. | ||
| /// Counts scanned records and checks Cancel before filtering them. | ||
| fn visit_chunks(&self, extent: Option<Extent>, bytes: usize, visit: &mut dyn FnMut(Vec<Feature>) -> Result<()>) -> Result<Batch> { | ||
| self.visit_request_chunks(&Request { extent, limit: usize::MAX, own: None }, bytes, visit) | ||
| } | ||
| /// As [`FeatureSource::visit_chunks`], narrowed by the request's box in the file's own system | ||
| /// when it gives one ([`Request::own`]), and each shape's own box tested against it. | ||
| fn visit_request_chunks(&self, req: &Request, bytes: usize, visit: &mut dyn FnMut(Vec<Feature>) -> Result<()>) -> Result<Batch> { | ||
| let encoding = self.encoding.decoder(); | ||
| let mut chunks = super::chunk_memory::Chunker::new(bytes, visit)?; | ||
| let req = Request { extent, limit: usize::MAX, own: None }; | ||
| let extent = extent.and_then(|e| self.reproject.extent_from_lonlat(&e)); | ||
| let req = Request { limit: usize::MAX, ..*req }; | ||
| // The request's box in the file's own system, when it is one (a box in another system | ||
| // is read as if absent), and whether it is one over the whole plane, which narrows | ||
| // nothing: every record, those without a box too, as a whole read. | ||
| let own = self.reproject.own_box(&req); | ||
| let everywhere = own == Some(super::whole_plane()); | ||
| let extent = self.reproject.request_box(&req).filter(|_| !everywhere); | ||
| if extent.is_some_and(|e| e.is_empty()) { | ||
| return Ok(Batch { complete: true, ..Batch::default() }); | ||
| } | ||
|
|
@@ -438,7 +448,7 @@ impl FeatureSource for ShpSource { | |
| // As in `read`, an extent the file's system couldn't bound (#1925) visits every record. | ||
| let late = req.extent.is_some() && bounds.is_none(); | ||
| // A whole read looks at whether the stored boxes hold their shapes, once. | ||
| let checking = req.extent.is_none() && self.boxes.load(Relaxed) == BOXES_UNKNOWN; | ||
| let checking = req.extent.is_none() && (own.is_none() || everywhere) && self.boxes.load(Relaxed) == BOXES_UNKNOWN; | ||
| let mut missed = false; | ||
| // A record a whole read couldn't read this time had its box left unchecked: the check | ||
| // waits for a read that reads them all. | ||
|
|
@@ -497,8 +507,9 @@ impl FeatureSource for ShpSource { | |
| return Ok(()); | ||
| } | ||
| }; | ||
| // As in `read`, the shape itself is checked. | ||
| if geometry.as_ref().map_or(req.extent.is_some(), |g| !g.inside) { | ||
| // As in `read`, the shape itself is checked; a read by area, its box in the file's | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment says the rule is "as in Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left for the release quality pass: no output differs today (the window read always passes an extent with its own box), and making |
||
| // own system included, gives no rows without a shape. | ||
| if geometry.as_ref().map_or(if own.is_some() { !everywhere } else { req.extent.is_some() }, |g| !g.inside) { | ||
| return Ok(()); | ||
| } | ||
| let geometry = geometry.map(|p| p.geometry); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several sources say
reads_own_box()is true (fgb.rs:831,geojson.rs:319,gpkg.rs:436,gpkg_mem.rs:338,parquet.rs:489) but don't overridevisit_request_chunks, so an own-box request on them visits every feature. That is correct today, because the render path gates own reads onfinds_all_by_area, which only the Shapefile sets. But it contradicts thereads_own_boxdoc, which says a source given its own box tests features against it. If one of these later gainsfinds_all_by_areawithout an override, it would silently read whole files on every frame. Either override the method there or narrow thereads_own_boxdoc.Confidence: medium.
Category: quality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 115ade7:
reads_own_box's doc now says it is aboutread, and that a complete visit tests an own box only where the source overridesvisit_request_chunks(the default visits every feature when given one).