urschrei / lonlat_bng

A multithreaded Rust library with FFI for converting WGS84 longitude and latitude coordinates into BNG (OSGB36) Eastings and Northings and vice versa (using OSTN15)
https://docs.rs/lonlat_bng
MIT License
25 stars 3 forks source link

Fails to convert TP01, TP31, TP32 points for OS testset #2

Open elmirjagudin opened 6 years ago

elmirjagudin commented 6 years ago

The lonlat_bng returns error result while converting points TP01, TP31, TP32 from Ordnance Survey OSTN15-OSGM15 test set.

The lonitude latitude for these points are:

           Longitude        Latitude
TP01    -6.29977752014  49.92226393730  
TP31    -8.57854456076  57.81351838410  
TP32    -7.59255560556  58.21262247180  

The code below demonstrates the problem:

fn test_poinsts()
{
   // TP01
   let r = convert_osgb36(&(-6.29977752014), &(49.92226393730)).unwrap();
   println!("TP01 {} {}", r.0, r.1);

   // TP31
   let r = convert_osgb36(&(-8.57854456076), &(57.81351838410)).unwrap();
   println!("TP31 {} {}", r.0, r.1);

   // TP32
   let r = convert_osgb36(&(-7.59255560556), &(58.21262247180)).unwrap();
   println!("TP32 {} {}", r.0, r.1);
}

The code above will panic, instead of printing OSGB36 coordinates.

The reason the convert_osgb36() above returns Err result is because the specified long/lat coordinates are outside of the allowed min/max values.

Interesting enough I tried to just increase the allowed bound box, and appear that it gives correct result. However I'm not sure is this is a right way to solve this problem.

urschrei commented 6 years ago

Ah, yes. That probably is the best way to fix it, even though the bounds check itself is the problem, because it's a rectangle, whereas the actual OSGB36 boundary is an irregular polygon – I could do a containment check for that, though I'll have to benchmark it to see how much slower it is.