簡體   English   中英

從文本文件中提取某些數據 - 字符串操作

[英]Extract certain data from text file - string manipulation

我正在嘗試處理一個文本文件並使用 python 提取所有經緯度實例,但是自從我使用它已經很多年了,我什至不知道該用什么谷歌來幫助。 在下面的示例中,我想要每個 start_location 和 end_location 的位置,然后將該數據放入單獨的文件中。

           ""start_address"" : ""Aberdeen, SD 57401, USA"",
               ""start_location"" : {
                  ""lat"" : 45.4646954,
                  ""lng"" : -98.48596610000001
               },
               ""steps"" : [
                  {
                     ""distance"" : {
                        ""text"" : ""207 ft"",
                        ""value"" : 63
                     },
                     ""duration"" : {
                        ""text"" : ""1 min"",
                        ""value"" : 13
                     },
                     ""end_location"" : {
                        ""lat"" : 45.4641268,
                        ""lng"" : -98.48597479999999
                     },
                     ""html_instructions"" : ""Head \u003cb\u003esouth\u003c/b\u003e on \u003cb\u003eCourt St\u003c/b\u003e toward \u003cb\u003e1st Ave SE\u003c/b\u003e"",
                     ""polyline"" : {
                        ""points"" : ""kyntGhpbxQhA?f@?""
                     },

似乎這可以幫助你: http : //fredgibbs.net/tutorials/extract-geocode-placenames-from-text-file.html

正如你在鏈接中看到的,這個人得到了一些與你的格式類似的坐標,正如我在這里粘貼的那樣:

 . . . ], "formatted_address" : "Albuquerque, NM, USA", "geometry" : { "bounds" : { "northeast" : { "lat" : 35.2180539, "lng" : -106.4711629 }, "southwest" : { "lat" : 34.9467659, "lng" : -106.881796 } }, "location" : { "lat" : 35.110703, "lng" : -106.609991 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 35.2180539, "lng" : -106.4711629 }, "southwest" : { "lat" : 34.9467659, "lng" : -106.881796 } . . .

然后將其作為 JSON 處理:

 json = r.json() lat = json['results'][0]['geometry']['location']['lat'] lng = json['results'][0]['geometry']['location']['lng']

注意此人從 Google 請求坐標,但可以針對您的問題復制此坐標

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM