proj5 icon indicating copy to clipboard operation
proj5 copied to clipboard

Inconsistent results

Open natassaf opened this issue 4 years ago • 2 comments

Converting from crs84 to merc and back does not give the same results. The difference is substantial.

#[test]
fn test_coords_merc_convertion() {
    let p1 = (23.9, 35.8);
    let p2 = (24.16, 36.3);
    let p3 = (24.6, 35.8);

    let waypoints_coords = vec![p1, p2, p3];
    let waypoints_merc = coords_to_merc(&waypoints_coords);
    let waypoints_coords_reconstructed = merc_to_coords(&waypoints_merc);
    assert_eq!(waypoints_coords, waypoints_coords_reconstructed);
}
pub type FloatXY = (f64, f64);
pub type PointXY = (i64, i64);

pub fn coords_to_merc(&self, coords: &Vec<FloatXY>) -> Vec<FloatXY> {
        let nodes_coords = CoordinateSource::LonLatBuf(Box::new(LonLatBuf {
            data: coords.clone(),
            ellipsoid: WGS_1984_ELLIPSOID,
        }));

        let mut target = CoordinateSource::CoordinateBuf(Box::new(CoordinateBuf {
            data: vec![],
            crs: Box::new(MercatorSystem),
            ellipsoid: WGS_1984_ELLIPSOID,
        }));
        let mut strategy = MultithreadingStrategy::MultiCore(ThreadPool::new(4));
        nodes_coords.project(&mut target, &mut strategy);
        target
            .get_data_ref()
            .iter()
            .map(|m| (m.0 as f64, m.1 as f64))
            .collect()
    }

pub fn merc_to_coords(&self, nodes: &Vec<FloatXY>) -> Vec<FloatXY> {
        // derive crs84 projections for nodes
        let nodes_coords = CoordinateSource::CoordinateBuf(Box::new(CoordinateBuf {
            data: nodes.iter().map(|p| (p.0 as f64, p.1 as f64)).collect(),
            crs: Box::new(MercatorSystem),
            ellipsoid: WGS_1984_ELLIPSOID,
        }));
        let mut nodes_lonlat = CoordinateSource::LonLatBuf(Box::new(LonLatBuf {
            data: vec![],
            ellipsoid: WGS_1984_ELLIPSOID,
        }));

        let mut strategy = MultithreadingStrategy::MultiCore(ThreadPool::new(4));
        nodes_coords.project(&mut nodes_lonlat, &mut strategy);
        nodes_lonlat
            .get_data_ref()
            .iter()
            .map(|m| (m.0 as f64, m.1 as f64))
            .collect()
    }

natassaf avatar Nov 08 '21 14:11 natassaf

Thanks for reporting. I'll look into it, but I sadly can't give an ETA.

fschutt avatar Nov 14 '21 11:11 fschutt

Use https://github.com/3liz/proj4rs instead, I never got around fixing this issue.

fschutt avatar Aug 29 '23 08:08 fschutt