Archive for the ‘IT’ Category

Postgres earthdistance vs PostGIS

April 24th, 2012 1 comment

I needed to calculate the distance between to GPS coordinates. I have found couple of methods.

1. Postgres earthdistance
you need to install the contrib package for postgres. Import the cube.sql and the earthdistance.sql. More about this at postgresql docs

psql -d yourdatabase -f cube.sql
psql -d yourdatabase -f earthdistance.sql

To test:

(point (47.5047554664,19.0479136054) <@> point (47.5049898995,19.0469509363))
AS distance;

This is in statute miles. Simply multiple by 1.609344 to have it in km.

2. PostGIS 2.0

After installing and importing the required postgis.sql and spatial_ref_sys.sql
you will have a lot of nice support for geographic object in your database. read more on the PostGIS site. ST_distance_sphere is considered the most accurate function to calculate the distance between 2 GPS points result is in meters.

Here is the verdict:

  ST_GeomFromText('POINT(47.5047554664 19.0479136054)',4326),
  ST_GeomFromText('POINT(47.5049898995 19.0469509363)',4326),
  'SPHEROID["WGS 84",6378137,298.257223563]') 
 AS NUMERIC),4) AS spheroid,
  ST_GeomFromText('POINT(47.5047554664 19.0479136054)',4326),
  ST_GeomFromText('POINT(47.5049898995 19.0469509363)',4326)
 ) AS NUMERIC),4) 
 AS sphere,
  ((point (47.5047554664,19.0479136054) 
  point (47.5049898995,19.0469509363)) * 1.609344)
 AS NUMERIC) * 1000,4)
 AS earthdistance;
 spheroid |  sphere  | earthdistance 
 109.3804 | 109.8435 |      109.8431

there is not much difference, now it will be question of performance.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

emacs commenting lines

July 1st, 2011 No comments

I was wondering if the comment-dwin (M-;) command could be changed that if i am anywhere in the line the whole line is commented and not a comment started from the end of the line. based on the idea found in a mailing list i altered the command with

(defun comment-dwim-line (&optional arg)
  (interactive "*P")
  (if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
      (comment-or-uncomment-region (line-beginning-position) (line-end-position))
    (comment-dwim arg)))
(global-set-key "\M-;" 'comment-dwim-line)

add this to your .emacs file and enjoy.

Categories: IT
Tags: , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Install Emacs from source on MAC OS X

April 29th, 2011 1 comment

How to install Emacs from source?

You will need Xcode tools to perform this operation.

MacBook-Pro: mkdir src
MacBook-Pro: cd src
MacBook-Pro: cvs -z3 co emacs
MacBook-Pro: cd emacs
MacBook-Pro: ./configure --with-ns --with-jpeg=no --with-gif=no --with-tiff=no
MacBook-Pro: make bootstrap
MacBook-Pro: make
MacBook-Pro: make install
MacBook-Pro: sudo cp -r nextstep/ /Applications/

if you would like to use it in terminal

MacBook-Pro: cd src
MacBook-Pro: make
MacBook-Pro: cp emacs /usr/bin/emacs
MacBook-Pro: emacs --version
GNU Emacs
Copyright (C) 2009 Free Software Foundation, Inc.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
MacBook-Pro: emacs -nw
Categories: MAC OS X
Tags: , ,
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Hidden files

October 10th, 2010 No comments

open a terminal and run the following to show hidden files

MacBook-Pro: defaults write AppleShowAllFiles true
MacBook-Pro: killall Finder

to hide them run the following

MacBook-Pro: defaults write AppleShowAllFiles false
MacBook-Pro: killall Finder
Categories: MAC OS X
Tags: ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

MAC OS X filling up free space

October 10th, 2010 1 comment

I have my MacBookPro for 1 year now, and recently I had to often the message that my MAC OS X HDD is running out of space, and effectively finder said ZeroKB, df -h 0 available. As I was installing quite a lot of apps for test during the last year, I have decided to reinstall snow leopard.
Read more…

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)