PostCode Distance UK

clive2002

Registered User.
Local time
Today, 22:47
Joined
Apr 21, 2002
Messages
91
I need to write some code to return the distance between two postcodes for a batch of records on a daily basis.

I can think of two ways to do this and I'm stuck on both.


1) Obtain a matrix of postcode distances and reference this in the database. Does anybody know of such a matrix.

2) Interact with some third party software like AutoRoute. How would i go about this, I presume some kind of ADO, anybody got any experience with this.


Thanks in advance
 
Depends on how accurate you want to be. I have been in transportation for almost 10 years, and everytime you create something to get distances 10 other people come along and have 10 different numbers (and they all claim theirs are more accurate).

I have come to use a 3 digit to 3 digit matrix for most of my databases. It does not give the exact miles and in some cases can be up to 50 miles off, but we are taking about rural areas. I'm not sure how the postal codes in the UK work, but if there is a way to ge the "3 digit" equivalent, it will help with keeping the db at a managable size.

tblMiles
Field 1 - ZipLane (Example 940-081)
Field 2 - Miles (3250)

HTH
 
Did you get any further with this query? I am also struggling to find an affordable way to manage this sort of calculation.

:confused:
 
As JFGambit says, it depends on how accurate you need to be. If you want the distance as the crow flies. This is not too difficult. You would need to integrate your database with a third party PostCode Address File (PAF) product. I haven't done this for many years , but last time I used AFD postcode. This gives OS co-ordinates for each post code in its database.

After that its just a case of owrking out the difference in horizontal units, the difference in vertical units and using good old pythagoras from school, to work out the distance between the two.

If you want distance by road. I can'r help, but i would like to know a solution if you find one.

hth

sametch
 
sametch said:
After that its just a case of owrking out the difference in horizontal units, the difference in vertical units and using good old pythagoras from school, to work out the distance between the two.

Horizontal and vertical units? The Earth's surface is curved and you require spherical trigonometry on curved triangles to calculate the distance in degrees, minutes, and seconds. ;)
 
Yeh Right!

I just about coped with trig at school, never could manage, circles and things, so i'll leave that one to you then Mile-O-Phile;)
 
Surely the UK isn't big enough to warrant such accuracy, in any case would it not be that road distances between cities be more apt?
 
Rich said:
would it not be that road distances between cities be more apt?

...if you had a metre-stick!
 
I have developed this technology for the UK, so it can be done. The accuracy is +-10-15 miles on average. The function is fast!

Routing is obviously much more accurate than looking up in a table unless the table has all the answers to every question, per-calculated, which is not possible, of course.

A lookup table is much much faster (~1500 x faster) than actually routing, but depending on the use case, you need to pick the right/best approach.

A downside to a lookup table is that you have to create it, and "carry" it around with you. For example, there are about 3,000 "districts" in the UK i.e. LS6, or AB16 a table of these locations would be 3k*3k = 9 million rows. More over, to create this table, a 0.5 second call to MapPoint is neededl (one call = one route distance) so it will take you about 52 days, at 24 hours a day to get all the distances!


At the end of the day its a trade off.

Lots of locations - accuracy not mega important - simple lookup table
A few locations, but you need accuracy? - routed each one
Loads and need to be accurate - Complex look up table! and good luck!


Feel free to contact me for more information. I'm sure we could work something out, it wont be for free through, sorry.
 
Last edited:
Sounds like a shameless plug to sell his stuff :(
 
Having your own post code database is no longer relevant, just use an online service like google maps.
 
I know this is an old thread - but the trouble is that UK postcodes are copyright, unlike US post codes

so google will only return the centre (centroid?) of a post code, with a certain degree of inaccuracy. This might be OK for some uses, but in rural areas such as Lincolnshire, say, the google lat/long for the post code can easily be 20-30 miles off the correct location

depending on what you are doing, this may or may not be critical.

In truth if you need 100% accuracy with UK post codes, I think you have to pay for it.
 
I used to have to geo-code postcodes using the Royal Mail PAF file (Postcode Address File).

This might be fine if you want to locate a particular house but if you want to use it on the addresses of things like chemical works the location of the actually postbox might be quite some distance from where the work actually takes place.
 
I appreciate that postal code as a geographic tool is an approximation at best. I've said that in the original post.
Postal codes are area locators and are approximated as a point - often using the centroid, as Dave says. But that's the nature of an area locator vs a point locator.

As nanscome has mentioned post codes, at least here in Canada, don't necessarily relate to a geo location. Government departments often have their own Postal Code - even though they may be distributed over cities and provinces.

Dave if you think rural UK is remote, come to Canada. Some postal codes are almost as large (sq miles) as
England, let alone North Yorkshire.
 
Last edited:
I appreciate that postal code as a geographic tool is an approximation at best. I've said that in the original post.
Postal codes are area locators and are approximated as a point - often using the centroid, as Dave says. But that's the nature of an area locator vs a point locator.

As nanscome has mentioned post codes, at least here in Canada, don't necessarily relate to a geo location. Government departments often have their own Postal Code - even though they may be distributed over cities and provinces.

Dave if you think rural UK is remote, come to Canada. Some postal codes are almost as large (sq miles) as
England, let alone North Yorkshire.

lol. that's a different problem though, isn't it.

Is the Canadian postcode/zipcode copyright? That's the thing. Google deliberately will only geocode a postcode to a restricted level of accuracy.
 

Users who are viewing this thread

Back
Top Bottom