118 lines
3.4 KiB
Python
118 lines
3.4 KiB
Python
import traceback
|
|
import requests
|
|
import json
|
|
import math
|
|
import os,django
|
|
|
|
from haversine import haversine
|
|
from re import match
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
from datetime import datetime, timedelta,date
|
|
from requests.auth import HTTPBasicAuth
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mfssogr.settings')
|
|
django.setup()
|
|
|
|
from apps.general.views import settingsmodule
|
|
|
|
def num_decimal_places(number):
|
|
return len(
|
|
(str(number) if '.' in str(number) \
|
|
else str(number) + '.').rstrip('0').split('.')[-1]
|
|
)
|
|
|
|
def go_to_metr(x, y, name_coordinate):
|
|
required_dist = 1
|
|
l = 0
|
|
r = min(180, 90-y)
|
|
while r-l > 1e-10:
|
|
m=(r+l)/2
|
|
|
|
dist = (
|
|
(haversine((x,y),(x,y+m))/1000)
|
|
) if name_coordinate == "y" else (
|
|
(haversine((x,y),(x+m,y))/1000)
|
|
)
|
|
|
|
if dist > required_dist:
|
|
r = m
|
|
else:
|
|
l = m
|
|
|
|
step = float(int(l))
|
|
|
|
numb_digit = 1
|
|
|
|
for _ in range(
|
|
num_decimal_places(y if name_coordinate == "y" else x)
|
|
):
|
|
numb_digit *= 10
|
|
|
|
step = step/numb_digit
|
|
finally_coordinate = x+step if name_coordinate == "x" else y+step
|
|
return finally_coordinate
|
|
|
|
|
|
def go_to_radius(init_x, init_y, radius):
|
|
array_coord_x = []
|
|
array_coord_y = []
|
|
for coordinate in ["x", "y"]:
|
|
local_coord = init_x if coordinate == "x" else init_y
|
|
init_coord = init_y if coordinate == "x" else init_x
|
|
|
|
array_coord = array_coord_x if coordinate == "x" else array_coord_y
|
|
|
|
for _ in range(radius):
|
|
local_coord = go_to_metr(
|
|
local_coord if coordinate == "x" else init_coord,
|
|
init_coord if coordinate == "x" else local_coord, coordinate)
|
|
array_coord.append(
|
|
(
|
|
(local_coord, init_coord)
|
|
) if coordinate == "x" else (
|
|
(init_coord, local_coord)
|
|
)
|
|
)
|
|
array_coord_all = []
|
|
|
|
for numb, _ in enumerate(range(len(array_coord_x))):
|
|
array_coord_all.append((array_coord_x[numb][0], array_coord_y[numb][1]))
|
|
return {
|
|
"coords_x": array_coord_x, "coords_y": array_coord_y,
|
|
"coords_all": array_coord_all
|
|
}
|
|
|
|
def test_glonas():
|
|
try:
|
|
response = requests.get('https://ask-glonass.ru/api/main?func=auth&login=demo&password=demo')
|
|
js = response.json()
|
|
|
|
except Exception as err:
|
|
print(traceback.format_exc())
|
|
|
|
|
|
def geo(latitude,longitude):
|
|
dist = int(settingsmodule.get_settings('seism_km',1000))
|
|
mylon = float(settingsmodule.get_settings('longitude','86.10111978605353'))
|
|
mylat = float(settingsmodule.get_settings('latitude','55.344251210827814'))
|
|
lon1 = mylon-dist/abs(math.cos(math.radians(mylat))*111.0) # 1 градус широты = 111 км
|
|
lon2 = mylon+dist/abs(math.cos(math.radians(mylat))*111.0)
|
|
lat1 = mylat-(dist/111.0)
|
|
lat2 = mylat+(dist/111.0)
|
|
print ('lat1 = '+str(lat1))
|
|
print ('lat2 = '+str(lat2))
|
|
|
|
print ('lon1 = '+str(lon1))
|
|
print ('lon2 = '+str(lon2))
|
|
if (latitude >= lat1 and latitude <= lat2) and (longitude >=lon1 and longitude<=lon2):
|
|
return True
|
|
return False
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(geo(55.34096929253043, 86.11575399794566))
|
|
#pprint(go_to_radius(55.38932757295573, 86.10670766964053, 5000))
|