Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
345 changes: 269 additions & 76 deletions crates/data/src/source/gpkg/edit.rs

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions crates/data/src/source/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
//! What a server sends is hostile input: geometry is decoded by [`wkb`], reads are bounded by
//! `LIMIT`, and statements time out.

use super::{Batch, Family, FeatureSource, Reproject, Request, SourceInfo, clamp_limit, in_request, stride};
use crate::{DataError, Feature, Field, FieldType, Geometry, GeometryType, Result, Value, wkb};
use super::{Batch, Family, FeatureSource, Reproject, Request, SourceInfo, clamp_limit, stride};
use crate::{DataError, Feature, Field, FieldType, GeometryType, Result, Value, wkb};
use mysql::prelude::Queryable;
use rustgis_geom::Extent;
use std::sync::{Arc, Mutex, OnceLock, Weak};
Expand Down Expand Up @@ -896,7 +896,12 @@ impl MysqlSource {
let Ok(b) = self.read_within(&Request { extent: None, limit: EXTENT_SAMPLE }, Some(PROBE_TIMEOUT)) else {
return Extent::EMPTY;
};
b.features.iter().filter_map(|f| f.geometry.as_ref()).fold(Extent::EMPTY, |e, g| e.union(&g.extent()))
// Read in the table's own system: each placed in longitude/latitude, vertex by vertex.
b.features
.into_iter()
.filter_map(|f| f.geometry)
.filter_map(|g| self.reproject.read(g))
.fold(Extent::EMPTY, |e, p| e.union(&p.lonlat))
}

/// The `WHERE` condition: a geometry, of the family read, and in `window` (a polygon's text
Expand Down Expand Up @@ -929,16 +934,17 @@ impl MysqlSource {
w
}

/// A row read as a feature: the id, the geometry and the fields, in the order of the select.
/// `None` without an id or a geometry RustGIS reads. A value of a date field that isn't a date
/// A row read as a feature: the id, the geometry (as the table holds it, in its own system)
/// and the fields, in the order of the select, with the geometry's box in longitude/latitude.
/// `None` without an id or a geometry RustGIS reads and places. A value of a date field that isn't a date
/// RustGIS holds is null, counted in `unread` ([`Batch::unread_dates`]).
fn row_feature(&self, r: &mysql::Row, unread: &mut Vec<usize>) -> Option<Feature> {
fn row_feature(&self, r: &mysql::Row, unread: &mut Vec<usize>) -> Option<(Feature, Extent)> {
let id = id_of(at(r, 0))?;
let geometry = match at(r, 1) {
mysql::Value::Bytes(b) => wkb::decode(b),
_ => None,
}?;
let geometry: Geometry = self.reproject.to_lonlat_geometry(geometry)?;
let super::Placed { geometry, lonlat } = self.reproject.read(geometry)?;
let attrs = self
.info
.fields
Expand All @@ -958,7 +964,7 @@ impl MysqlSource {
})
.collect();
// A negative key keeps its bits: still one id per row, and the same on every read.
Some(Feature { id, geometry: Some(geometry), attrs })
Some((Feature { id, geometry: Some(geometry), attrs }, lonlat))
}
}

Expand Down Expand Up @@ -1075,14 +1081,13 @@ impl MysqlSource {
for r in &rows {
// Dates that aren't ones are counted in the rows kept.
let mut unread = Vec::new();
let Some(f) = self.row_feature(r, &mut unread) else {
let Some((f, lonlat)) = self.row_feature(r, &mut unread) else {
out.skipped += 1;
continue;
};
// The index matched the request's box in the table's coordinates, which holds more
// than the request when they are projected.
let Some(g) = &f.geometry else { continue };
if !in_request(g, req) {
// than the request when they are projected: placed in longitude/latitude to compare.
if req.extent.is_some_and(|e| !lonlat.intersects(&e)) {
continue;
}
super::add_unread_dates(&mut out.unread_dates, &unread);
Expand All @@ -1098,6 +1103,11 @@ impl FeatureSource for MysqlSource {
&self.info
}

/// The table's own system, which its rows are read in (as a file's are kept).
fn coord_crs(&self) -> crate::raster::Crs {
self.reproject.crs()
}

fn read(&self, req: &Request) -> Result<Batch> {
self.read_within(req, None)
}
Expand Down Expand Up @@ -1364,8 +1374,10 @@ mod tests {
let started = std::time::Instant::now();
let part = src.read(&Request { extent: Some(q), limit: 1000 }).unwrap_or_else(|e| panic!("{}: {e}", t.label()));
let quarter = started.elapsed();
// In the table's own system: compared in longitude/latitude, as the request is.
let to = src.coord_crs().to(crate::raster::Crs::LonLat).unwrap_or_else(|e| panic!("{e}"));
for ft in &part.features {
let g = ft.geometry.as_ref().map(|g| g.extent()).unwrap_or(Extent::EMPTY);
let g = ft.geometry.as_ref().map(|g| to.geometry(g).extent()).unwrap_or(Extent::EMPTY);
assert!(g.intersects(&q.padded(0.01, 0.0)), "{}: feature {} outside the request", t.label(), ft.id);
}
let mut ids: Vec<u64> = whole.features.iter().map(|f| f.id).collect();
Expand Down
Loading
Loading