python实现逆地理转码
来源:互联网 发布:java 数组长度 long 编辑:程序博客网 时间:2024/05/02 03:08
用python 实现把经纬度坐标对应到各个城市的方法
参考文献地址http://www.cnblogs.com/giserliu/p/4982187.html
1.安装geopy
(1)可以用pip install geopy
(2)pycharm中选择file-setting-Projectuntitled-project Interpreter
2.程序代码
2.1反地理编码(将经纬度对应到城市)
from geopy.geocoders import Nominatimgeolocator = Nominatim()location = geolocator.reverse("51.43, 126.39")print(location.address)
2.2地理编码(城市对应到经纬度)
from geopy.geocoders import Nominatimgeolocator = Nominatim()location1 = geolocator.geocode("175 5th Avenue NYC")print((location1.latitude, location1.longitude))
问题二:
1.Python 中出现编译错误
address[i] =location.address.encode('utf')
借助百度api反地理编码
#coding=utf-8
import urllib2
import json
import os
import time
from time importsleep
url0 = 'http://api.map.baidu.com/geocoder/v2/?ak=你的密钥=renderReverse&location=%s,%s&output=json&pois=1' # % (lng,lat)
f = open('D:\\Max\\python2.12\\new\\201601.TXT')
head = f.readline()
n=0
p = open('E:\\pressure_201601.txt','w')
p.write(head.strip() + ' ' + 'address' + '\n')
p.close()
for line inf:
time.sleep(0.1) #暂停0.1秒
n = n + 1
l = line.strip().split(' ')
l = [i for i inl if i != '']
lng = str(float(l[2]) /100)
lat = str(float(l[1]) /100)
url = url0 % (lat, lng)
html = urllib2.urlopen(url)
try:
html = html.read().decode('utf-8')
index1 = html.find('(')
html = html[index1 + 1:-1]
html = json.loads(html)
address = html['result']['formatted_address']
print n
except:
address = 'wrong'
address1 = address.encode("utf8")
#print address
p = open('E:\\pressure_201601.txt','a')
p.write(line.strip() + ' ' + address1+'\n')
p.close()
print("ok")
- python实现逆地理转码
- 地理编码的实现
- 基于矢量数据的逆地理编码功能实现
- python地理数据处理库geopy
- 地理编码与逆地理编码
- CLGeocoder地理编码与逆地理编码
- 定位、地理编码、逆地理编码
- 地理反编码的实现
- No1 CoreLocation实现地理定位
- Android 实现地理定位功能
- 逆地理编码
- 地理
- iOS MapKit导航及地理转码辅助类
- Python 对城市进行地理编码
- Geopandas 安装 (python中的地理空间数据)
- pyecharts:基于python地理地图可视化详解
- Python地理数据处理之GDAL/OGR使用
- Python地理数据处理之Matplotlib安装使用
- Leetcode 237. Delete Node in a Linked List
- 两种解析URL的方法
- 用命令行创建.NET Core
- 第八周项目5—模式匹配(BT 、KMP算法)
- 第8周 项目4-字符串加密
- python实现逆地理转码
- 学习angulaujs2踩过的那些坑及注意事项(持续更新...)
- postgresql 删除失败 权限
- untiy 3d ShaderLab_第9章_2_球体阴影(一) 平行光对球体的投影
- fireFox post请求插件,火狐浏览器插件
- Gradle学习笔记--框架搭建
- Python中range函数的详细用法
- 从淘汰Oracle数据库的事情说起
- 树莓派部署nginx+php遇到的问题