gis Posts

How to Convert from a Point to a KML files and Generate a Circle with Radius on Each Point

Yesterday I got a challenging assignment to generate a telco network coverage map. But the only data i got is BTS (Base Transceiver Station) location, which is only latitude, longitude and coverage radius given on excel file. I need to convert those excel sheet data into a google map page, and displayed it to subscribers accordingly.

The biggest problem that i had is the number of data is quite big, i need to map more than 20k BTS location and need displayed it fast and without lagging. So a simple google maps script wont work because google maps have a limitation for this.

So i need to create a workaround, and after researching for quite some times i pick KML and Google FusionTable. KML data format for creating radius, and Google FusionTable for displaying it.

This is my PHP code for converting latitude, longitude and radius into KML code.

$lats = array('4.53191944444444','5.34593888888889');
$longs = array('97.93600000000001','95.99299999999999');
$meter = 2000; 
$kml = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="" xmlns:atom=""><Document>        
            <Style id="style0">

for($i = 0; $i < count($lats); $i++) {

    $lat = $lats[$i];
    $long = $longs[$i];

    // Get circle coordinates
    $coordinatesList = getCirclecoordinates($lat, $long, $meter);

    // Output
    $kml  .= '<Placemark><name>Circle '.$i.'</name><styleUrl>#style0</styleUrl><Polygon><outerBoundaryIs><LinearRing><coordinates>'.$coordinatesList.'</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark>';

$kml .= '</Document></kml>';
function getCirclecoordinates($lat, $long, $meter) {
  // convert coordinates to radians
  $lat1 = deg2rad($lat);
  $long1 = deg2rad($long);
  $d_rad = $meter/6378137;
  $coordinatesList = "";
  // loop through the array and write path linestrings
  for($i=0; $i<=360; $i+=3) {
    $radial = deg2rad($i);
    $lat_rad = asin(sin($lat1)*cos($d_rad) + cos($lat1)*sin($d_rad)*cos($radial));
    $dlon_rad = atan2(sin($radial)*sin($d_rad)*cos($lat1), cos($d_rad)-sin($lat1)*sin($lat_rad));
    $lon_rad = fmod(($long1+$dlon_rad + M_PI), 2*M_PI) - M_PI;
    $coordinatesList .= rad2deg($lon_rad).",".rad2deg($lat_rad).",0 ";
  return $coordinatesList;

$fp = fopen('e:\lele.kml', 'w');
fwrite($fp, $kml);

After KML is done, i just need to upload it to Google FusionTable and display it on my web page.


Daftar Kode Provinsi, Kecamatan, Kabupaten dan Desa di Indonesia Menurut Kemendagri

Setelah berkeliaran kesana-kesini, apalagi data kemendagri berupa pdf sehingga menyulitkan diparsing :-P , akhirnya dapet juga versi sql dari data Kemendagri. Setelah diparsing sehingga mysql-compatible, hasil akhir sql filenya bisa diunduh di —> sini

Data Kemendagri


Database KodePos Seluruh Indonesia

Awalnya iseng-iseng mencari data kodepos seluruh Indonesia, akhirnya dapet juga setelah email secara resmi ke PT Pos Indonesia. Namun file yang dikirimkan oleh PT Pos berupa file Excel (xls), walaupun dengan sedikit effort akhirnya bisa juga diimport ke database MySql.

Oh ya, file SQL-nya bisa didownload dari Github gw,

Semoga bisa membantu :-)


A Simple Indonesian Geographic Coordinate Conversion Between Degrees to Degree-Minute-Second (DMS)

Recently i have a simple GIS project which force me to display an Indonesian DMS coordinate format, instead of the usual decimal format. This is a simple utility class i used to do convertion.

import java.text.DecimalFormat;

public class DegreeConverterTest {

    public static final String LONGITUDE = "longitude";
    public static final String LATITUDE = "latitude";

    public DegreeConverterTest(String testName) {

    public static void main(String a[]) {
        System.out.println(degree2DMS(-8.857, LATITUDE));
        System.out.println(degree2DMS(10.645, LATITUDE));
        System.out.println(degree2DMS(135.696, LONGITUDE));

    public static String degree2DMS(double coordinate, String mode) {
        String dms = "";

        char degree = '\u00B0';
        int degLong, minLongA;
        double minLong, secLong;
        DecimalFormat df = new DecimalFormat("#,###,####0.0000");

        if (LONGITUDE.equals(mode)) {
            // minus is BB (Bujur Barat or west longitude)
            // plus is BT (Bujur Timur of east longitude)
            degLong = (int) coordinate;
            minLong = (coordinate % 1) * 60;
            minLongA = (int) minLong;
            secLong = (minLong % 1) * 60;
            String secLongAs = String.valueOf(df.format(secLong));
            dms = degLong + degree + " " + minLongA + "' " + secLongAs + "\" BT";
        } else if (LATITUDE.equals(mode)) {
            // minus is LS (Lintang Selatan or south latitude)
            // plus is LU (Lintang Utara or north latitude)
            boolean isMinus = true;
            String minusDegree = "LS";
            degLong = (int) coordinate;
            String degLongS = String.valueOf(degLong);
            if (degLongS.contains("-")) {
                degLongS = degLongS.replace("-", "");
            } else {
                isMinus = false;
                minusDegree = "LU";

            minLong = (coordinate % 1) * 60;
            minLongA = (int) minLong;
            String minLongAs = String.valueOf(minLongA);
            if (isMinus) {
                minLongAs = minLongAs.replace("-", "");

            secLong = (minLong % 1) * 60;
            String secLongAs = String.valueOf(df.format(secLong));
            if (isMinus) {
                secLongAs = secLongAs.replace("-", "");

            dms = degLongS + degree + " " + minLongAs + "' " + secLongAs + "\" " + minusDegree;
        return dms;

And this is the output i got on my netbeans’ console

8° 51' 25.2000" LS
10° 38' 42.0000" LU
311 41' 45.6000" BT

Daftar Kode Provinsi, Kecamatan, Kabupaten dan Desa di Indonesia Menurut Kode BPS

Kali ini gw kembali menulis tentang GIS, berawal dari masalah yang gw temui di project terbaru gw terkait geospasial Indonesia. Disana gw kesulitan untuk mendapatkan kode dan nama wilayah di Indonesia secara sistematis, akhirnya gw bikin versi sql-nya. Semoga data gw bisa bermanfaat bagi seluruh penggiat spasial Indonesia (Y)

SQL File-nya bisa diunduh —> disini

database kabupaten sql

database kabupaten sql