Archiv der Kategorie: common

Kino – etwas angestaubt

Samstag war ich im Kino . Zur Auswahl standen „Ender’s Game“ (wohl eher nicht), „Only God Forgives“ (sagte mir nichts. Interessant: FSK 18 in USA/DE, R15+ in Japan) „Gravity“ (schon gesehen, absolut empfehlenswert, gewaltige Bilder, besonders in 3D) und: „The Dust Of Time„. Sagte mir auch nichts. Da aber Bruno Ganz, Willem Dafoe und Christiane Paul als Hauptdarsteller dieser europäischen Produktion mit dabei waren, hab ich mich dafür entschieden.

Originalton mit japanischem Untertitel. So weit, so gut, würde der Film nicht unter anderem in  Griechenland und Sibirien spielen – auch im Originalton und mit Untertitel. Japanischem Untertitel, versteht sich. Blöd auch, dass der Film der zweite Teil einer Trilogie war, wie ich später feststellte.

Also lag es doch gar nicht an meinen mangelnden Russisch- und Griechischkenntnissen, dass sich mir der Beginn des Films so überhaupt nicht erschloss.

Auch tragisch, dass der dritte Teil der Trilogie auf Grund des Ablebens seines Regisseurs  nie begonnen wurde.

Ach ja, und der Film ist von 2008 und hat entweder ein paar Jahre auf die Untertitelung gewartet, oder erlebt gerade in Japan seine Renaissance.

So wirklich begeistert war ich nicht, und war schon aufbruchbereit, als der Abspann anfing. Aber da hatte ich nicht mit den japanischen Cineasten gerechnet. Mucksmäuschenstill (abgesehen von mind. einem Schnarcher), noch immer im abgedunkelten Kinosaal, wurde sich der Abspann knochentrocken bis zur letzten Zeile („© 2008“) angeschaut.

Und dann gab es Applaus – allerdings tatsächlich nur den für diesen Film angemessenen – ich nehme an, dass Buhrufe der japanischen Höflichkeit fremd sind.

Über Zeitzonen hinweg

Inzwischen ist die erste Woche schon rum. Dank Skype lässt sich der Kontakt nach Hause wunderbar aufrecht erhalten. Nur gestaltet sich die Sache mit den 8 Stunden Zeitunterschied gar nicht so einfach:

xxxxxxxxsssssssssfffffffffffffsssssssssssfffffffffffffssssssssfwwwwwfwwwffffffssssssssfwwwwwfwwwffffffssssssssfwwwwwfwwwffffffssssssssfwwwwwfwwwffffffssssssssfwwwwwwfffffffffsssssssssssfffffffffffffsssssssssssfffffffffffffss
sssssssssffffffffffffffssssssssssfffffffffffffsssssssssffwwwfwwwwwffffsssssssssffwwwfwwwwwffffsssssssssffwwwfwwwwwffffsssssssssffwwwfwwwwwffffsssssssssffwwwfwwwwwfffffssssssssssffffffffffffffssssssssssfffffffffffffssxxxxxxxx
Freizeit
gleichzeitige Freizeit
Schlafen
Arbeiten

Creating KML Image Overlay from GeoTIFF or tfw file

As stated in my previous post my wife came around with a large map from work.

After compressing the image we wanted to visualize the map within Google Earth. I was quite surprised to see, that there is no small, common tool for that, so I sat down and wrote some (php) code, which I would like to share with you. (Be warned: all the scripts only work for UTM.)

This is, what we will have in the end:

    $image = "~/Desktop/geo-image-overlay.tif";
    $geoData = getGeoTIFF($image);
    $kml = geoTiffToKML($exifData, array("title" => "GeoTIFF", "imgFile" => "~/Desktop/geo-image-overlay.tif"));
    print $kml;

 

<!--?xml version="1.0" encoding="UTF-8"?-->


GeoTIFF

    ~/Desktop/geo-image-overlay.tif

    51.5724
    51.2639
    7.1835
    6.9287



The KML-code can be copied an pasted into Google Earth.

First of all, the geographic reference must be obtained either from the image’s EXIF-Data or from the separate WorldFile, which, by convention has the same name as the original image but it’s own extension (tfw for tif images, jpw for jpg).

The easy way: use GeoTIFF information and read it with exiftool by Phil Harvey.

define("EXIFTOOL_BIN", "/usr/bin/env exiftool");
function getGeoTIFF($file) {
    $data = array();
    $cmd = sprintf(EXIFTOOL_BIN." -GeoTIFF:* -EXIF:* -json '%s'", $file);
    exec($cmd, $data, $val);
    if ($val == 0) {
        $geo = json_decode(implode("\n", $data), true);
        return $geo[0];
    } else {
        return array();
    }
}

It’s a little strange, but part of the relevant „GeoTIFF“ information is stored in an images „EXIF“ data.

If you don’t use exiftool but if you have a WorldFile for your image, you might as well use zthe following function:

define("UTM_DEFAULT_ZONE", 32);

function tfw2GeoTIFF($file, $zone=UTM_DEFAULT_ZONE) {
    $tfwPath = substr($file, 0, strrpos($file, ".")).".tfw";
    $tifPath = substr($file, 0, strrpos($file, ".")).".tif";

    $tfw = file($tfwPath);
    list($w, $h) = getimagesize($tifPath, $info);

    $data = array();
    $data['SourceFile'] = $tifPath;
    $data['Projection'] = "UTM zone ".$zone;
    $data['ModelTiePoint'] = sprintf("%f %f 0 %f %f 0", $tfw[1], $tfw[2], $tfw[4] + (0), $tfw[5]);
    $data['PixelScale'] = sprintf("%f %f 0", $tfw[0], $tfw[3]);
    $data['ImageHeight'] = $h;
    $data['ImageWidth'] = $w;

    return $data;
}

The main problem is, that the WorldFile doesn’t contain any information about the reference system and units used within the file – you just have to know it. Who on earth defines such a „format“?
I just assumed to get UTM geo information and you have to assume the right zone.
For convenience the function uses the same attribute names as the GeoTIFF spec.

As said, I just assumed UTM data. As KML files have to contain coordinates as WGS84 I searched for a conversion script which I found on stack overflow.
Here is the PHP adaption:

function utm2wgs84($utmZone,$east,$north) {
  // This is the lambda knot value in the reference
  $LngOrigin = deg2rad($utmZone * 6 - 183);

  // The following set of class constants define characteristics of the
  // ellipsoid, as defined my the WGS84 datum.  These values need to be
  // changed if a different dataum is used.

  $FalseNorth = 0.;   // South or North?
  //if (lat < 0.) FalseNorth = 10000000.  // South or North?   //else          FalseNorth = 0.   $Ecc = 0.081819190842622;       // Eccentricity   $EccSq = $Ecc * $Ecc;   $Ecc2Sq = $EccSq / (1. - $EccSq);   $Ecc2 = sqrt($Ecc2Sq);      // Secondary eccentricity   $E1 = ( 1 - sqrt(1-$EccSq) ) / ( 1 + sqrt(1-$EccSq) );   $E12 = $E1 * $E1;   $E13 = $E12 * $E1;   $E14 = $E13 * $E1;   $SemiMajor = 6378137.0;         // Ellipsoidal semi-major axis (Meters)   $FalseEast = 500000.0;          // UTM East bias (Meters)   $ScaleFactor = 0.9996;          // Scale at natural origin   // Calculate the Cassini projection parameters   $M1 = ($north - $FalseNorth) / $ScaleFactor;   $Mu1 = $M1 / ( $SemiMajor * (1 - $EccSq/4.0 - 3.0*$EccSq*$EccSq/64.0 -     5.0*$EccSq*$EccSq*$EccSq/256.0) );   $Phi1 = $Mu1 + (3.0*$E1/2.0 - 27.0*$E13/32.0) * sin(2.0*$Mu1)     + (21.0*$E12/16.0 - 55.0*$E14/32.0)           * sin(4.0*$Mu1)     + (151.0*$E13/96.0)                          * sin(6.0*$Mu1)     + (1097.0*$E14/512.0)                        * sin(8.0*$Mu1);   $sin2phi1 = sin($Phi1) * sin($Phi1);   $Rho1 = ($SemiMajor * (1.0-$EccSq) ) / pow(1.0-$EccSq*$sin2phi1,1.5);   $Nu1 = $SemiMajor / sqrt(1.0-$EccSq*$sin2phi1);   // Compute parameters as defined in the POSC specification.  T, C and D   $T1 = tan($Phi1) * tan($Phi1);   $T12 = $T1 * $T1;   $C1 = $Ecc2Sq * cos($Phi1) * cos($Phi1);   $C12 = $C1 * $C1;   $D  = ($east - $FalseEast) / ($ScaleFactor * $Nu1);   $D2 = $D *  $D;   $D3 = $D2 * $D;   $D4 = $D3 * $D;   $D5 = $D4 * $D;   $D6 = $D5 * $D;   // Compute the Latitude and Longitude and convert to degrees   $lat = $Phi1 - $Nu1*tan($Phi1)/$Rho1 *     ( $D2/2.0 - (5.0 + 3.0*$T1 + 10.0*$C1 - 4.0*$C12 - 9.0*$Ecc2Sq)*$D4/24.0      + (61.0 + 90.0*$T1 + 298.257223563*$C1 + 45.0*$T12 - 252.0*$Ecc2Sq - 3.0*$C12)*$D6/720.0 );   $lat = rad2deg($lat);   $lon = $LngOrigin +     ( $D - (1.0 + 2.0*$T1 + $C1)*$D3/6.0       + (5.0 - 2.0*$C1 + 28.0*$T1 - 3.0*$C12 + 8.0*$Ecc2Sq + 24.0*$T12)*$D5/120.0) / cos($Phi1);   $lon = rad2deg($lon);   // Returns a PC_LatLon object   return array("lat" => $lat, "lon" => $lon);
}

And finally here comes the main function to produce the KML.
(Sorry for the lame tempting mechanism…)

define("KML_TEMPLATE", '<!--?xml version="1.0" encoding="UTF-8"?-->


%s

    %s

    %f
    %f
    %f
    %f


');

function geoTiffToKML($geoTiff, $options = array()) {
    $scale = isset($options['imgScale'])?1/$options['imgScale']:1;
    $file = isset($options['imgFile'])?$options['imgFile']:$geoTiff['SourceFile'];
    $title = isset($options['title'])?$options['title']:"No Name";

    // calculate n, s, w, e

    // projection analysis
    if (substr($geoTiff['Projection'], 0, 8) == "UTM zone") {
        $zone = intval(substr($geoTiff['Projection'], 8));

        list($rot1, $rot2, $u1, $eUTM, $nUTM, $u2) = explode(" ", trim($geoTiff['ModelTiePoint']));
        list($scaleNS, $scaleWE, $u) = explode(" ", trim($geoTiff['PixelScale']));

        $iw = $geoTiff['ImageWidth'];
        $ih = $geoTiff['ImageHeight'];

        $wUTM = abs($scale * $scaleWE * $iw) + $eUTM;
        $sUTM = $nUTM - abs($scale * $scaleNS * $ih);

        $ne = utm2wgs84($zone,$eUTM,$nUTM);
        $n = $ne['lat'];
        $e = $ne['lon'];
        $sw = utm2wgs84($zone,$wUTM,$sUTM);
        $s = $sw['lat'];
        $w = $sw['lon'];

        return sprintf(KML_TEMPLATE, $title, $file, max($n, $s), min($n, $s), max($e, $w), min($e, $w));

    } else {
        die('No support for other projections than UTM');
    }
}

Converting/scaling large TIFF images from a GIS

My wife works as in a land surveying office. This weekend she brought a compressed TIFF image, which was a rasterized version of a cities GIS data.

In compression mode, the file took about 90MB space, but as the image is 56706 px by 47255 px in 8Bit greyscale, it holds a little less than 2.5 GB of information.

There was no chance opening it in Photoshop, nor was ImageMagick able to create a scaled version.

Finally vips (VIPS – VipsWiki) did the job:

vips im_affinei_all input.tif output.tif vsqbs 0.4 0 0 0.4 0 0

Vips offers different interpolators: nearest, bilinear, bicubic, lbb, nohalo, vsqbs; the latest worked best for our original material.

jQuery.printQr: use QR-Codes for your Print-Stylesheet with Google Charts API and jQuery

It’s a common practice to make the URIs of links visible in a print styleheets via CSS:

@media print {
a:after {
content: " (" attr(href) ")";
}
}

Quite often you would not like to type a cryptic url by hand. Here is what you may utilize jQuery.printQr for.

Here is all you have to do:

<script src="jquery.printqr.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
    $('a').printQr();
});
</script>

These lines of code will add QR Codes for all links to the bottom of the page when you print it.
I built a little demo page.

Have fun with it, I’m interested in some feedback.

Magic Earth: Unsere Welt in 3D

Seit ein paar Tagen ist das Buch „Magic Earth: Unsere Welt in 3D“ im Handel erhältlich, in dem auch eine meiner Peru-3D-Aufnahmen abgedruckt ist. Mein Beleg-Exemplar ist auch bei mir angekommen.

Ein wenig schade ist, dass die Bilder über die Doppelseite und damit über den Falz gehen.

Dafür gibt es schöne Fotos und Relief-Karten in 3D rund um den Globus.

Image Galleries from DropBox

My previous post gave a little sneak peek to my very first wordpress plugin „Dropbox Gallery“.
Although it is not ready for press right now, I’ll tell you about its features and advantages.

No (manual) upload needed
All you do is drag a file to your Dropbox folder. You should upload an image with a reasonable filesize, so don’t use your 20 megapixel raw image. Thumbnailing is done by dropbox.

Caching, not copying
The images from your Dropbox are cached for faster access. The cache has a configurable lifetime.

Update galleries or individual pictures
On the other hand every new revision of an image is detected and updated. You altered your image in Photoshop? No need to update your image in WordPress.

Choose any folder from your Dropbox account
You may choose any folder to create an image gallery out of its contents. All images of the folder you chose are displayed in your article.

And here is what you get
[dbgallery path=/Photos/Blog/Gallery-Demo]