[tracker] Add extraction of GPS coordinates



commit 9270cc6d612d9633f3f857821c67c54a88b46aa9
Author: Mikael Ottela <mikael ottela ixonos com>
Date:   Tue Jun 7 09:08:51 2011 +0300

    Add extraction of GPS coordinates

 src/libtracker-extract/tracker-exif.c      |   75 +++++++++++++++++
 src/libtracker-extract/tracker-exif.h      |    3 +
 src/libtracker-extract/tracker-xmp.c       |  120 ++++++++++++++++++++++------
 src/libtracker-extract/tracker-xmp.h       |    5 +
 src/tracker-extract/tracker-extract-gif.c  |   79 +++++++++++-------
 src/tracker-extract/tracker-extract-jpeg.c |   79 ++++++++++++------
 src/tracker-extract/tracker-extract-pdf.c  |   97 +++++++++++++---------
 src/tracker-extract/tracker-extract-png.c  |   84 ++++++++++++--------
 src/tracker-extract/tracker-extract-tiff.c |   79 ++++++++++++------
 9 files changed, 438 insertions(+), 183 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-exif.c b/src/libtracker-extract/tracker-exif.c
index a0c7674..444e464 100644
--- a/src/libtracker-extract/tracker-exif.c
+++ b/src/libtracker-extract/tracker-exif.c
@@ -278,6 +278,71 @@ get_white_balance (ExifData *exif,
 	return NULL;
 }
 
+static gchar *
+get_gps_coordinate (ExifData *exif,
+		    ExifTag   tag,
+		    ExifTag   reftag)
+{
+	ExifEntry *entry = exif_data_get_entry (exif, tag);
+	ExifEntry *refentry = exif_data_get_entry (exif, reftag);
+
+	if (entry && refentry) {
+		ExifByteOrder order;
+		ExifRational c1,c2,c3;
+		gfloat f;
+		gchar ref;
+
+		order = exif_data_get_byte_order (exif);
+		c1 = exif_get_rational (entry->data, order);
+		c2 = exif_get_rational (entry->data+8, order);
+		c3 = exif_get_rational (entry->data+16, order);
+		ref = exif_get_short (refentry->data, order);
+		
+		f = (double)c1.numerator/c1.denominator+
+		  (double)c2.numerator/(c2.denominator*60)+
+		  (double)c3.numerator/(c3.denominator*60*60);
+
+		if (ref == 'S' || ref == 'W') {
+		      f = -1 * f;
+		}
+		return g_strdup_printf ("%f", f);
+	}
+
+	return NULL;
+}
+
+static gchar *
+get_gps_altitude (ExifData *exif,
+		  ExifTag   tag,
+		  ExifTag   reftag)
+{
+	ExifEntry *entry = exif_data_get_entry (exif, tag);
+	ExifEntry *refentry = exif_data_get_entry (exif, reftag);
+
+	if (entry) {
+		ExifByteOrder order;
+		ExifRational c;
+		gfloat f;
+		gboolean ref;
+
+		order = exif_data_get_byte_order (exif);
+		c = exif_get_rational (entry->data, order);
+		f = (double)c.numerator/c.denominator;
+
+		/* Strictly speaking it is invalid not to have this
+		   but.. let's try to cope here */
+		if (refentry) {
+		        ref = exif_get_short (refentry->data, order);
+		
+			if (ref == 1) {
+			        f = -1 * f;
+			}
+		}
+		return g_strdup_printf ("%f", f);
+	}
+
+	return NULL;
+}
 
 static gint
 get_int (ExifData *exif,
@@ -401,6 +466,13 @@ parse_exif (const unsigned char *buffer,
 	if (!data->y_resolution)
 		data->y_resolution = get_value (exif, EXIF_TAG_Y_RESOLUTION);
 
+	if(!data->gps_altitude)
+	        data->gps_altitude = get_gps_altitude (exif, EXIF_TAG_GPS_ALTITUDE, EXIF_TAG_GPS_ALTITUDE_REF);
+	if(!data->gps_latitude)
+       	        data->gps_latitude = get_gps_coordinate (exif, EXIF_TAG_GPS_LATITUDE, EXIF_TAG_GPS_LATITUDE_REF);
+	if(!data->gps_longitude)
+	        data->gps_longitude = get_gps_coordinate (exif, EXIF_TAG_GPS_LONGITUDE, EXIF_TAG_GPS_LONGITUDE_REF);
+
 	exif_data_free (exif);
 #endif /* HAVE_LIBEXIF */
 
@@ -515,6 +587,9 @@ tracker_exif_free (TrackerExifData *data)
 	g_free (data->software);
 	g_free (data->x_resolution);
 	g_free (data->y_resolution);
+	g_free (data->gps_altitude);
+	g_free (data->gps_latitude);
+	g_free (data->gps_longitude);
 
 	g_free (data);
 }
diff --git a/src/libtracker-extract/tracker-exif.h b/src/libtracker-extract/tracker-exif.h
index 96bdd23..219caa6 100644
--- a/src/libtracker-extract/tracker-exif.h
+++ b/src/libtracker-extract/tracker-exif.h
@@ -52,6 +52,9 @@ typedef struct {
 	gchar *software;
 	gchar *x_resolution;
 	gchar *y_resolution;
+        gchar *gps_altitude;
+        gchar *gps_latitude;
+        gchar *gps_longitude;
 	gint resolution_unit;
 } TrackerExifData;
 
diff --git a/src/libtracker-extract/tracker-xmp.c b/src/libtracker-extract/tracker-xmp.c
index 21ec190..3d0e52b 100644
--- a/src/libtracker-extract/tracker-xmp.c
+++ b/src/libtracker-extract/tracker-xmp.c
@@ -117,6 +117,43 @@ fix_white_balance (const gchar *wb)
 	}
 }
 
+static gchar *
+gps_coordinate_dup (const gchar *coordinates)
+{
+  static GRegex *reg = NULL;
+  GMatchInfo *info = NULL;
+
+  if (!reg) {
+    reg = g_regex_new ("([0-9]+),([0-9]+.[0-9]+)([A-Z])", 0, 0, NULL);
+  }
+
+  if (g_regex_match (reg, coordinates, 0, &info)) {
+    gchar *deg,*min,*ref;
+    gdouble r,d,m;
+
+    deg = g_match_info_fetch (info, 1);
+    min = g_match_info_fetch (info, 2);
+    ref = g_match_info_fetch (info, 3);
+
+    d = atof (deg);
+    m = atof (min);
+    
+    r = d + m/60;
+
+    if ( (ref[0] == 'S') || (ref[0] == 'W')) {
+      r = r * -1;
+    }
+
+    g_free (deg);
+    g_free (min);
+    g_free (ref);
+
+    return g_strdup_printf ("%f", r);
+  } else {
+    return NULL;
+  }
+}
+
 /* We have an array, now recursively iterate over it's children.  Set
  * 'append' to true so that all values of the array are added under
  * one entry.
@@ -249,7 +286,7 @@ fix_orientation (const gchar *orientation)
 	if (orientation && g_ascii_strcasecmp (orientation, "top - left") == 0) {
 		return "nfo:orientation-top";
 	} else if (orientation && g_ascii_strcasecmp (orientation, "top - right") == 0) {
-			return  "nfo:orientation-top-mirror";
+		return  "nfo:orientation-top-mirror";
 	} else if (orientation && g_ascii_strcasecmp (orientation, "bottom - right") == 0) {
 		return "nfo:orientation-bottom-mirror";
 	} else if (orientation && g_ascii_strcasecmp (orientation, "bottom - left") == 0) {
@@ -324,6 +361,14 @@ iterate_simple (const gchar    *uri,
 			data->white_balance = g_strdup (fix_white_balance (value));
 		} else if (!data->copyright && g_ascii_strcasecmp (name, "Copyright") == 0) {
 			data->copyright = g_strdup (value);
+		} else if (!data->gps_altitude && g_ascii_strcasecmp (name, "GPSAltitude") == 0) {
+		        data->gps_altitude = div_str_dup (value);
+		} else if (!data->gps_altitude_ref && g_ascii_strcasecmp (name, "GPSAltitudeRef") == 0) {
+		        data->gps_altitude_ref = g_strdup (value);
+	        } else if (!data->gps_latitude && g_ascii_strcasecmp (name, "GPSLatitude") == 0) {
+		        data->gps_latitude = gps_coordinate_dup (value);
+	        } else if (!data->gps_longitude && g_ascii_strcasecmp (name, "GPSLongitude") == 0) {
+		        data->gps_longitude = gps_coordinate_dup (value);
 		}
 		/* PDF*/
 	} else if (g_ascii_strcasecmp (schema, NS_PDF) == 0) {
@@ -637,6 +682,10 @@ tracker_xmp_free (TrackerXmpData *data)
 	g_free (data->country);
 	g_free (data->state);
 	g_free (data->city);
+	g_free (data->gps_altitude);
+	g_free (data->gps_altitude_ref);
+	g_free (data->gps_latitude);
+	g_free (data->gps_longitude);
 
 	g_free (data);
 }
@@ -885,8 +934,8 @@ tracker_xmp_apply (TrackerSparqlBuilder *preupdate,
 		tracker_sparql_builder_object_blank_close (metadata);
 	}
 
-	if (data->address || data->country || data->city) {
-		gchar *addruri;
+	if (data->address || data->state || data->country || data->city ||
+	    data->gps_altitude || data->gps_latitude || data->gps_longitude) {
 
 		tracker_sparql_builder_predicate (metadata, "slo:location");
 
@@ -894,43 +943,62 @@ tracker_xmp_apply (TrackerSparqlBuilder *preupdate,
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "slo:GeoLocation");
 
-		addruri = tracker_sparql_get_uuid_urn ();
+		if (data->address || data->state || data->country || data->city) {
+	                gchar *addruri;
 
-		tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
-		tracker_sparql_builder_object_iri (metadata, addruri);
+		        addruri = tracker_sparql_get_uuid_urn ();
 
-		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
+		        tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
+	                tracker_sparql_builder_object_iri (metadata, addruri);
 
-		tracker_sparql_builder_insert_open (preupdate, NULL);
-		tracker_sparql_builder_subject_iri (preupdate, addruri);
+		        tracker_sparql_builder_insert_open (preupdate, NULL);
+		        tracker_sparql_builder_subject_iri (preupdate, addruri);
 
-		g_free (addruri);
+		        g_free (addruri);
 
-		tracker_sparql_builder_predicate (preupdate, "a");
-		tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+		        tracker_sparql_builder_predicate (preupdate, "a");
+		        tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
 
-		if (data->address) {
-			tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
-			tracker_sparql_builder_object_unvalidated (preupdate, data->address);
-		}
+			if (data->address) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
+			        tracker_sparql_builder_object_unvalidated (preupdate, data->address);
+			}
 
-		if (data->state) {
-			tracker_sparql_builder_predicate (preupdate, "nco:region");
-			tracker_sparql_builder_object_unvalidated (preupdate, data->state);
+			if (data->state) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:region");
+				tracker_sparql_builder_object_unvalidated (preupdate, data->state);
+			}
+
+			if (data->city) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:locality");
+				tracker_sparql_builder_object_unvalidated (preupdate, data->city);
+			}
+
+			if (data->country) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:country");
+				tracker_sparql_builder_object_unvalidated (preupdate, data->country);
+			}
+
+			tracker_sparql_builder_insert_close (preupdate);
 		}
 
-		if (data->city) {
-			tracker_sparql_builder_predicate (preupdate, "nco:locality");
-			tracker_sparql_builder_object_unvalidated (preupdate, data->city);
+		if (data->gps_altitude) {
+		        /* FIXME We are not handling the altitude ref here */
+		        tracker_sparql_builder_predicate (metadata, "slo:altitude");
+		        tracker_sparql_builder_object_unvalidated (metadata, data->gps_altitude);
 		}
 
-		if (data->country) {
-			tracker_sparql_builder_predicate (preupdate, "nco:country");
-			tracker_sparql_builder_object_unvalidated (preupdate, data->country);
+		if (data->gps_latitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:latitude");
+			tracker_sparql_builder_object_unvalidated (metadata, data->gps_latitude);
 		}
 
-		tracker_sparql_builder_insert_close (preupdate);
+		if (data->gps_longitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:longitude");
+			tracker_sparql_builder_object_unvalidated (metadata, data->gps_longitude);
+		}
 
+		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
 	}
 
 	return TRUE;
diff --git a/src/libtracker-extract/tracker-xmp.h b/src/libtracker-extract/tracker-xmp.h
index e0d0085..91fdc51 100644
--- a/src/libtracker-extract/tracker-xmp.h
+++ b/src/libtracker-extract/tracker-xmp.h
@@ -73,6 +73,11 @@ typedef struct {
 	gchar *white_balance;
 	gchar *copyright;
 
+        gchar *gps_altitude;
+        gchar *gps_altitude_ref;
+        gchar *gps_latitude;
+        gchar *gps_longitude;
+
 	/* TODO NS_XAP*/
 	gchar *rating;
 
diff --git a/src/tracker-extract/tracker-extract-gif.c b/src/tracker-extract/tracker-extract-gif.c
index fb113d3..0e6ca98 100644
--- a/src/tracker-extract/tracker-extract-gif.c
+++ b/src/tracker-extract/tracker-extract-gif.c
@@ -422,8 +422,8 @@ read_metadata (TrackerSparqlBuilder *preupdate,
 		tracker_sparql_builder_object_unvalidated (metadata, xd->coverage);
 	}
 
-	if (xd->address || xd->country || xd->city) {
-		gchar *addruri;
+	if (xd->address || xd->state || xd->country || xd->city ||
+	    xd->gps_altitude || xd->gps_latitude || xd-> gps_longitude) {
 
 		tracker_sparql_builder_predicate (metadata, "slo:location");
 
@@ -431,43 +431,60 @@ read_metadata (TrackerSparqlBuilder *preupdate,
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "slo:GeoLocation");
 
-		addruri = tracker_sparql_get_uuid_urn ();
-
-		tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
-		tracker_sparql_builder_object_iri (metadata, addruri);
-
-		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
-
-		tracker_sparql_builder_insert_open (preupdate, NULL);
-		tracker_sparql_builder_subject_iri (preupdate, addruri);
-
-		g_free (addruri);
-
-		tracker_sparql_builder_predicate (preupdate, "a");
-		tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+		if (xd->address || xd->state || xd->country || xd->city)  {
+		        gchar *addruri;
+			addruri = tracker_sparql_get_uuid_urn ();
+			
+			tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
+			tracker_sparql_builder_object_iri (metadata, addruri);			
+			
+			tracker_sparql_builder_insert_open (preupdate, NULL);
+			tracker_sparql_builder_subject_iri (preupdate, addruri);
+			
+			g_free (addruri);
+			
+			tracker_sparql_builder_predicate (preupdate, "a");
+			tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+			
+			if (xd->address) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->address);
+			}
+			
+			if (xd->state) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:region");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->state);
+			}
+			
+			if (xd->city) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:locality");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->city);
+			}
+			
+			if (xd->country) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:country");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->country);
+			}
 
-		if (xd->address) {
-			tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->address);
+			tracker_sparql_builder_insert_close (preupdate);
 		}
-
-		if (xd->state) {
-			tracker_sparql_builder_predicate (preupdate, "nco:region");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->state);
+		
+		if (xd->gps_altitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:altitude");
+			tracker_sparql_builder_object_unvalidated (metadata, xd->gps_altitude);
 		}
 
-		if (xd->city) {
-			tracker_sparql_builder_predicate (preupdate, "nco:locality");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->city);
+		if (xd->gps_latitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:latitude");
+			tracker_sparql_builder_object_unvalidated (metadata, xd->gps_latitude);
 		}
 
-		if (xd->country) {
-			tracker_sparql_builder_predicate (preupdate, "nco:country");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->country);
+		if (xd->gps_longitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:longitude");
+			tracker_sparql_builder_object_unvalidated (metadata, xd->gps_longitude);
 		}
 
-		tracker_sparql_builder_insert_close (preupdate);
-
+		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
 	}
 
 	if (gd.width) {
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index b54f511..a1113de 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -74,7 +74,10 @@ typedef struct {
 	const gchar *city;
 	const gchar *state;
 	const gchar *address;
-	const gchar *country; 
+	const gchar *country;
+        const gchar *gps_altitude;
+        const gchar *gps_latitude;
+        const gchar *gps_longitude;
 } MergeData;
 
 struct tej_error_mgr {
@@ -246,6 +249,10 @@ tracker_extract_get_metadata (const gchar          *uri,
 	md.state = tracker_coalesce_strip (2, xd->state, id->state);
 	md.address = tracker_coalesce_strip (2, xd->address, id->sublocation);
 	md.country = tracker_coalesce_strip (2, xd->country, id->country_name);
+        /* FIXME We are not handling the altitude ref here for xmp */
+	md.gps_altitude = tracker_coalesce_strip (2, xd->gps_altitude, ed->gps_altitude);
+	md.gps_latitude = tracker_coalesce_strip (2, xd->gps_latitude, ed->gps_latitude);
+	md.gps_longitude = tracker_coalesce_strip (2, xd->gps_longitude, ed->gps_longitude);
 	md.creator = tracker_coalesce_strip (3, xd->creator, id->byline, id->credit);
 	md.comment = tracker_coalesce_strip (2, comment, ed->user_comment);
 	md.make = tracker_coalesce_strip (2, xd->make, ed->make);
@@ -543,52 +550,70 @@ tracker_extract_get_metadata (const gchar          *uri,
 		tracker_sparql_builder_object_unvalidated (metadata, md.comment);
 	}
 
-	if (md.city || md.state || md.address || md.country) {
-		gchar *addruri;
+	if (md.address || md.state || md.country || md.city ||
+	    md.gps_altitude || md.gps_latitude || md.gps_longitude) {
 
 		tracker_sparql_builder_predicate (metadata, "slo:location");
 
-		tracker_sparql_builder_object_blank_open (metadata); /* GeoLocation */
+		tracker_sparql_builder_object_blank_open (metadata); /* GeoPoint */
 		tracker_sparql_builder_predicate (metadata, "a");
 		tracker_sparql_builder_object (metadata, "slo:GeoLocation");
 
-		addruri = tracker_sparql_get_uuid_urn ();
+		if (md.address || md.state || md.country || md.city) {
+	                gchar *addruri;
 
-		tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
-		tracker_sparql_builder_object_iri (metadata, addruri);
+		        addruri = tracker_sparql_get_uuid_urn ();
 
-		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
+		        tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
+	                tracker_sparql_builder_object_iri (metadata, addruri);
 
-		tracker_sparql_builder_insert_open (preupdate, NULL);
-		tracker_sparql_builder_subject_iri (preupdate, addruri);
+		        tracker_sparql_builder_insert_open (preupdate, NULL);
+		        tracker_sparql_builder_subject_iri (preupdate, addruri);
 
-		g_free (addruri);
+		        g_free (addruri);
 
-		tracker_sparql_builder_predicate (preupdate, "a");
-		tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+		        tracker_sparql_builder_predicate (preupdate, "a");
+		        tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
 
-		if (md.address) {
-			tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.address);
-		}
+			if (md.address) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
+			        tracker_sparql_builder_object_unvalidated (preupdate, md.address);
+			}
+
+			if (md.state) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:region");
+				tracker_sparql_builder_object_unvalidated (preupdate, md.state);
+			}
 
-		if (md.state) {
-			tracker_sparql_builder_predicate (preupdate, "nco:region");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.state);
+			if (md.city) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:locality");
+				tracker_sparql_builder_object_unvalidated (preupdate, md.city);
+			}
+
+			if (md.country) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:country");
+				tracker_sparql_builder_object_unvalidated (preupdate, md.country);
+			}
+
+			tracker_sparql_builder_insert_close (preupdate);
 		}
 
-		if (md.city) {
-			tracker_sparql_builder_predicate (preupdate, "nco:locality");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.city);
+		if (md.gps_altitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:altitude");
+			tracker_sparql_builder_object_unvalidated (metadata, md.gps_altitude);
 		}
 
-		if (md.country) {
-			tracker_sparql_builder_predicate (preupdate, "nco:country");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.country);
+		if (md.gps_latitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:latitude");
+			tracker_sparql_builder_object_unvalidated (metadata, md.gps_latitude);
 		}
 
-		tracker_sparql_builder_insert_close (preupdate);
+		if (md.gps_longitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:longitude");
+			tracker_sparql_builder_object_unvalidated (metadata, md.gps_longitude);
+		}
 
+		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
 	}
 
 	if (cinfo.density_unit != 0 || ed->x_resolution) {
diff --git a/src/tracker-extract/tracker-extract-pdf.c b/src/tracker-extract/tracker-extract-pdf.c
index f1a63ed..c617ad8 100644
--- a/src/tracker-extract/tracker-extract-pdf.c
+++ b/src/tracker-extract/tracker-extract-pdf.c
@@ -505,56 +505,73 @@ tracker_extract_get_metadata (const gchar          *uri,
 			tracker_sparql_builder_object (metadata, xd->metering_mode);
 		}
 
-		if (xd->address || xd->country || xd->city) {
-			gchar *addruri;
+		if (xd->address || xd->state || xd->country || xd->city ||
+		    xd->gps_altitude || xd->gps_latitude || xd-> gps_longitude) {
 
-			tracker_sparql_builder_predicate (metadata, "slo:location");
+		        tracker_sparql_builder_predicate (metadata, "slo:location");
 
-			tracker_sparql_builder_object_blank_open (metadata);
+			tracker_sparql_builder_object_blank_open (metadata); /* GeoLocation */
 			tracker_sparql_builder_predicate (metadata, "a");
-			tracker_sparql_builder_object (metadata, "slo:GeoLocation"); /* GeoLocation */
-
-			addruri = tracker_sparql_get_uuid_urn ();
-
-			tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
-			tracker_sparql_builder_object_iri (metadata, addruri);
-
-			tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
-
-			tracker_sparql_builder_insert_open (preupdate, NULL);
-			tracker_sparql_builder_subject_iri (preupdate, addruri);
-
-			g_free (addruri);
-
-			tracker_sparql_builder_predicate (preupdate, "a");
-			tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
-
-			if (xd->address) {
-				tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
-				tracker_sparql_builder_object_unvalidated (preupdate, xd->address);
+			tracker_sparql_builder_object (metadata, "slo:GeoLocation");
+			
+			if (xd->address || xd->state || xd->country || xd->city)  {
+			        gchar *addruri;
+				addruri = tracker_sparql_get_uuid_urn ();
+				
+				tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
+				tracker_sparql_builder_object_iri (metadata, addruri);			
+				
+				tracker_sparql_builder_insert_open (preupdate, NULL);
+				tracker_sparql_builder_subject_iri (preupdate, addruri);
+				
+				g_free (addruri);
+				
+				tracker_sparql_builder_predicate (preupdate, "a");
+				tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+				
+				if (xd->address) {
+				        tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
+				        tracker_sparql_builder_object_unvalidated (preupdate, xd->address);
+				}
+				
+				if (xd->state) {
+				        tracker_sparql_builder_predicate (preupdate, "nco:region");
+				        tracker_sparql_builder_object_unvalidated (preupdate, xd->state);
+				}
+				
+				if (xd->city) {
+				        tracker_sparql_builder_predicate (preupdate, "nco:locality");
+				        tracker_sparql_builder_object_unvalidated (preupdate, xd->city);
+				}
+				
+				if (xd->country) {
+				        tracker_sparql_builder_predicate (preupdate, "nco:country");
+				        tracker_sparql_builder_object_unvalidated (preupdate, xd->country);
+				}
+				
+				tracker_sparql_builder_insert_close (preupdate);
 			}
-
-			if (xd->state) {
-				tracker_sparql_builder_predicate (preupdate, "nco:region");
-				tracker_sparql_builder_object_unvalidated (preupdate, xd->state);
+			
+			if (xd->gps_altitude) {
+			        tracker_sparql_builder_predicate (metadata, "slo:altitude");
+			        tracker_sparql_builder_object_unvalidated (metadata, xd->gps_altitude);
 			}
-
-			if (xd->city) {
-				tracker_sparql_builder_predicate (preupdate, "nco:locality");
-				tracker_sparql_builder_object_unvalidated (preupdate, xd->city);
+			
+			if (xd->gps_latitude) {
+			        tracker_sparql_builder_predicate (metadata, "slo:latitude");
+			        tracker_sparql_builder_object_unvalidated (metadata, xd->gps_latitude);
 			}
-
-			if (xd->country) {
-				tracker_sparql_builder_predicate (preupdate, "nco:country");
-				tracker_sparql_builder_object_unvalidated (preupdate, xd->country);
+			
+			if (xd->gps_longitude) {
+			        tracker_sparql_builder_predicate (metadata, "slo:longitude");
+			        tracker_sparql_builder_object_unvalidated (metadata, xd->gps_longitude);
 			}
-
-			tracker_sparql_builder_insert_close (preupdate);
+			
+			tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
 		}
-
 		tracker_xmp_free (xd);
 	} else {
-		/* So if we are here we have NO XMP data and we just
+	        /* So if we are here we have NO XMP data and we just
 		 * write what we know from Poppler.
 		 */
 		write_pdf_data (pd, metadata, keywords);
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 7bd5073..e111213 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -411,51 +411,69 @@ read_metadata (TrackerSparqlBuilder *preupdate,
 		tracker_sparql_builder_object_unvalidated (metadata, xd->coverage);
 	}
 
-	if (xd->address || xd->country || xd->city) {
-		gchar *addruri;
+	if (xd->address || xd->state || xd->country || xd->city ||
+	    xd->gps_altitude || xd->gps_latitude || xd-> gps_longitude) {
 
 		tracker_sparql_builder_predicate (metadata, "slo:location");
 
-		tracker_sparql_builder_object_blank_open (metadata);
+		tracker_sparql_builder_object_blank_open (metadata); /* GeoLocation */
 		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "slo:GeoLocation"); /* GeoLocation */
-
-		addruri = tracker_sparql_get_uuid_urn ();
-
-		tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
-		tracker_sparql_builder_object_iri (metadata, addruri);
-
-		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
-
-		tracker_sparql_builder_insert_open (preupdate, NULL);
-		tracker_sparql_builder_subject_iri (preupdate, addruri);
-
-		g_free (addruri);
-
-		tracker_sparql_builder_predicate (preupdate, "a");
-		tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+		tracker_sparql_builder_object (metadata, "slo:GeoLocation");
+
+		if (xd->address || xd->state || xd->country || xd->city)  {
+		        gchar *addruri;
+			addruri = tracker_sparql_get_uuid_urn ();
+			
+			tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
+			tracker_sparql_builder_object_iri (metadata, addruri);			
+			
+			tracker_sparql_builder_insert_open (preupdate, NULL);
+			tracker_sparql_builder_subject_iri (preupdate, addruri);
+			
+			g_free (addruri);
+			
+			tracker_sparql_builder_predicate (preupdate, "a");
+			tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+			
+			if (xd->address) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->address);
+			}
+			
+			if (xd->state) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:region");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->state);
+			}
+			
+			if (xd->city) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:locality");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->city);
+			}
+			
+			if (xd->country) {
+			  tracker_sparql_builder_predicate (preupdate, "nco:country");
+			  tracker_sparql_builder_object_unvalidated (preupdate, xd->country);
+			}
 
-		if (xd->address) {
-			tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->address);
+			tracker_sparql_builder_insert_close (preupdate);
 		}
-
-		if (xd->state) {
-			tracker_sparql_builder_predicate (preupdate, "nco:region");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->state);
+		
+		if (xd->gps_altitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:altitude");
+			tracker_sparql_builder_object_unvalidated (metadata, xd->gps_altitude);
 		}
 
-		if (xd->city) {
-			tracker_sparql_builder_predicate (preupdate, "nco:locality");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->city);
+		if (xd->gps_latitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:latitude");
+			tracker_sparql_builder_object_unvalidated (metadata, xd->gps_latitude);
 		}
 
-		if (xd->country) {
-			tracker_sparql_builder_predicate (preupdate, "nco:country");
-			tracker_sparql_builder_object_unvalidated (preupdate, xd->country);
+		if (xd->gps_longitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:longitude");
+			tracker_sparql_builder_object_unvalidated (metadata, xd->gps_longitude);
 		}
 
-		tracker_sparql_builder_insert_close (preupdate);
+		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
 	}
 
 	if (ed->x_resolution) {
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index 53f9644..1b9525e 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -60,6 +60,9 @@ typedef struct {
 	const gchar *state;
 	const gchar *address;
 	const gchar *country;
+        const gchar *gps_altitude;
+        const gchar *gps_latitude;
+        const gchar *gps_longitude;       
 } MergeData;
 
 typedef struct {
@@ -365,6 +368,10 @@ tracker_extract_get_metadata (const gchar          *uri,
 	md.state = tracker_coalesce_strip (2, xd->state, id->state);
 	md.address = tracker_coalesce_strip (2, xd->address, id->sublocation);
 	md.country = tracker_coalesce_strip (2, xd->country, id->country_name);
+        /* FIXME We are not handling the altitude ref here for xmp */
+	md.gps_altitude = tracker_coalesce_strip (2, xd->gps_altitude, ed->gps_altitude);
+	md.gps_latitude = tracker_coalesce_strip (2, xd->gps_latitude, ed->gps_latitude);
+	md.gps_longitude = tracker_coalesce_strip (2, xd->gps_longitude, ed->gps_longitude);
 	md.creator = tracker_coalesce_strip (3, xd->creator, id->byline, id->credit);
 	md.x_dimension = tracker_coalesce_strip (2, td.width, ed->x_dimension);
 	md.y_dimension = tracker_coalesce_strip (2, td.length, ed->y_dimension);
@@ -461,53 +468,73 @@ tracker_extract_get_metadata (const gchar          *uri,
 		tracker_sparql_builder_object_unvalidated (metadata, xd->license);
 	}
 
-	if (md.city || md.state || md.address || md.country) {
-		gchar *addruri;
+	if (md.address || md.state || md.country || md.city ||
+	    md.gps_altitude || md.gps_latitude || md.gps_longitude) {
 
 		tracker_sparql_builder_predicate (metadata, "slo:location");
 
-		tracker_sparql_builder_object_blank_open (metadata);
+		tracker_sparql_builder_object_blank_open (metadata); /* GeoPoint */
 		tracker_sparql_builder_predicate (metadata, "a");
-		tracker_sparql_builder_object (metadata, "slo:GeoLocation"); /* GeoLocation */
+		tracker_sparql_builder_object (metadata, "slo:GeoLocation");
 
-		addruri = tracker_sparql_get_uuid_urn ();
+		if (md.address || md.state || md.country || md.city) {
+	                gchar *addruri;
 
-		tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
-		tracker_sparql_builder_object_iri (metadata, addruri);
+		        addruri = tracker_sparql_get_uuid_urn ();
 
-		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
+		        tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
+	                tracker_sparql_builder_object_iri (metadata, addruri);
 
-		tracker_sparql_builder_insert_open (preupdate, NULL);
-		tracker_sparql_builder_subject_iri (preupdate, addruri);
+		        tracker_sparql_builder_insert_open (preupdate, NULL);
+		        tracker_sparql_builder_subject_iri (preupdate, addruri);
 
-		g_free (addruri);
+		        g_free (addruri);
 
-		tracker_sparql_builder_predicate (preupdate, "a");
-		tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+		        tracker_sparql_builder_predicate (preupdate, "a");
+		        tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+
+			if (md.address) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
+			        tracker_sparql_builder_object_unvalidated (preupdate, md.address);
+			}
+
+			if (md.state) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:region");
+				tracker_sparql_builder_object_unvalidated (preupdate, md.state);
+			}
 
-		if (md.address) {
-			tracker_sparql_builder_predicate (preupdate, "nco:streetAddress");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.address);
+			if (md.city) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:locality");
+				tracker_sparql_builder_object_unvalidated (preupdate, md.city);
+			}
+
+			if (md.country) {
+			        tracker_sparql_builder_predicate (preupdate, "nco:country");
+				tracker_sparql_builder_object_unvalidated (preupdate, md.country);
+			}
+
+			tracker_sparql_builder_insert_close (preupdate);
 		}
 
-		if (md.state) {
-			tracker_sparql_builder_predicate (preupdate, "nco:region");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.state);
+		if (md.gps_altitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:altitude");
+			tracker_sparql_builder_object_unvalidated (metadata, md.gps_altitude);
 		}
 
-		if (md.city) {
-			tracker_sparql_builder_predicate (preupdate, "nco:locality");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.city);
+		if (md.gps_latitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:latitude");
+			tracker_sparql_builder_object_unvalidated (metadata, md.gps_latitude);
 		}
 
-		if (md.country) {
-			tracker_sparql_builder_predicate (preupdate, "nco:country");
-			tracker_sparql_builder_object_unvalidated (preupdate, md.country);
+		if (md.gps_longitude) {
+		        tracker_sparql_builder_predicate (metadata, "slo:longitude");
+			tracker_sparql_builder_object_unvalidated (metadata, md.gps_longitude);
 		}
 
-		tracker_sparql_builder_insert_close (preupdate);
+		tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */
 	}
 
+
 	if (id->contact) {
 		gchar *uri = tracker_sparql_escape_uri_printf ("urn:contact:%s", id->contact);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]