Python 空间数据处理


Geopy测试

GeoCodeing:得出具体的地址

from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.geocode("中国人民大学")
print(location.address)
中国人民大学, 人民大学北路, 稻香园南社区, 海淀区, 北京市, 100872, 中国

经纬度信息

print((location.latitude, location.longitude))
(39.96976785, 116.307086480528)

反向解码:通过经纬度信息得到具体的地址

location1 = geolocator.reverse("29.60173, 103.48222")
print location1.address
名山中路, 峨眉山市, 峨眉山市 / Emeishan, 乐山市 / Leshan, 四川省, 中国
location1.point
Point(29.6015657, 103.4791074, 0.0)

坐标位置的具体信息

location1.raw
{u'address': {u'city': u'\u5ce8\u7709\u5c71\u5e02',
  u'country': u'\u4e2d\u56fd',
  u'country_code': u'cn',
  u'county': u'\u5ce8\u7709\u5c71\u5e02 / Emeishan',
  u'road': u'\u540d\u5c71\u4e2d\u8def',
  u'state': u'\u56db\u5ddd\u7701',
  u'state_district': u'\u4e50\u5c71\u5e02 / Leshan'},
 u'boundingbox': [u'29.5996549',
  u'29.6015657',
  u'103.4791074',
  u'103.4885191'],
 u'display_name': u'\u540d\u5c71\u4e2d\u8def, \u5ce8\u7709\u5c71\u5e02, \u5ce8\u7709\u5c71\u5e02 / Emeishan, \u4e50\u5c71\u5e02 / Leshan, \u56db\u5ddd\u7701, \u4e2d\u56fd',
 u'lat': u'29.6015657',
 u'licence': u'Data \xa9 OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright',
 u'lon': u'103.4791074',
 u'osm_id': u'297311246',
 u'osm_type': u'way',
 u'place_id': u'125494104'}

距离的测量

  • Geopy can calculate geodesic distance between two points using the Vincenty distance or great-circle distance formulas, with a default of Vincenty available as the class geopy.distance.distance, and the computed distance available as attributes (e.g., miles, meters, etc.).
from geopy.distance  import vincenty,great_circle
newport_ri = (29.60173, 103.48222)  #峨眉山
cleveland_oh = (39.96976785, 116.307086480528)  # 中国人民大学
print(vincenty(newport_ri, cleveland_oh).km)
1640.02356001
print(great_circle(newport_ri,cleveland_oh).km)
aa=great_circle(newport_ri,cleveland_oh)
1640.52238261
from geopy import Location
aa=Location(address="峨眉山")
print aa.address
峨眉山

下面演示geopy 利用http://nominatim.openstreetmap.org/ 封装细节

import urllib2
from  bs4  import BeautifulSoup
def getDetailUrl(search_add):
    nominatim="http://nominatim.openstreetmap.org/"

    search_url=nominatim+"search.php?q=%s&polygon=1" %search_add
    # urllib2.urlopen(search_url)
    req=urllib2.Request(search_url)
    cont=BeautifulSoup(urllib2.urlopen(req))
    detail_url_suffix=cont.find('a',class_="btn btn-default btn-xs details")
    detail_url=nominatim+detail_url_suffix['href']
    detail_cont=BeautifulSoup(urllib2.urlopen(detail_url))
    return detail_cont
search_add="中国人民大学"
detail_cont=getDetailUrl(search_add)
print detail_cont.find("table",id="locationdetails").text
Name 中国人民大学 (name)
Chinesische Volksuniversität (name:de)
Renmin University of China (name:en)
Université populaire de Chine (name:fr)
中国人民大学 (name:zh)

Typeamenity:university
Last Updated2015-12-25 09:18
Admin Level15
RankOther: 30
CoveragePolygon
Centre Point39.96976785,116.307086480528
OSMway 30725330
Extra Tags http://www.ruc.edu.cn/ (website)
print detail_cont.find("table",id="address").text
Local name
Type
OSM
Admin level

Distance





中国人民大学
amenity:university


0
details >


人民大学北路
highway:residential
way 165743483
15
0
details >


稻香园南社区
place:village
node 2036482794
15
0
details >


海淀路社区
place:village
node 2449570839
15
0
details >


海淀区
place:suburb
relation 5505984
6
0
details >


北京市
place:state
relation 912940
4
0
details >


100872
place:postcode


0
details >


中国
place:country
relation 270056
2
~13 m
details >


cn
place:country_code


0
details >

转载自:https://blog.csdn.net/weiyudang11/article/details/52495645

You may also like...

退出移动版