python 无需 Web 访问的反向地理编码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1425149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:13:59  来源:igfitidea点击:

Reverse Geocoding Without Web Access

pythongpsgeocodingreverse-geocoding

提问by Paul Osborne

I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.

我正在开发一个应用程序,其中一个要求是我能够根据 GPS 数据执行实时反向地理编码操作。特别是,我必须能够确定纬度、经度对映射到的州/省,并检测我们何时从一个州/省移动到另一个州/省。

I have a couple ideas so far but wondered if anyone had any ideas on either of the following:

到目前为止,我有一些想法,但想知道是否有人对以下任一方面有任何想法:

  • What is the best approach for tackling this problem in an efficient manner?
  • Where is a good place to find and what is the appropriate format for North American state/province boundaries
  • 以有效方式解决此问题的最佳方法是什么?
  • 在哪里可以找到合适的地方以及北美州/省边界的适当格式是什么

As a starter, here are the two main ideas I have:

作为初学者,以下是我的两个主要想法:

  1. Break North America into a grid with each rectangle in the grid mapping to a particular state province. Do a lookup on this table (which grows quickly the more precise you would like to be) based on the latitude and then the longitude (or vice versa).
  2. Define polygons for each of the states and do some sort of calculation to determine in which polygon a lat/lon pair lies. I am not sure exactly how to go about this. HTML image maps come to mind as one way of defining the bounds for a state/province.
  1. 将北美分成一个网格,网格中的每个矩形都映射到一个特定的州省。根据纬度和经度(反之亦然)在此表上进行查找(随着您的需要,它会增长得越快)。
  2. 为每个州定义多边形并进行某种计算以确定纬度/经度对位于哪个多边形中。我不确定如何解决这个问题。HTML 图像映射是定义州/省边界的一种方式。

I am working in python for the interested or those that might have a nice library they would like to suggest.

我正在为感兴趣的人或那些可能有他们想要推荐的不错的库的人使用 python。

To be clear... I do not have web access available to me, so using an existing reverse geocoding service is not an option at runtime

需要明确的是......我没有可用的网络访问权限,因此在运行时不能选择使用现有的反向地理编码服务

采纳答案by Yuval F

I suggest using a variant of your first idea: Use a spatial index. A spatial index is a data structure built from rectangles, mapping lat/long to the payload. In this case you will probably map rectangles to state-province pairs. An R-treemay be a good option. Here's an R-tree python package. You could detect roaming by comparing the results of consecutive searches.

我建议使用您的第一个想法的变体:使用空间索引。空间索引是由矩形构建的数据结构,将纬度/经度映射到有效载荷。在这种情况下,您可能会将矩形映射到州-省对。一个R-树可能是一个不错的选择。这是一个R-tree python 包。您可以通过比较连续搜索的结果来检测漫游。

回答by hoju

I created an offline reverse geocoding module for countries: https://bitbucket.org/richardpenman/reverse_geocode

我为国家创建了一个离线反向地理编码模块:https: //bitbucket.org/richardpenman/reverse_geocode

>>> import reverse_geocode 
>>> coordinates = (-37.81, 144.96), (31.76, 35.21)
>>> reverse_geocode.search(coordinates)
[{'city': 'Melbourne', 'code': 'AU', 'country': 'Australia'},
 {'city': 'Jerusalem', 'code': 'IL', 'country': 'Israel'}]

I will see if I can add data for states.

我会看看我是否可以为州添加数据。

回答by Derek Swingley

I would stay away from implementing your own solution from scratch. This is a pretty big undertaking and there are already tools out there to do this. If you're looking for an open source approach (read: free), take a look at this blog post: Using PostGIS to Reverse Geocode.

我不会从头开始实施您自己的解决方案。这是一项相当大的任务,并且已经有工具可以做到这一点。如果您正在寻找一种开源方法(阅读:免费),请查看此博客文章: 使用 PostGIS 反向地理编码

回答by puls200

If you can get hold of state boundaries as polygons (for example, via OpenStreetMap), determining the current state is just a point-in-polygon test.

如果您可以将状态边界视为多边形(例如,通过 OpenStreetMap),则确定当前状态只是多边形中的点测试。

If you need address data, an offline solution would be to use Microsoft Mappoint.

如果您需要地址数据,离线解决方案是使用 Microsoft Mappoint。

回答by Jared

You can get data for the entire united states from open street mapYou could then extract the data you need such as city or state locations into what ever format works best for your application. Note although data quality is good it isn't guaranteed to be completely accurate so if you need complete accuracy you may have to look somewhere else.

您可以从开放的街道地图中获取整个美国的数据 然后可以将您需要的数据(例如城市或州位置)提取为最适合您的应用程序的格式。请注意,虽然数据质量很好,但不能保证完全准确,因此如果您需要完全准确,您可能需要查看其他地方。

回答by Dustin

I have a database with all of this data and some access tools. I made mine from the census tiger data. I imagine it'd basically be an export of my database to sqlite and a bit of code translation.

我有一个包含所有这些数据和一些访问工具的数据库。我是根据人口普查老虎数据制作的。我想它基本上是将我的数据库导出到 sqlite 和一些代码翻译。