добавил заготовку и r.txt
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
def get_a_useless_value(envelope):
|
||||||
|
l, b = envelope["lowerCorner"].split(" ")
|
||||||
|
r, t = envelope["upperCorner"].split(" ")
|
||||||
|
return [str(abs(float(l) - float(r)) / 2.0), str(abs(float(t) - float(b)) / 2.0)]
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import sys
|
||||||
|
from io import BytesIO
|
||||||
|
from get_a_useless_value import get_a_useless_value
|
||||||
|
import requests
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
# Пусть наше приложение предполагает запуск:
|
||||||
|
# python search.py Москва, ул. Ак. Королева, 12
|
||||||
|
# Тогда запрос к геокодеру формируется следующим образом:
|
||||||
|
toponym_to_find = " ".join(sys.argv[1:])
|
||||||
|
|
||||||
|
geocoder_api_server = "http://geocode-maps.yandex.ru/1.x/"
|
||||||
|
|
||||||
|
geocoder_params = {
|
||||||
|
"apikey": "40d1649f-0493-4b70-98ba-98533de7710b",
|
||||||
|
"geocode": toponym_to_find,
|
||||||
|
"format": "json"}
|
||||||
|
|
||||||
|
response = requests.get(geocoder_api_server, params=geocoder_params)
|
||||||
|
|
||||||
|
if not response:
|
||||||
|
# обработка ошибочной ситуации
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Преобразуем ответ в json-объект
|
||||||
|
json_response = response.json()
|
||||||
|
# Получаем первый топоним из ответа геокодера.
|
||||||
|
toponym = json_response["response"]["GeoObjectCollection"][
|
||||||
|
"featureMember"][0]["GeoObject"]
|
||||||
|
# Координаты центра топонима:
|
||||||
|
toponym_coodrinates = toponym["Point"]["pos"]
|
||||||
|
# Долгота и широта:
|
||||||
|
vrem = []
|
||||||
|
for i in toponym_coodrinates.split(" "):
|
||||||
|
vrem.append(float(i))
|
||||||
|
point = vrem
|
||||||
|
org_point = "{0},{1}".format(point[0], point[1])
|
||||||
|
toponym_longitude, toponym_lattitude = toponym_coodrinates.split(" ")
|
||||||
|
# Собираем параметры для запроса к StaticMapsAPI:
|
||||||
|
map_params = {
|
||||||
|
"ll": ",".join([toponym_longitude, toponym_lattitude]),
|
||||||
|
"spn": ",".join(get_a_useless_value(toponym["boundedBy"]["Envelope"])),
|
||||||
|
"l": "map",
|
||||||
|
"pt": "{0},pm2dgl".format(org_point)
|
||||||
|
}
|
||||||
|
|
||||||
|
map_api_server = "http://static-maps.yandex.ru/1.x/"
|
||||||
|
# ... и выполняем запрос
|
||||||
|
response = requests.get(map_api_server, params=map_params)
|
||||||
|
|
||||||
|
Image.open(BytesIO(
|
||||||
|
response.content)).show()
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
from PyQt5.QtGui import QPixmap
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class Window(QMainWindow):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.acceptDrops()
|
||||||
|
self.setWindowTitle("Image")
|
||||||
|
self.setGeometry(0, 0, 400, 300)
|
||||||
|
self.label = QLabel(self)
|
||||||
|
self.pixmap = QPixmap('image.png')
|
||||||
|
self.label.setPixmap(self.pixmap)
|
||||||
|
self.label.resize(self.pixmap.width(), self.pixmap.height())
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
|
App = QApplication(sys.argv)
|
||||||
|
window = Window()
|
||||||
|
sys.exit(App.exec())
|
||||||
Reference in New Issue
Block a user