api地理編碼
Motivation
動機
In my second semester of my Master’s degree, I was working on a dataset which had all the records of the road accident in Victoria, Australia (2013-19). I was very curious to know, which national highways are the most dangerous in Victoria, and need attention to improve safety. The dataset did have the longitude and latitude coordinates where the accidents occurred, but it did not have other supporting and useful information like the name of roads where the accident took place, or the suburb, LGA etc. So I thought there must be a way to retrieve that information and analyse it, since its all geographic information which should be linked to the location coordinates. The answer was extracting the information through the process of reverse-geocoding.
在攻讀碩士學位的第二學期,我正在研究一個數據集,其中包含澳大利亞維多利亞州(2013-19年)道路交通事故的所有記錄。 我很好奇,維多利亞州哪些國道最危險,需要注意以提高安全性。 該數據集確實具有發生事故的經度和緯度坐標,但是它沒有其他支持和有用的信息,例如發生事故的道路名稱,郊區,LGA等。因此,我認為必須有一種方法檢索并分析該信息,因為應該將所有地理信息鏈接到位置坐標。 答案是通過反向地理編碼來提取信息。
What does Geocoding/Reverse-geocoding mean?
地理編碼/反向地理編碼是什么意思?
Geocoding is the process of converting addresses (like “1600 Amphitheatre Parkway, Mountain View, CA”) into geographic coordinates (like latitude 37.423021 and longitude -122.083739). This might be very useful if your planning to visualise the concentration of your data points in a map. Reverse geocoding is the process of converting geographic coordinates into a human-readable address. If you have good wrangling skills, you can extract other useful information like the nearby street/highway, district area or a landmark.
地理編碼是將地址(如“ 1600 Amphitheatre Parkway,Mountain View,CA”)轉換為地理坐標(如緯度37.423021和經度-122.083739)的過程。 如果您計劃可視化地圖中數據點的集中度,這可能非常有用。 反向地理編碼是將地理坐標轉換為人類可讀地址的過程。 如果您有良好的摔跤技巧,則可以提取其他有用的信息,例如附近的街道/高速公路,地區或地標。
My aim was to use reverse-geocoding to extract the name of the highways on which those accidents occurred. There are many platforms available for geocoding, but I used the Google Maps Platform. It is one of the best platforms available which gives you accurate and detailed information. It also offers free services for up to 100,000 requests.
我的目的是使用反向地理編碼來提取發生這些事故的高速公路的名稱。 有許多可用于地理編碼的平臺,但是我使用了Google Maps Platform。 它是可為您提供準確和詳細信息的最佳平臺之一。 它還為多達100,000個請求提供免費服務。
Implementation for Reverse-Geocoding
反向地理編碼的實現
I have used python here to implement reverse-geocoding.
我在這里使用python來實現反向地理編碼。
Step 1: — Get your Google API Key and enable Geocoding API service. You can refer to this YouTube link to help you set it up.
步驟1:—獲取您的Google API密鑰并啟用地址解析API服務。 您可以參考此YouTube 鏈接來幫助您進行設置。
Step 2: — Use the reverse_geocode function which converts the location coordinates and receives API output.
步驟2:—使用reverse_geocode函數轉換位置坐標并接收API輸出。
Remember you have to the input the location coordinates as a tuple. I have provided a screenshot of my implementation which converts 10 location coordinates and retrieves information in JSON format about the region via the API.
記住,您必須以元組的形式輸入位置坐標。 我提供了實現的屏幕截圖,該屏幕截圖可轉換10個位置坐標,并通過API以JSON格式檢索有關該區域的信息。

Note: For geocoding you have to use the ‘geocode(<address>)’ method. The result should be stored in a list of size 2.
注意:對于地理編碼,您必須使用'geocode(<address>)'方法。 結果應存儲在大小為2的列表中。
Step3: — Extracting the information in the API output to get the required information.
步驟3:—在API輸出中提取信息以獲取所需的信息。
This is perhaps the trickiest part of the implementation especially in reverse geocoding. There is a lot of information retrieved and you might need to wrangle the data you want before any analysis. Here’s how the output of one set of location coordinates i.e. (-37.81125,144.93391) in the above data frame looks like: -
這可能是實現過程中最棘手的部分,尤其是在反向地理編碼中。 檢索到很多信息,您可能需要在進行任何分析之前先整理所需的數據。 這是上述數據框中的一組位置坐標即(-37.81125,144.93391)的輸出如下所示:-

As you can clearly see in the output, the accident occurred on the ‘City Link’ Highway in Victoria.
從輸出中可以清楚地看到,事故發生在維多利亞州的“ City Link”高速公路上。
The problem I faced here was that the API output from all the accident records was not always in the same format as above. Many of them had different information put in different places. Hence I had to use my wrangling skills to extract the required information from each response.
我在這里遇到的問題是,所有事故記錄的API輸出并不總是與上述格式相同。 他們中許多人在不同的地方放置了不同的信息。 因此,我不得不使用自己的爭吵技巧從每個響應中提取所需的信息。
So, I came up with the idea of extracting the route number of the highway instead of the name on which the accidents occurred. The highways in Victoria are numbered in the pattern starting with ‘M’ and a number. For example, M2 here is the ‘City Link Highway’ or also known as the Western Link. This format was very easy to extract using ‘re’ package of python since it followed a definite pattern. After the extraction, I was easily able to convert these codes to their respective Highway names. I have provided an illustration of that code as well.
因此,我想到了提取高速公路的路線號而不是事故發生的名稱的想法。 維多利亞州的高速公路以“ M”和一個數字開頭。 例如,這里的M2是“城市鏈接高速公路”或也稱為“西方鏈接”。 這種格式很容易使用python的“ re”包提取,因為它遵循確定的模式。 提取后,我可以輕松地將這些代碼轉換為各自的公路名稱。 我也提供了該代碼的說明。
Note: You can also access the data through the JSON hierarchy, but then again it might not be the same always.
注意:您也可以通過JSON層次結構訪問數據,但是同樣,它也不一定總是相同的 。

Mission Accomplished!
任務完成!
I personally really enjoyed the process of getting more information to support my analysis of the data set. It gave me deeper insights and understanding of the frequency of road accidents taking place in Victoria. Many times the information is not as detailed as you would expect and you will have to merge other data sets to get more value out of your main data set. If the above explanations are not clear, do reach out to me via Linkedin & I will be happy to assist you. Thank You!
我個人真的很喜歡獲得更多信息以支持我對數據集進行分析的過程。 它使我對維多利亞州發生道路交通事故的頻率有了更深刻的了解和理解。 很多時候,信息沒有您期望的那么詳細,您將不得不合并其他數據集以從主數據集中獲得更多價值。 如果以上解釋不清楚,請通過Linkedin與我聯系,我們很樂意為您提供幫助。 謝謝!
翻譯自: https://medium.com/swlh/making-more-sense-of-your-data-through-geocoding-api-3bcbc609c993
api地理編碼
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/389238.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/389238.shtml 英文地址,請注明出處:http://en.pswp.cn/news/389238.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!