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.
Jadval yaratmiz
(X gorizontal 41.2701661 va Y vertikal 69.3053935)
----+-----------+-------------------
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
ST_Distance_Spheroid
#location #postgres #masofa #maps #distance
Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw
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 (Jadvalga joy nomi va kordinatalarni kiritamiz.
id serial NOT NULL,
joy_nomi varchar(255) NOT NULL,
location Point NOT NULL,
PRIMARY KEY (id)
);
(X gorizontal 41.2701661 va Y vertikal 69.3053935)
INSERT INTO oraliqmasofa (joy_nomi, location) VALUESid | joy_nomi | location
( 'Toshkent', '(41.2701661, 69.3053935)' ),
( 'Andijon', '(40.7794781, 72.3737798)' );
SELECT * FROM oraliqmasofa;
----+-----------+-------------------
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))Natija: 262,797.01645757 metr.
FROM oraliqmasofa a, oraliqmasofa b
WHERE a.id=1 AND b.id=2;
ST_Distance_Spheroid
SELECT ST_Distance_Spheroid(geometry(a.location), geometry(b.location), 'SPHEROID["WGS 84",6378137,298.257223563]')Natija: 263,430.941199621 metr.
FROM oraliqmasofa a, oraliqmasofa b
WHERE a.id=1 AND b.id=2;
#location #postgres #masofa #maps #distance
Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw
Obektni belgilangan hududda ekanligini nazorat qilish.
Obekt kordinatalarini doim aniqlay olasiz va obekt belgilab qo'ygan hududingizdan chiqib ketishini nazorat qilish uchun ushbu koddan foydalanishingiz mumkin.
Masalan sizda Tashkent cityda yetkazib berish xizmati bor deylik. Yetkazib beruvchi ish vaqtida Tashkent city hududidan chiqishi mumkin emas. Yetkazib beruvchi yukni olib ketayotganda telegram guruhingizga live locationni tashlab qo'yadi va bot uni ma'lum hududdan chiqib ketmasligini avtomatik nazorat qiladi. Agar belgilangan hududni tark etsa bot guruhga yetkazib beruvchi hududni tark etganini eslatadi.
#location #geo #python #point #shapely #polygon
Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw
Obekt kordinatalarini doim aniqlay olasiz va obekt belgilab qo'ygan hududingizdan chiqib ketishini nazorat qilish uchun ushbu koddan foydalanishingiz mumkin.
Masalan sizda Tashkent cityda yetkazib berish xizmati bor deylik. Yetkazib beruvchi ish vaqtida Tashkent city hududidan chiqishi mumkin emas. Yetkazib beruvchi yukni olib ketayotganda telegram guruhingizga live locationni tashlab qo'yadi va bot uni ma'lum hududdan chiqib ketmasligini avtomatik nazorat qiladi. Agar belgilangan hududni tark etsa bot guruhga yetkazib beruvchi hududni tark etganini eslatadi.
# pip3 install Shapely
from shapely.geometry import Point, Polygon
# Obektni yaratish
obekt1= Point(41.113411, 65.365202)
obekt2 = Point(41.106910, 65.409277)
# Ko'pburchak yaratish. kordinatalar https://www.google.com/maps saytidan olindi
coords = [
(41.083028, 65.430785),
(41.072987, 65.418473),
(41.074045, 65.389805),
(41.089205, 65.356101),
(41.146976, 65.339829),
(41.146054, 65.381927),
(41.118575, 65.393169),
(41.095997, 65.389417)
]
poly = Polygon(coords)
print(obekt1.within(poly))
# >>> True # obekt1 kopburchak ichida
print(obekt2.within(poly))
# >>> False # obekt2 kopburchak ichida emas
Agar kodga tushunmagan bo'lsangiz kanal a'zolari 3000 taga yetganda ushbu kodni amaliy batafsil tushuntirib videodars tayyorlayman.#location #geo #python #point #shapely #polygon
Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw