DEFRA / os-map-ref

OsMapRef is a tool to help handle UK Ordnance Survey map references, in particular to convert them to other coordinate systems
Other
2 stars 5 forks source link

Location returns incorrect map reference #39

Open tobyprivett opened 2 years ago

tobyprivett commented 2 years ago

The Location class is incorrectly caclulating the map_reference.

This problem arises because first character of the easting/northing is used to locate the grid key in a matrix, and expects inputs with a specific number of characters.

Starting with a postcode TQ13 7LJ, the EA Address Facade via defra-ruby-address gives us easting: 277938.47, northing: 70817.97

If we pass these values into the OsMapRef::Location class, the northing will be 70817. And this gives us an incorrect grid reference in Scotland:

OsMapRef::Location.for("277938.47,70817.97").map_reference
=> "NN 77938 08170"

If we append a 0 to the northing , we get a grid reference in the right location:

OsMapRef::Location.for("277938.47,070817.9").map_reference
=> "SX 77938 70817"

However, northing should be a number, and numbers don't have leading zeros. The OS Places API states that the Y_COORDINATE is a Float.

Recommendation is to re-write the Location class using thee toString method of this Javascript class as a starting point.

PaulDoyle-EA commented 2 years ago

A complete fix for this would need to take into account how the gem currently adjusts "short" easting and northing values by right-zero-padding them; see for example https://github.com/DEFRA/os-map-ref/blob/7bed0439d9442fd90a82c42ee49a8a55a6f6de57/spec/os_map_ref/input_processor_spec.rb#L78 That logic would need to be somehow reconciled with the need to left-zero-pad in some cases. Such a change could adversely impact current users of the gem. Taking this into account, it was decided to retain the current behaviour of the gem and to update the README to explain that some easting/northern values should be left-zero-padded on input.