Calculate the distance between two GPS-Coordinates (ctd.)

September 17th, 2007 by exhuma.twn

And here’s the same thing as plpgsql function for Postgres:

CREATE OR REPLACE FUNCTION lldistance( a point, b point)
RETURNS float AS $$
DECLARE    x FLOAT;
        dlat FLOAT;
        dlon FLOAT;
BEGIN
   dlat = radians(a[0]-b[0]);
   dlon = radians(a[1]-b[1]);
   x := sin(dlat/2)^2 +
        cos(radians(a[0])) * cos(radians(b[0])) *
        sin(dlon/2)^2;
   RETURN 6367442.5 * (2*atan2(sqrt(x), sqrt(1-x)));
END;
$$ LANGUAGE plpgsql

This results in more accurate distances than simply using

SELECT point1 <-> point2 FROM sometable;

You could also use plpython as function language and copy/paste the earlier post, but plpgsql is more portable.

Posted in Coding Voodoo | 1 Comment »

Calculate the distance between two GPS-Coordinates

September 17th, 2007 by exhuma.twn

This function uses the Haversine formula to calculate the distance which takes into account the spherical nature of the earth.
As the earth is not a perfect sphere, this function approximates this by using the average radius.

from math import sin, cos, radians, sqrt, atan2

def lldistance(a, b):
   """
   Calculates the distance between two GPS points (decimal)
   @param a: 2-tuple of point A
   @param b: 2-tuple of point B
   @return: distance in m
   """

   r = 6367442.5             # average earth radius in m
   dLat = radians(a[0]-b[0])
   dLon = radians(a[1]-b[1])
   x = sin(dLat/2) ** 2 + \
       cos(radians(a[0])) * cos(radians(b[0])) *\
       sin(dLon/2) ** 2
   y = 2 * atan2(sqrt(x), sqrt(1-x))
   d = r * y

   return d

Posted in Python | 1 Comment »

Centering a window on the screen with Qt

September 10th, 2007 by exhuma.twn

Yet another thing that’s not automagic in Qt.
Here’s a python solution:

if __name__ == "__main__":

   app = QtGui.QApplication(sys.argv)

   dw = app.desktop().width()
   dh = app.desktop().height()

   myapp = MainWindow()
   myapp.setGeometry(
         int((dw - (dw - (dw / 2)) * 1.5) / 2),
         int((dh - (dh - (dh / 2)) * 1.5) / 2),
         int((dw - (dw / 2)) * 1.5),
         int((dh - (dh / 2)) * 1.5))
   myapp.show()
   sys.exit(app.exec_())

This will also resize the window, adapting to the desktop size.
Found and adapted from the Qt interest archive.

Posted in Python | No Comments »

Adding Scrollbars to a QFrame in Qt

September 10th, 2007 by exhuma.twn

Many things are very easy to accomplish in Qt. Qt’s designer is a great help with that. But the is no option to simply “enable” scrollbars for a frame. Also, the QScrollArea can nowhere be found in the designer. The solution is actually quite simple:

  1. Add the component you want to be scrollable (QFrame, QLabel, …) in the designer as usual
  2. In the application code:
    1. Create a new QScrollArea
    2. Set the parent of the widget you created in the designer to “None”
    3. Set the widget of the QScrollArea to the widget from step 1
    4. Insert the QScrollArea to you ui

And here’s some example code (boiled down to the essentials):

sa = QtGui.QScrollArea()
self.ui.myWidget.setParent(None)
sa.setWidget(self.ui.myWidget)
self.ui.vboxlayout1.insertWidget(0, sa)

You would probably write this somewhere in you application-constructor right after you call setupUi.

This will insert the scroll area at the top of vboxlayout1 (see the doc for insertWidget). You can of course also use addWidget.

It’s a shame that there’s no direct support for QScrollArea in designer. Maybe we will see it in some future release.

An example for C++ can be found in the Qt Forums.

Posted in Python | 1 Comment »

Speed comparison of various terminals

September 6th, 2007 by exhuma.twn

Terminal speed comparisonI never cared about which terminal to chose. I usually ended up with aterm on non-KDE boxes and Konsole on KDE boxes. This comparison (and the attached comments) is actually quite interesting.

The results were quite surprising ;)

Posted in Linux | No Comments »

Web Provider Fun

August 16th, 2007 by exhuma.twn

Oh yess… rants… I love to rant… and after my adventures of today and reading the last post, I have to dump my thoughts as well. And this one is about one of our web-providers in our oh-so technically advanced country. Or so they claim.
Read the rest of this entry »

Posted in Babble | No Comments »

VIM rc-file

August 10th, 2007 by exhuma.twn

Due to inane network restrictions I am maintaining several copies of my vimrc file. I would syncronize it though other means. Alas, the restrictions not only cover the network. So I have to resort to simply posting it here.

This is not meant to be an explanation of vim configuration file. However, it contains lots of comments, and might prove a good primer/starting-point. Eventually I will also include other modifications I made in my vim-home-folder as they are either used in the vimrc or just plain useful ;)

Read the rest of this entry »

Posted in Babble, Coding Voodoo | 2 Comments »

Ohloh Open Source Statistics

July 26th, 2007 by exhuma.twn

ohlo language statsOholoh is a site that keeps code statistics of open-source projetcs. It’s very interesting to browse though the different projects and look at their metrics.

It can also be a nice incentive to get people do commit on a regular basis, as it adds a sort of healthy competition to the development cycle.

Anyhow…. Great idea, and it already keeps track of quite a number of projects.

Posted in Coding Voodoo | No Comments »

Visual Basic Sucks!

July 19th, 2007 by exhuma.twn

That’s all I have to say!

Posted in Coding Voodoo | No Comments »

The LAB Color space

July 12th, 2007 by exhuma.twn

A few months ago, I decided to write a “quick” introduction to the LAB color space.
But instead of just writing the “hey! look, I can increase the luminosity of my image without losing color information”-type of post, I decided to get intimate with LAB and make the fuzzier concepts (the A and the B) a bit easier to understand using practical examples.

The reason why I still haven’t written more about LAB is simple. I got hooked! The more I read about LAB the more I am intrigues by the possibilities and the more I read about it. It’s a vicious circle.

I am now working on my 3rd attempt of the first example (yes, the usual-luminosity-suspect ;) ) and I am still not quite satisfied. My recent discovery is how stupidly easy one can fix a color-cast in an image with LAB. With this technique you can even get rid of light fog or haze.

However, creating, and annotating, the example images is very time-consuming. And until end of summer I am still very busy, so I will have to postpone my posts a few months :|

Stay tuned!

Posted in Photo Voodoo | No Comments »

« Previous Entries Next Entries »

Pages

Recent Posts

Categories

Links


Archives

Meta