Um “mal eben” eine Auswahl an geo-referenzierten Photos aus dem Dateimanager Nautilus auf einer Karte in Google Maps/Earth anzeigen zu lassen, habe ich mir 2 kleine Bash-Skripte für Nautilus-Scripts geschrieben, die mir dabei behilflich sind.
Nun selektiere ich einfach ein paar Photos, mache einen Rechtsklick und wähle “Skripte > Open in Google Maps” aus.
Im Hintergrund werden jetzt die EXIF-Header der ausgewählten Photos mit Hilfe von exiftool auf Koordinaten untersucht. Es wird dann eine temporäre HTML-Seite in Firefox geöffnet, die eine Google Maps-Karte mit allen Photos enthält.
Alternativ können die Photos auch in Google Earth angezeigt werden. Hierfür wird dann eine temporäre KML-Datei erstellt.
Und so lassen sich die Skripte einrichten:
Kopiere nachfolgenden Quelltext in einen Texteditor und speichere die Datei unter “/home/{User}/.gnome2/nautilus-scripts/Open in GoogleMaps” (ohne Dateiendung).
# Get the calling dir CURRENTDIR=$(echo ${NAUTILUS_SCRIPT_CURRENT_URI}) # Path to the temporary KML file KMLFILE="/tmp/$$.html" #Write KML - Header echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" >> $KMLFILE echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">" >> $KMLFILE echo "<head>" >> $KMLFILE echo "<title>Open in GoogleMaps</title>" >> $KMLFILE echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" >> $KMLFILE echo "" >> $KMLFILE echo "<script src=\"http://maps.google.com/maps?file=api&v=2&\" type=\"text/javascript\">" >> $KMLFILE echo "</script>" >> $KMLFILE echo "<style type=\"text/css\">" >> $KMLFILE echo " html, body, #map {" >> $KMLFILE echo " width: 100%;" >> $KMLFILE echo " height: 100%;" >> $KMLFILE echo " }" >> $KMLFILE echo "" >> $KMLFILE echo " body {" >> $KMLFILE echo " margin-top: 0px;" >> $KMLFILE echo " margin-right: 0px;" >> $KMLFILE echo " margin-left: 0px;" >> $KMLFILE echo " margin-bottom: 0px;" >> $KMLFILE echo " }" >> $KMLFILE echo "</style>" >> $KMLFILE echo "</head>" >> $KMLFILE echo "" >> $KMLFILE echo "<body>" >> $KMLFILE echo " <div id=\"map\"></div> " >> $KMLFILE echo " <div id=\"footer\">" >> $KMLFILE echo "" >> $KMLFILE echo "<script type=\"text/javascript\">" >> $KMLFILE echo "//<![CDATA[" >> $KMLFILE echo "var map;" >> $KMLFILE echo "var markerOptions;" >> $KMLFILE echo "var bounds;" >> $KMLFILE echo "" >> $KMLFILE echo "function addPoint(name, fileName, lat, lng) {" >> $KMLFILE echo " var latlng = new GLatLng(lat, lng);" >> $KMLFILE echo " var marker = new GMarker(latlng, markerOptions);" >> $KMLFILE echo " marker.value = 1;" >> $KMLFILE echo " GEvent.addListener(marker,\"click\", function() {" >> $KMLFILE echo " var myHtml = \"<b>\" + name + \"</b> <img src=\\\"\" + fileName + \"\\\" width=\\\"200\\\" />\";" >> $KMLFILE echo " map.openInfoWindowHtml(latlng, myHtml);});" >> $KMLFILE echo " map.addOverlay(marker);" >> $KMLFILE echo " bounds.extend(latlng);" >> $KMLFILE echo "}" >> $KMLFILE echo "" >> $KMLFILE echo "if (GBrowserIsCompatible()) {" >> $KMLFILE echo " map = new GMap2(document.getElementById(\"map\"));" >> $KMLFILE echo " map.setCenter(new GLatLng(0,0));" >> $KMLFILE echo " var mgr = new GMarkerManager(map);" >> $KMLFILE echo " map.setMapType(G_SATELLITE_MAP);" >> $KMLFILE echo " map.enableScrollWheelZoom();" >> $KMLFILE echo " map.addControl(new GLargeMapControl());" >> $KMLFILE echo " map.addControl(new GMapTypeControl());" >> $KMLFILE echo " map.addControl(new GScaleControl());" >> $KMLFILE echo " map.addControl(new GOverviewMapControl());" >> $KMLFILE echo "" >> $KMLFILE echo " var photoIcon = new GIcon(G_DEFAULT_ICON);" >> $KMLFILE echo " photoIcon.image = \"http://maps.google.com/mapfiles/kml/pal4/icon46.png\";" >> $KMLFILE echo " photoIcon.iconSize = new GSize(30, 30);" >> $KMLFILE echo " markerOptions = { icon:photoIcon };" >> $KMLFILE echo " bounds = new GLatLngBounds();" >> $KMLFILE PHOTOSADDED=1 #Loop selected files while [ $# -gt 0 ]; do fileName=$1 # Try to get GPS coordinates of this file KOORD=$(exiftool -n -f -p '$GPSLatitude,$GPSLongitude' "${fileName}") #If the coordinates are invalid, they do look like this: "-,-" PRUEF=$(expr index "$KOORD" "-") if [ $PRUEF = 0 ] then #This is a valid photo, so add to KML PHOTOSADDED=0 echo " addPoint(\"${fileName}\", \"`pwd`/${fileName}\", ${KOORD});" >> $KMLFILE fi shift done #Write KML - Footer echo " map.setZoom(map.getBoundsZoomLevel(bounds));" >> $KMLFILE echo " map.setCenter(bounds.getCenter());" >> $KMLFILE echo " }" >> $KMLFILE echo "//]]>" >> $KMLFILE echo "</script>" >> $KMLFILE echo "</div> " >> $KMLFILE echo "</body>" >> $KMLFILE echo "</html>" >> $KMLFILE if [ $PHOTOSADDED = 0 ] then firefox "${KMLFILE}" else zenity --error --text "Not one photo containing coordinates. Could not create KML file!" fi
Und das Skript für Google Earth kann unter dieser Datei gespeichert werden:
“/home/{User}/.gnome2/nautilus-scripts/Open in GoogleEarth” (auch ohne Dateiendung)
# Get the calling dir CURRENTDIR=$(echo ${NAUTILUS_SCRIPT_CURRENT_URI}) # Path to the temporary KML file KMLFILE="/tmp/$$.kml" #Write KML - Header echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >> $KMLFILE echo "<kml xmlns=\"http://earth.google.com/kml/2.1\">" >> $KMLFILE echo "<Document>" >> $KMLFILE echo " <name>KmlFile</name>" >> $KMLFILE echo " <Style id=\"Photo\">" >> $KMLFILE echo " <IconStyle>" >> $KMLFILE echo " <Icon>" >> $KMLFILE echo " <href>http://maps.google.com/mapfiles/kml/pal4/icon46.png</href>" >> $KMLFILE echo " </Icon>" >> $KMLFILE echo " </IconStyle>" >> $KMLFILE echo " </Style>" >> $KMLFILE PHOTOSADDED=1 #Loop selected files while [ $# -gt 0 ]; do fileName=$1 # Try to get GPS coordinates of this file KOORD=$(exiftool -n -f -p '$GPSLongitude,$GPSLatitude' "${fileName}") #If the coordinates are invalid, they do look like this: "-,-" PRUEF=$(expr index "$KOORD" "-") if [ $PRUEF = 0 ] then #This is a valid photo, so add to KML PHOTOSADDED=0 echo "<Placemark>" >> $KMLFILE echo " <name>${fileName}</name>" >> $KMLFILE echo " <description><![CDATA[<img src=\"`pwd`/${fileName}\" width=\"200\"/>]]></description>" >> $KMLFILE echo " <styleUrl>#Photo</styleUrl>" >> $KMLFILE echo " <Point>" >> $KMLFILE echo " <coordinates>${KOORD}</coordinates>" >> $KMLFILE echo " </Point>" >> $KMLFILE echo "</Placemark>" >> $KMLFILE fi shift done #Write KML - Footer echo "</Document>" >> $KMLFILE echo "</kml>" >> $KMLFILE if [ $PHOTOSADDED = 0 ] then googleearth "${KMLFILE}" else zenity --error --text "Not one photo containing coordinates. Could not create KML file!" fi
Nach einem Neustart von Nautilus werden diese zwei Skripte jetzt im Rechtsklick-Menü aufgeführt.
Zur Ausführung werden folgende Pakete/Programme benötigt:
- libimage-exiftool-perl
- zenity
- Firefox
- Google Earth
Die Skripte dürfen frei verwendet und weiter entwickelt werden.
Martin Vogel said
Danke für diese beiden Skripte – genau danach habe ich gesucht! Das Google-Maps-Skript zeigt bei mir zwar nur einen leeren Bildschirm, auch wenn ich meinen API-Key ergänze, das Google-Earth-Skript jedoch läuft tadellos.