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-tree may be a good option. Here's an R-tree python package. You could detect roaming by comparing the results of consecutive searches.
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.
You can get data for the entire united states from open street map You 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.
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.
The free reverse geocoding service I developed (www.feroeg.com) is based on spatialite, a sqlite library implementing SQL spatial capabilities (r-tree). The data are imported from OpenStreetMap (nation, cities, streets,street number) and OpenAddresses (street numbers) using proprietary tools. The entire world consumes about 250GB. There is a paper describing the architecture of the service: https://feroeg.com/Feroeg_files/Feroeg Presentation.pdf
At the moment the project (importer and server) is closed source.
Reverse Geocoding Library (C++) and converting tools are availabile on request.
发布评论
评论(7)
我为国家/地区创建了一个离线反向地理编码模块: https://github.com/richardpenman/reverse_geocode
我将看看我是否可以添加州数据。
I created an offline reverse geocoding module for countries: https://github.com/richardpenman/reverse_geocode
I will see if I can add data for states.
我建议使用您的第一个想法的变体:使用空间索引。空间索引是一种由矩形构建的数据结构,将纬度/经度映射到有效负载。在这种情况下,您可能会将矩形映射到州-省对。 R-tree 可能是一个不错的选择。这是一个R-tree python 包。您可以通过比较连续搜索的结果来检测漫游。
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-tree may be a good option. Here's an R-tree python package. You could detect roaming by comparing the results of consecutive searches.
我不会从头开始实施您自己的解决方案。这是一项相当大的任务,并且已经有工具可以做到这一点。如果您正在寻找开源方法(阅读:免费),请查看此博客文章:使用 PostGIS 进行反向地理编码。
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.
如果您可以将状态边界视为多边形(例如,通过 OpenStreetMap),则确定当前状态只是多边形内的点测试。
如果您需要地址数据,离线解决方案是使用 Microsoft Mappoint。
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.
If you need address data, an offline solution would be to use Microsoft Mappoint.
您可以从 开放街道地图 获取整个美国的数据,然后您可以提取所需的数据,例如将城市或州位置转换为最适合您的应用程序的格式。请注意,虽然数据质量很好,但不能保证完全准确,因此如果您需要完全准确,您可能需要寻找其他地方。
You can get data for the entire united states from open street map You 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.
我有一个包含所有这些数据和一些访问工具的数据库。我根据人口普查老虎数据得出了我的结论。我想这基本上是将我的数据库导出到 sqlite 并进行一些代码翻译。
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.
我开发的免费反向地理编码服务(www.feroeg.com)基于Spatialite,一个实现 SQL 空间功能(r-tree)的 sqlite 库。
数据是使用专有工具从 OpenStreetMap(国家、城市、街道、街道号码)和 OpenAddresses(街道号码)导入的。
全世界消耗了大约250GB。
有一篇论文描述了该服务的架构:
https://feroeg.com/Feroeg_files/FeroegPresentation.pdf
目前项目(导入程序和服务器)是闭源的。
可根据要求提供反向地理编码库 (C++) 和转换工具。
The free reverse geocoding service I developed (www.feroeg.com) is based on spatialite, a sqlite library implementing SQL spatial capabilities (r-tree).
The data are imported from OpenStreetMap (nation, cities, streets,street number) and OpenAddresses (street numbers) using proprietary tools.
The entire world consumes about 250GB.
There is a paper describing the architecture of the service:
https://feroeg.com/Feroeg_files/Feroeg Presentation.pdf
At the moment the project (importer and server) is closed source.
Reverse Geocoding Library (C++) and converting tools are availabile on request.