谷歌地图 - 如何从地址获取建筑物的多边形坐标?
如何实现以下内容:
- 用户定义地址
- 用户定义颜色
- 服务在谷歌地图上搜索相应的建筑物
- 颜色填充地图上找到的建筑物
服务用我知道如何的
: 1.查找地址的纬度/经度
2 .绘制多边形
因此,为了完成任务,我需要从地址获取建筑物的多边形坐标。怎样做?
How to implement the following:
- User defines an address
- User defines a color
- Service searches for a corresponding building on the google map
- Service fills the found building on the map with the color
I know how to:
1.find lat/long of the address
2.draw the polygon
So, to do the task I need to get polygon coordinates of building from address. How to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
(1) 获取图片tile
(2) 基于分段建筑物关于像素颜色(此处为 0xF2EEE6)。
(3) 图像清理(例如 先腐蚀后膨胀) + 获取多边形角点像素坐标的算法。
(4) 墨卡托投影以获取像素的纬度/经度
(1) Acquire image tile
(2) Segment buildings based on pixel color (here, 0xF2EEE6).
(3) Image cleanup (e.g. erosion then dilation) + algorithm to acquire pixel coordinates of polygon corners.
(4) Mercator projection to acquire lat/long of pixel
您可以使用 Google Geocoding API 将地址转换为地理坐标。
然后,您可以使用 Python 和样式化的静态地图来获取某个位置处建筑物的多边形(以像素坐标表示):
现在,您可以使用少量 JavaScript 和 Google 地图将像素坐标转换为纬度和经度应用程序编程接口:
You can convert the address to geographic coordinates by the use of the Google Geocoding API.
Then, you can use Python and a styled static map to obtain the polygon of the building (in pixel coordinates) at some location:
Now, you can convert the pixel coordinates to latitude and longitude by the use of little JavaScript, and the Google Maps API:
我可以谦虚地建议您使用 OpenStreetMaps 来代替吗?
这要容易得多,因为这样您就可以使用 OverPass API。
但是,多边形可能与谷歌地图或州调查不匹配。
如果您使用谷歌地图,后者也适用。
Might I humbly suggest you use OpenStreetMaps for this instead ?
It's a lot easier, because then you can use the OverPass API.
However, polygons might not match with google-maps or with state survey.
The latter also holds true if you would use google-maps.
我已经为此工作了几个小时,最接近的是找到一个请求 uri,该 uri 返回其中包含多边形的结果。我相信它通过
editids
参数指定建筑物(边界)。我们只需要一种从建筑物(边界)获取当前 editid 的方法。我拥有的 URI 是:
结果的一部分包含所需的内容:
I've been working on this for hours, the closest I have come is finding a request uri that returns a result with a polygon in it. I believe it specifies the building(boundary) by
editids
parameter. We just need a way to get the current editids from a building(boundary).The URI I have is:
Part of the result has what is needed:
我对这个问题很感兴趣,并写了一个解决方案。请参阅我的 github 项目。
I was intrigued on this problem and wrote a solution to it. See my github project.
Google Maps API 包含
GeocoderResults
对象 这可能就是您所需要的。具体来说,是在geometry
字段中返回的数据。The Google Maps API contains a
GeocoderResults
object that might be what you need. Specifically the data returned in thegeometry
field.