通过匹配邮政编码字符串查找最接近其他英国邮政编码的英国邮政编码 [英] Find UK PostCodes closest to other UK Post Codes by matching the Post Code String

查看:189
本文介绍了通过匹配邮政编码字符串查找最接近其他英国邮政编码的英国邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个让我醒了好几天的问题。我到目前为止唯一的结论是,红牛通常不会帮助编码。



我的应用程序中有一个场景,我有几个工作(1到50)。这份工作有一个地址,我有以下地址的属性:邮政编码,纬度和经度。



我也有工作表,他们也有地址。通过屏幕创建职位或工作人员时,我使用Google地图查询来确保提供的邮政编码有效,并且在英国,所有地址都已通过验证。



I正在使用调度程序控件在y轴上显示一些工作人员,并在x轴上显示时间轴。每个作业都有日期,只能在作业日期的调度程序上垂直移动。用户选择多个作业,并将它们显示在靠近调度程序的篮子中。然后用户可以将工作拖放到工作人员身上。所有这一切都是手动的,所以它的工作原理。



我的任务是自动化这个,这样用户除了验证和分配作业外没有太多的工作。因此,我必须使过程自动化。



每个工作人员都有一个名为WillingMaximumDistanceTravel的属性,它是一个代表里程的整数,工人愿意出差工作。 p>

现在这里头痛:我有1500多名工作人员。我有一个实用功能,使用Newtonsoft的Json Convert来从Google地图中取消序列化响应。我需要提供邮政编码A和B。



我还计划在DB中引入一个新的表,以将发现的距离存储为邮政编码A,邮政编码B和距离。因此,如果我发现自己比较了相同的邮政编码,我会立即从数据库中取回结果,而不是慢慢地,最终,我不再需要打扰Google了,因为这个表将是非常全面的。



我不能使用简单的Haversine公式,因为Crow-fly路径不是我的要求。这样的痛苦在于需要大量的时间来计算。有些工人可以旅行超过10英里,而有些工作可能从15到80不等。我必须从列表中获取第一份工作,并与系统中的所有适用的工作人员一起运行!我想知道英国的邮政编码有一个模式。如果我们排列英国邮政编码清单,我们可以从字母数字模式粗略估计,我们将在哪里达到100英里的标记,200英里的标记等?



如果有人对代码感兴趣,请放一行,我将粘贴它。

解决方案

你想寻找空间索引或空格填充曲线。空间索引将2d问题降低到1d问题,并且递归将表面细分为较小的图块,但它基本上是瓦片的重新排序。您可以使用4个字符将表面细分为索引或字符串。后一种可以对您有用,因为它允许您使用隐藏在数据库引擎中的所有字符串操作查询字符串。你想查找尼克的空间索引四叉树希尔伯特曲线博客。


Here is a question that has me awake for a number of days now. The only conclusion I came up so far is that Red Bull does not usually help coders.

I have a scenario in my application where I have a couple of jobs (1 to 50). The job has an address and I have the following properties of an address: Postcode, Latitude, and Longitude.

I have a table of workers also and they too have addresses. While the jobs or workers are created through screens, I use Google Map queries to make sure the provided Postcode is valid and is in UK so all the addresses are verified.

I am using a scheduler control to display some workers on y-axis and a timeline on x-axis. Every job has a date and can only move vertically on the scheduler on the job’s date. The user selects a number of jobs and they are displayed in a basket close to the scheduler. The user can then drag and drop job against workers. All this is manual so it works.

My task is to automate this so that the user does not do much except just verifying and allotting the jobs. Therefore, I have to automate the process.

Every worker has a property called WillingMaximumDistanceTravel which is an integer representing miles, the worker is willing to travel for a job.

Now here is the headache: I have over 1500 workers. I have a utility function that uses Newtonsoft’s Json Convert to de-serialize a stream of response from Google Maps. I need to feed it Postcode A and B.

I also plan to introduce a new table to DB to store the distance finds as Postcode A, Postcode B, and Distance. Therefore, if I find myself comparing the same postcodes again, I will just retrieve the result from DB instead and slowly and eventually, I would no longer require bothering Google anymore as this table would be very comprehensive.

I cannot use the simple Haversine formula, as Crow-fly path is not my requirement here. The pain in this is that it takes a lot of time to calculate. Some workers can travel over 10 miles while some vary from 15 to 80. I have to take the first job from the list and run it with every applicable worker o the system! I was wondering that the UK postcode has a pattern to it. If we sort a list of UK postcodes, can we rough-estimate, from the alphanumeric pattern, where will we hit a 100-mile mark, a 200-mile mark and so on?

If anyone is interested in the code, please drop a line and I will paste it.

解决方案

You want to look for a spatial-index or a space-filling-curve. A spatial index reduce the 2d problem to a 1d problem and recursivley subdivide the surface into smaller tiles but it is basically a reordering of the tiles. You can subdivide the surface either with an index or a string using 4 characters. The latter one can be useful to you because it let you query the string with all string operation hidden in the database engine. You want to look for Nick's spatial index quadtree hilbert-curve blog.

这篇关于通过匹配邮政编码字符串查找最接近其他英国邮政编码的英国邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆