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:

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

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:

SELECT 
round(
 CAST(
  ST_Distance_Spheroid(
  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,
round(
 CAST(
 ST_distance_sphere(
  ST_GeomFromText('POINT(47.5047554664 19.0479136054)',4326),
  ST_GeomFromText('POINT(47.5049898995 19.0469509363)',4326)
 ) AS NUMERIC),4) 
 AS sphere,
round(
 CAST(
  ((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)
Loading...

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

;; http://www.opensubscriber.com/message/emacs-devel@gnu.org/10971693.html
(defun comment-dwim-line (&optional arg)
  (interactive "*P")
  (comment-normalize-vars)
  (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)
Loading...

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 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/emacs 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/Emacs.app /Applications/Emacs.app

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 23.1.90.1
Copyright (C) 2009 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
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)
Loading...

Hidden files

October 10th, 2010 No comments

open a terminal and run the following to show hidden files

MacBook-Pro: defaults write com.apple.Finder AppleShowAllFiles true
MacBook-Pro: killall Finder

to hide them run the following

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

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)
Loading...

http monitoring with God

August 26th, 2010 No comments

A few more line to the monitoring of yesterday

[...]
    w.restart_if do |restart|
      restart.condition(:http_response_code) do |c|
        c.host = 'localhost'
        c.port = port
        c.path = '/'
        c.code_is_not = 200
        c.timeout = 3.seconds
        c.times = [2, 5]
      end
[...]
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

still this performance issue

August 26th, 2010 No comments

Unfortunately my previous solution was only temporary, after a while I mentioned that mongrels are eating the memory and hanging.
Read more…

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

redmine on nginx with mongrel_cluster performace

August 25th, 2010 No comments

I have seen some serious performance issues and some error messages with nginx and mongrel_cluster.
Read more…

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...