Nematillo Ochilov
1.02K subscribers
337 photos
124 videos
383 files
685 links
Buxoro viloyati Gʻijduvon tumanida istiqomat qiluvchi dasturchi, @Nematillo_Ochilov

youtube.com/c/nematilloochilov
@NematilloOchilov - blog
@pythonuz - Python darslari
@js_uz - Java Script
@MQLUZ - Savdo robotlari
@sjtbot - Test kalitlarini tekshirish
Download Telegram
Nematillo Ochilov
PostgreSQLda geo ma'lumotlarni qaysi turda saqlash kerak va bir manzildan ikkinchi manzilgacha bo'lgan masofani PostgreSQLda qanday hisoblash mumkin? Yetkazib berish (dostavka) va yo'lovchi tashish (taxi) xizmatlarini onlayn tarzda tashkil qilish qiyin emas…
Postgisni ma'lumotlar bazasiga ulaymiz.

CREATE EXTENSION postgis;

Agar postgisni oldin o'rnatmagan bo'lsangiz quyidagi buyruqni terminalga yozib postgisni o'rnating.

sudo apt-get install postgresql-12-postgis-3

12 yoki 3 vaqt o'tishi bilan yangi talqinlarga o'zgarishi mumkin.

Jadval yaratmiz

CREATE TABLE oraliqmasofa (
id serial NOT NULL,
joy_nomi varchar(255) NOT NULL,
location Point NOT NULL,
PRIMARY KEY (id)
);

Jadvalga joy nomi va kordinatalarni kiritamiz.
(X gorizontal 41.2701661 va Y vertikal 69.3053935)

INSERT INTO oraliqmasofa (joy_nomi, location) VALUES 
( 'Toshkent', '(41.2701661, 69.3053935)' ),
( 'Andijon', '(40.7794781, 72.3737798)' );


SELECT * FROM oraliqmasofa;
id | joy_nomi | location
----+-----------+-------------------
1 | Toshkent | (41.2701661, 69.3053935)
2 | Andijon | (40.7794781, 72.3737798)
(2 rows)


Endi masofani tanlash uchun biz har doim yerni mukammal shar sifatida ishlatadigan ST_Distance_Spheredan foydalanishimiz mumkin, bu juda tez, ammo ST_DistanceSpheroiddan kamroq aniqroq. Ikkalasini ham sinab ko'raman:

ST_Distance_Sphere
SELECT ST_Distance_Sphere(geometry(a.location), geometry(b.location))
FROM oraliqmasofa a, oraliqmasofa b
WHERE a.id=1 AND b.id=2;
Natija: 262,797.01645757 metr.

ST_Distance_Spheroid
SELECT ST_Distance_Spheroid(geometry(a.location), geometry(b.location), 'SPHEROID["WGS 84",6378137,298.257223563]')
FROM oraliqmasofa a, oraliqmasofa b
WHERE a.id=1 AND b.id=2;
Natija: 263,430.941199621 metr.

#location #postgres #masofa #maps #distance

Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw
Bir manzildan ikkinchi manzilgacha bo'lgan yo'l masofasini aniqlash.

Bir manzildan ikkinchi manzilgacha bo'lgan yo'l masofasini aniqlash (to'g'ri chiziq bo'ylab emas yo'l bo'ylab) va taxminiy avtomobilda borish vaqtini ushbu funksiya yordamida bepul aniqlaymiz.1 kunda 22000 ta masofani tekshirish uchun so'rov yuborish mumkin.

import requests
import random


def route_distance(start, end): # yo'l masofasini o'lchash funksiyasi
keys_openrouteservice = [ # openrouteservice bepul kalitlari
"5b3ce3597851110001cf6248db84a52feecd456dbb2a4ee52a35ee4f",
"5b3ce3597851110001cf6248b44db44b33c64508afa658b8673c9580",
"5b3ce3597851110001cf6248701a505f4a83471da001d266b2860ac6",
"5b3ce3597851110001cf6248cbd8b98cf94b49998c93ca0605780f15",
"5b3ce3597851110001cf62480bea960faed84e018b953afbd3510ae7",
"5b3ce3597851110001cf62485788356becfe4894aba648ee6673baab",
"58d904a497c67e00015b45fc8129a6e7cd6d44aca2c1c45b56810512",
"5b3ce3597851110001cf6248e268bd7907a2427ba90d7d9555c20aac",
"5b3ce3597851110001cf6248e29e876eaf39498bb0b0b2ad0863e216",
"5b3ce3597851110001cf6248065eabf9d1e1454bbef78fe96f3016ec",
"5b3ce3597851110001cf62488ad066f5960f48e28aae44a1f27a245c"
]
key = random.choice(keys_openrouteservice) # taxminiy kalitlarni tanlash
url2 = f'https://api.openrouteservice.org/v2/directions/driving-car?api_key=' \
f'{key}&start={start}&end={end}'
d = requests.get(url2) # manzillar orasidagi yo'lni o'lshash uchun so'rov yuborish
z = d.json()['features'][0]['properties']['segments'][0]
distance = round(float(z['distance'])/1000, 2) # masofa km
duration = round(float(z['duration'])/60, 0) # vaqt minut
return [distance, duration]


rd = route_distance(
"69.241732,41.311668", # Istiqlol san'at saroyi
"69.316101,41.348023" # Toshkent botanika bog'i
)
print(f'Masofa: {rd[0]} km, Avtomobilda taxminiy borish vaqti: {rd[1]} minut')

>>> Masofa: 9.92 km, Avtomobilda taxminiy borish vaqti: 12.0 minut

#road #route #km #metr #gps #maps #free #xarita #online


Kanalga bepul obuna bo'lish👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw
Nematillo Ochilov
Location
Istalgan manzildagi telegram foydalanuvchilarini ko'rish uslubi.

Pyrogram kutubxonasida ushbu uslub orqali istalgan kordinatalardagi Nearby guruhlarni va guruhdagi foydalanuvchilarni ko'rishingiz mumkin.


Bu uslubni qayerda qo'llash foydaliroq?

Manzilga
aloqador guruh ochganda va guruhga aynan o'sha manzil foydalanuvchilarini guruhga qo'shish kerak bo'lganda ushbu uslub ayni muddao.
Masalan Toshkent shahrida kiyimlar do'koningiz bor va do'koningizda savdo hajmi susaygan.Bunday vaziyatda telegramda guruh ochib Toshkent shahrida istiqomat qilayotganlarni guruhga qo'shib mahsulotlarni reklama qilishingiz mumkin.


Yuqoridagi kodda Tashkent city kordinatasi namuna qilib ko'rsatilgan.

Manba: https://docs.pyrogram.org/api/methods/get_nearby_chats

#pyrogram #nearby #km #metr #gps #maps #free #xarita #online

@NematilloOchilov