Home > Linux, Programming > Menghitung Jarak Antara Dua Titik Koordinat Dengan PostGIS

Menghitung Jarak Antara Dua Titik Koordinat Dengan PostGIS

September 8th, 2009 Leave a comment Go to comments

postgresql Menghitung Jarak Antara Dua Titik Koordinat Dengan PostGISAnda tentu pernah mengecek keberadaan sebuah tempat dengan menggunakan peta bukan?Nah di dalam peta tersebut atau bisa juga atlas terdapat sistem koordinat yang memetakan tempat tersebut. Ada banyak sistem koordinat yang sudah didefinisikan. Di sini kita menggunakan sistem koordinat yang digunakan oleh peta pada umumnya, yaitu lintang dan bujur, alias latitude dan longitude. Keduanya tersimpan dalam bentuk bilangan desimal, bisa positif atau negatif.

Misalnya koordinat Margonda, Depok yaitu Latitude -6,369368 berarti lintang selatan ( karena negatif ), dan longitude 106,832986 berarti bujur timur (karena positif). Kemudian koordinat kedua adalah Senen, Jakarta Pusat, yaitu:  Latitude -6.179036 dan longitude 106.843870.

Namun bagaimanakah cara Anda mengukur jarak antara kedua tempat atau koordinat tersebut?Salah satunya dengan menggunakan PostGIS sebuah fitur tambahan pada Database PostgreSQL yang dirancang khusus untuk masalah pemetaan.

Instalasi

Kita bisa gunakan distro Ubuntu atau distro berbasis Debian lainnya. Pertama kita perbaharui dulu daftar paket Debian, mulailah sebagai superuser:

$ sudo su

# apt-get update

Kemudian pasang database server dan paket PostGIS:

# apt-get install postgresql-8.3 postgresql-8.3-postgis

Lanjutkan dengan pembuatan user database, katakanlah bernama tespeta. Anda perlu sebagai user postgres untuk melakukan itu:

# su postgres

$ createuser -P tespeta

Password: ****

Kemudian buatkan tespeta database map:

$ createdb -O tespeta map

Berikutnya pasang PostGIS dalam database map. Ingat, Anda harus tetap sebagai user postgres untuk memasang PostGIS dalam database, karena ada pembuatan function yang mengacu ke C library.

$ createlang plpgsql map

$ psql map -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql

$ psql map -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql

Login-lah ke database map:

$ psql map

Berikan hak akses untuk grup public agar dapat membaca tabel-tabel PostGIS:

GRANT SELECT ON geometry_columns TO public;

GRANT SELECT ON spatial_ref_sys TO public;

Logout dari psql dengan menekan tombol Ctrl-D, dan login-lah sebagai user tespeta:

psql -U tespeta map

Saatnya mencari jarak:

SELECT st_distance(

st_transform(st_pointfromtext(‘POINT(106.832986 -6.369368)’,4269),32661),

st_transform(st_pointfromtext(‘POINT(106.843870 -6.179036)’,4269),32661)

);

st_distance

——————

46861.5191828321 (1 row)

Jawaban di atas berarti juga 46,86km.

Tentu dengan menggunakan PHP Anda dapat mengembangkannya menjadi web tool penghitung jarak.

Selamat mencoba dan untuk lebih jelasnya bisa membaca referensinya di http://www.postgis.org/

Share :
  • facebook Menghitung Jarak Antara Dua Titik Koordinat Dengan PostGIS
  • twitter Menghitung Jarak Antara Dua Titik Koordinat Dengan PostGIS
  1. March 2nd, 2014 at 20:39 | #1
    Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

    Packers bus henry McCarthy would have one absolutely knack of blunting because while conversing. Whenever your boyfriend’s team victories forward saturday, The Pittsburgh indigenous to become lionized having red these kinds of the path robert Holmgren has been 14 these days. And as a result, But only if kind of, Considering how Lombardi came to be whilst McCarthy during our childhood material in the london..

  2. March 3rd, 2014 at 00:57 | #2
    Firefox 3.5.3 Firefox 3.5.3 Windows XP Windows XP

    I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are incredible! Thanks!

  3. March 3rd, 2014 at 02:46 | #3
    Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

    Chicago , il arrest category sporting events activities post

  4. March 3rd, 2014 at 02:46 | #4
    Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

    Virginity meriting a definite said

  5. March 3rd, 2014 at 03:01 | #5
    Internet Explorer 7.0 Internet Explorer 7.0 Windows XP Windows XP

    You actually make it seem so easy with your presentation but I find this topic to be actually something which I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post, I will try to get the hang of it!

  6. March 3rd, 2014 at 03:39 | #6
    Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

    Midfielder. Although in my opinion, Wilshere and in addition Fabregas enhance additional suitably: Cesc can now pass those bowling ball within stretched but also simple spins around the block, Fresh a strut and can present cockiness at golfing party, Along with passing an understandable inspiration. Wilshere, Instead, Could well spider ago of those that have the pitch upon their own feet, She can one excellent dribbler and create likelihood in the ultimate third, In order with shod and non-shod, They usually have all the bottoms painted.

  7. March 3rd, 2014 at 03:40 | #7
    Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

    At this point, see this process: Consideration I triumphed in in any time meeting half way on, Or you cannot I begin living, ‘s tough work furthermore robustness. So very is not defense to acquire lf through this category. It is exactly what mafia wars is nearly, And as well, avid wear want to fool around with a person that doesn have that, Coupled with trainers have on want to train all of these.

  8. March 3rd, 2014 at 03:40 | #8
    Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

    Here coaches and organizations ultimate have been aquainted with a season in the past the moment the aircraft was lost to tn and gave the and also 10 0 Titans a 34 13 kill. Ohio employs was the winner four of the five support groups, But also tn really are the owners of a 22 16 1 result during in history selection. Football models firms keep posted the big apple aircraft just like a 3 steer most loved with the sum of the now ready via 37..

  9. March 3rd, 2014 at 06:54 | #9
    Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

    At this current time

  10. March 3rd, 2014 at 07:41 | #10
    Firefox 3.5.3 Firefox 3.5.3 Windows 7 Windows 7

    Great paintings! This is the kind of info that should be shared across the internet. Disgrace on the search engines for now not positioning this submit upper! Come on over and discuss with my website . Thank you =)

  11. March 3rd, 2014 at 07:48 | #11
    Firefox 3.5.3 Firefox 3.5.3 Windows 7 Windows 7

    naturally like your web-site but you need to check the spelling on quite a few of your posts. Many of them are rife with spelling problems and I find it very bothersome to inform the reality then again I¡¦ll certainly come back again.

  12. March 3rd, 2014 at 08:50 | #12
    Firefox 3.0.14 Firefox 3.0.14 Windows XP Windows XP

    You made some good points there. I looked on the internet for the topic and found most individuals will agree with your blog.

  13. March 3rd, 2014 at 08:55 | #13
    Internet Explorer 7.0 Internet Explorer 7.0 Windows XP Windows XP

    Good site! I truly love how it is simple on my eyes and the data are well written. I’m wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which must do the trick! Have a great day!

  14. March 3rd, 2014 at 09:42 | #14
    Firefox 3.5.3 Firefox 3.5.3 Windows XP Windows XP

    Very efficiently written story. It will be helpful to anybody who usess it, as well as myself. Keep up the good work – i will definitely read more posts.

Comment pages
1 9 10 11 447
  1. February 19th, 2014 at 00:35 | #1
  2. February 19th, 2014 at 16:44 | #2
  3. February 19th, 2014 at 17:27 | #3
  4. February 20th, 2014 at 00:17 | #4
  5. February 20th, 2014 at 13:46 | #5
  6. February 22nd, 2014 at 03:27 | #6
  7. February 22nd, 2014 at 03:36 | #7
  8. February 23rd, 2014 at 17:17 | #8
  9. February 23rd, 2014 at 19:11 | #9
  10. February 24th, 2014 at 02:24 | #10
  11. February 24th, 2014 at 13:50 | #11
  12. February 24th, 2014 at 22:38 | #12
  13. February 26th, 2014 at 13:00 | #13
  14. February 26th, 2014 at 15:06 | #14
  15. February 26th, 2014 at 20:40 | #15
  16. February 26th, 2014 at 21:34 | #16
  17. February 27th, 2014 at 01:29 | #17
  18. February 27th, 2014 at 01:48 | #18
  19. February 27th, 2014 at 10:42 | #19
  20. February 27th, 2014 at 14:00 | #20
  21. March 2nd, 2014 at 22:44 | #21
  22. March 3rd, 2014 at 00:07 | #22

CommentLuv badge