A bit of pseudo-code describing (at a very high level of abstraction) how an AddressBaseGeocoder()
and a FuzzyGeocoder()
(based on ONSPD) should behave and how we would interact with them.
g = AddressBaseGeocoder('SA8 4DA')
g.getLocalAuth() raises MultipleCodesException
g.getLocalAuth("10010020128") returns "W06000011"
g.getLocalAuth("100100624439") returns "W06000012"
g.getLocalAuth("spoons") raises NotFoundException
g = FuzzyGeocoder('SA8 4DA')
g.getLocalAuth() returns "W06000012"
g.getLocalAuth("100100624439") raises NotFoundException
g = AddressBaseGeocoder('SA1 3UT')
g.getLocalAuth() returns "W06000011"
g.getLocalAuth("100100357246") returns "W06000011"
g = FuzzyGeocoder('SA1 3UT')
g.getLocalAuth() returns "W06000011"
g.getLocalAuth("100100357246") raises NotFoundException
def geocode(postcode):
try:
g = AddressBaseGeocoder(postcode)
except AddressBaseNotImportedException:
g = FuzzyGeocoder(postcode)
return g
.. this means that AddressBaseGeocoder()
may generate an object where
g.getLocalAuth()
returns a value but
g.getWard()
throws an exception.
That allows us to try + see if we get an unambiguous response + only address pick if the level of geography we care about requires it..
g = AddressBaseGeocoder('SA1 6HU')
g.getLocalAuth() returns "W06000011"
g.getWard() raises MultipleCodesException
if we just want local auth, postcode is good enough. If we want ward, we have to call g.getAddresses()
and show an address picker so we can call g.getWard("100100360556")
or whatever
Maybe I'm thinking of out of scope cases here as Where doesn't currently do this, but if we wanted to use something like this in EE then we'd need to consider the following:
It's possible that a postcode could be split over some boundaries but not ones that we care about. For example, a police area will have a very low ratio of split postcodes compared to a polling district. We wouldn't want to offer an address picker if a postcode was split over two local authorities that are both in the same police area (or Westminster consistency or whatever).
Because of this we'd need to have a way of passing in the type of area we want like
g.getAreas('constituency')
and have that return or raise an exception or whatever.So far so good (I think), but in the case of getting a list of elections, we don't know the types of areas we need to get until we know the elections that are happening in that area. Because of that we'd need some ability to say "get me the elections for this postcode, but check if any one of them needs an address picker". But then in other cases we might want to force it to offer an address picker for an area type that doesn't have an election, for example a polling district.
That makes the flow a little more complex, especially if it's over an API.
Anyway, random thoughts to complicate things more…