changeset 1509:e70bbc97acc5

added metadata_read_GPS_coord
author nadvornik
date Sat, 04 Apr 2009 19:10:49 +0000
parents 23d24af93ab0
children ad5018434476
files src/metadata.c src/metadata.h
diffstat 2 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/metadata.c	Sat Apr 04 16:42:54 2009 +0000
+++ b/src/metadata.c	Sat Apr 04 19:10:49 2009 +0000
@@ -515,6 +515,43 @@
 	g_free(string);
 	return ret;
 }
+
+gdouble metadata_read_GPS_coord(FileData *fd, const gchar *key, gdouble fallback)
+{
+	gdouble coord;
+	gchar *endptr;
+	gdouble deg, min, sec;
+	gboolean ok = FALSE;
+	gchar *string = metadata_read_string(fd, key, METADATA_PLAIN);
+	if (!string) return fallback;
+	
+	deg = g_ascii_strtod(string, &endptr);
+	if (*endptr == ',')
+		{
+		min = g_ascii_strtod(endptr + 1, &endptr);
+		if (*endptr == ',')
+			sec = g_ascii_strtod(endptr + 1, &endptr);
+		else 
+			sec = 0.0;
+		
+		
+		if (*endptr == 'S' || *endptr == 'W' || *endptr == 'N' || *endptr == 'E') 
+			{
+			coord = deg + min /60.0 + sec / 3600.0;
+			ok = TRUE;
+			if (*endptr == 'S' || *endptr == 'W') coord = -coord;
+			}
+		}
+	
+	if (!ok)
+		{
+		coord = fallback;
+		log_printf("unable to parse GPS coordinate '%s'\n", string);
+		}
+	
+	g_free(string);
+	return coord;
+}
 	
 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value)
 {
--- a/src/metadata.h	Sat Apr 04 16:42:54 2009 +0000
+++ b/src/metadata.h	Sat Apr 04 19:10:49 2009 +0000
@@ -30,6 +30,7 @@
 GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format);
 gchar *metadata_read_string(FileData *fd, const gchar *key, MetadataFormat format);
 guint64 metadata_read_int(FileData *fd, const gchar *key, guint64 fallback);
+gdouble metadata_read_GPS_coord(FileData *fd, const gchar *key, gdouble fallback);
 
 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value);
 gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *values);