从文本文件字符串操作中提取某些数据

2024-10-09 01:21:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试处理一个文本文件,并使用python提取Lat/Lon的所有实例,但自从我使用它以来,已经有这么多年了,我甚至不知道谷歌需要什么帮助。在下面的示例中,我需要每个开始位置的位置&;结束_位置,然后将该数据放入一个单独的文件中

           ""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@?""
                     },

Tags: 实例text示例valuelocationstartamplon
1条回答
网友
1楼 · 发布于 2024-10-09 01:21:41

似乎这可以帮助您:http://fredgibbs.net/tutorials/extract-geocode-placenames-from-text-file.html

正如您在链接中看到的,此人获得了一些与您的格式类似的坐标,我将其粘贴到这里:

&13; 第13部分,;
.
.
.
   ],
     "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
           }           
.
.
.
和#13;
和#13;

然后将其作为JSON处理,如下所示:

&13; 第13部分,;
json = r.json()
lat = json['results'][0]['geometry']['location']['lat']
lng = json['results'][0]['geometry']['location']['lng']
和#13;
和#13;

注意 此人要求谷歌提供坐标,但这可能会被复制以解决您的问题

相关问题 更多 >

    热门问题