Closed Mike-Heneghan closed 5 years ago
Realised that there are occasions where the Postcode get_by_district
method returns no results.
We have the average latitude and longitude (centroid) and we are then trying to find the nearest point (postcode) to this centroid.
Currently, I think there can be situations where the average point has a latitude or longitude which is less than any of the points. In these circumstances, the query returns no results.
As a fallback, I added a condition to check the length of the query result and check it it greater than zero.
If it is not greater than equal I would search by greater than the average point to try to find results in there.
Although I think there might be four potential orderings in which the result might be.
The shape of postcode districts and clustering of postcodes within a district leads to situations where the district has no postcodes with less than or equal to latitudes and longitudes of the average point.
From discussions today it was decided that going forward as an enhancement to the postcode district search after the average latitude and longitude has been calculated fro the district the closest points in each quadrant i.e. (lte, lte) (lte, gte), (gte, lte), (gte, gte) will be found and the one with the closest Euclidean distance to the average point selected and returned.
This process should have the advantage of being more resilient as a postcode point should definitely be found and it should be closer to the logical centre based on density of postcodes.
Noticed an issue with an error searching a similar postcode district which also wasn't supported. On this occasion, it appears to be because the postcode district is no longer in use although I think we might need to add better error handling.
Updated the code to pick the closest point un each quadrant and then measure the distance to the central point. Manually testing with google maps.
Test with the G83 postcode district which has an unusual shape but is likely to have different concentrations of postcode.
Noticed an issue with an error searching a similar postcode district which also wasn't supported. On this occasion, it appears to be because the postcode district is no longer in use although I think we might need to add better error handling.
Found the error to be raised syntax wasn't correct so rather than returning "Postcode not supported" we were getting a 500 error.
Merged
Issues with one of the postcode districts.