Nematillo Ochilov
1.03K 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
CHAR(n), VARCHAR(n), VARCHAR, text?

Eng maqbul yechim text ekan.

#postgres #text

Kanalga a'zo bo'lish 👇
https://t.me/joinchat/AAAAAD6YXE73Trzz2TcWdw