让 Django 感知地理定位的好方法? - Django/地理定位

发布于 2024-09-29 04:26:54 字数 282 浏览 2 评论 0原文

我希望能够将各种模型(场地、地点、地标)与城市/国家相关联。

但我不确定实现这一点的一些好方法是什么。


我遵循一条简单的路线,我已经实现了国家和城市模型。

每当提到新的城市或国家时,都会自动创建它。

不幸的是,我有各种问题:

  • 数据库很容易被污染

  • Django 不知道这些城市/国家到底是什么


什么建议或想法吗?谢谢! :)

I would like to be able to associate various models (Venues, places, landmarks) with a City/Country.

But I am not sure what some good ways of implementing this would be.


I'm following a simple route, I have implemented a Country and City model.

Whenever a new city or country is mentioned it is automatically created.

Unfortunately I have various problems:

  • The database can easily be polluted

  • Django has no real knowledge of what those City/Countries really are


Any tips or ideas? Thanks! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏日落 2024-10-06 04:26:54

一个好的起点是从 Geonames 等服务获取位置数据集。还有 GeoDjango 出现在 这个问题
当您遇到新的位置名称时,请在添加之前对照较大的数据集进行检查。对于第二点,您需要将其设计到对象模型中并相应地编写代码。

以下是您可能需要考虑的其他一些事项:

  • 别名和别名。缩写
    • 这些出现的次数比您想象的要多。人们经常使用非官方城镇的郊区或社区的名称。您也可以考虑像 LA ->;洛杉矶 MTL 飞往 蒙大拿州蒙特利尔。森林-> Mount Forest、Saint vs (ST st. ST-) 等
  • 模糊搜索
    • 考虑到拼写差异,查找城市名称会容易得多。这也有助于减少同一地点的重复名称数量。
    • 您可以通过预先计算 Soundex数据集中城市的双 Metaphone 值。执行查找时,计算搜索词的值并与预先计算的值进行比较。这最适合英语,但您可能会在其他浪漫语言衍生语言上取得成功(不确定除这些之外您还有什么选择)。
  • 位置等效/包含
    • 能够确定布鲁克林是纽约市的一个行政区。

归根结底,这是一个难题,但应用这些建议应该会大大减少数据损坏的数量和您必须处理的其他令人头疼的问题。

A good starting places would be to get a location dataset from a service like Geonames. There is also GeoDjango which came up in this question.
As you encounter new location names, check them against your larger dataset before adding them. For your 2nd point, you'll need to design this into your object model and write your code accordingly.

Here are some other things you may want to consider:

  • Aliases & Abbreviations
    • These come up more than you would think. People often use the names of suburbs or neighbourhoods that aren't official towns. You can also consider ones like LA -> Los Angeles MTL for Montreal, MT. Forest -> Mount Forest, Saint vs (ST st. ST-), etc.
  • Fuzzy Search
    • Looking up city names is much easier when differences in spelling are accounted for. This also helps reduce the number of duplicate names for the same place.
    • You can do this by pre-computing the Soundex or Double Metaphone values for the cities in your data set. When performing a lookup, compute the value for the search term and compare against the pre-computed values. This will work best for English, but you may have success with other romance language derivatives (unsure what your options are beyond these).
  • Location Equivalence/Inclusion
    • Be able to determine that Brooklyn is a borough of New York City.

At the end of the day, this is a hard problem, but applying these suggestions should greatly reduce the amount of data corruption and other headaches you have to deal with.

满栀 2024-10-06 04:26:54

来自 yahoo 和 google 的地理编码数据集可能是一个很好的起点,也可以看看 django 中的 geopy 库。

Geocoding datasets from yahoo and google can be a good starting poing, Also take a look at geopy library in django.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文