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
CHAR(n), VARCHAR(n), VARCHAR, text?
Eng maqbul yechim text ekan.
#postgres #text
Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw
Eng maqbul yechim text ekan.
#postgres #text
Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw