判断百度某一经纬度的地图颜色值python

时间:2023-03-09 13:37:10
判断百度某一经纬度的地图颜色值python
 from PIL import Image
import MySQLdb
import os
import urllib
import time
from multiprocessing.dummy import Pool as ThreadPool def gaidu_is_water((latitude,longitude)):
while True:
try:
ll = longitude + ',' + latitude
url = "http://api.map.baidu.com/staticimage?center="+ll+"&zoom=18&width=1&height=1"
data = urllib.urlretrieve(url, ll)
im = Image.open(ll)
rgb_im = im.convert('RGB')
print rgb_im.getpixel((0, 0))
if rgb_im.getpixel((0, 0)) in [(167, 192, 224),(104, 137, 167),(153, 183, 219)]:
# print 'is water'
flag = 1
else:
flag = 0
# print 'not water'
# print ll,'ok'
break
except Exception, e:
print e
time.sleep(5)
continue if __name__ == '__main__':
print gaidu_is_water('114.24419,22.332689')
pool = ThreadPool(20)
results = pool.map(gaidu_is_water, lls)
pool.close()
pool.join()