Skip to content
Closed
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
21 changes: 19 additions & 2 deletions rgis-transform/src/jobs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::sync::Arc;
use geo::MapCoords;
use geo_projected::CastTo;
use geodesy::prelude::Context;

const MERCATOR_LAT_LIMIT: f64 = 85.06;

pub struct ReprojectRasterExtentJob {
pub extent: geo::Rect<f64>,
pub layer_id: rgis_primitives::LayerId,
Expand Down Expand Up @@ -41,7 +44,6 @@ impl bevy_jobs::Job for ReprojectRasterExtentJob {
if source_is_geographic {
let target_is_mercator = self.target_crs.is_mercator();
if target_is_mercator {
const MERCATOR_LAT_LIMIT: f64 = 85.06;
min.y = min.y.max(-MERCATOR_LAT_LIMIT);
max.y = max.y.min(MERCATOR_LAT_LIMIT);
}
Expand Down Expand Up @@ -198,9 +200,24 @@ impl bevy_jobs::Job for ReprojectGeometryJob {
}

async fn perform(self, progress_sender: bevy_jobs::Context) -> Self::Outcome {
let feature_collection = Arc::unwrap_or_clone(self.feature_collection);
let mut feature_collection = Arc::unwrap_or_clone(self.feature_collection);
let total = feature_collection.features.len();

// If projecting geographic coordinates to Mercator, clamp latitudes to
// ±85.06° to prevent near-pole vertices from producing extreme Y values.
if self.source_crs.is_geographic() && self.target_crs.is_mercator() {
for feature in &mut feature_collection.features {
if let Some(ref mut geom) = feature.geometry {
*geom = geom.map_coords(|coord| geo::Coord {
x: coord.x,
y: geo_projected::UnprojectedScalar::new(
coord.y.0.clamp(-MERCATOR_LAT_LIMIT, MERCATOR_LAT_LIMIT),
),
});
}
}
}

let mut feature_collection = feature_collection.cast::<geo_projected::Projected>();

for (i, feature) in feature_collection.features.iter_mut().enumerate() {
Expand Down
Loading