Merge lp:~mterry/geonames/expose-more into lp:geonames

Proposed by Michael Terry
Status: Merged
Approved by: Michael Terry
Approved revision: 26
Merged at revision: 23
Proposed branch: lp:~mterry/geonames/expose-more
Merge into: lp:geonames
Prerequisite: lp:~mterry/geonames/trainify
Diff against target: 271 lines (+117/-15) (has conflicts)
8 files modified
configure.ac (+1/-1)
debian/changelog (+10/-0)
debian/libgeonames0.symbols (+4/-0)
src/geonames-mkdb.c (+6/-3)
src/geonames-query.c (+2/-2)
src/geonames.c (+67/-2)
src/geonames.h (+12/-0)
tests/test-geonames.c (+15/-7)
Text conflict in debian/changelog
To merge this branch: bzr merge lp:~mterry/geonames/expose-more
Reviewer Review Type Date Requested Status
Allison Karlitskaya (community) Approve
Nick Dedekind (community) Approve
Review via email: mp+287365@code.launchpad.net

Commit message

Add geonames_city_get_country_code, geonames_city_get_latitude, geonames_city_get_longitude, and geonames_city_get_population.

Description of the change

Expose country code, latitude, longitude, and population. This will be useful for the unity8 welcome wizard, to preseed the timezone selector with all countries that match the selected locale, and to use in a visual map of cities.

To post a comment you must log in.
lp:~mterry/geonames/expose-more updated
22. By Michael Terry

Merge trainify

23. By Michael Terry

Merge trainify

24. By Michael Terry

Add get_population

25. By Michael Terry

Mention it in changelog

26. By Michael Terry

And add symbol; geeze

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

Looks fine. Confirm tests pass.

review: Approve
Revision history for this message
Allison Karlitskaya (desrt) wrote :

(style only) seems quite good -- one minor comment below.

review: Approve
Revision history for this message
Michael Terry (mterry) wrote :

Comment replied inline. I agree with you, but better safe than sorry.

lp:~mterry/geonames/expose-more updated
27. By Michael Terry

And for safety, initialize static geonames_data to NULL

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2016-02-26 20:55:20 +0000
3+++ configure.ac 2016-03-21 23:37:48 +0000
4@@ -1,4 +1,4 @@
5-AC_INIT(geonames, 0.1)
6+AC_INIT(geonames, 0.2)
7
8 AM_INIT_AUTOMAKE([foreign])
9 AM_SILENT_RULES([yes])
10
11=== modified file 'debian/changelog'
12--- debian/changelog 2016-03-15 13:33:03 +0000
13+++ debian/changelog 2016-03-21 23:37:48 +0000
14@@ -1,3 +1,4 @@
15+<<<<<<< TREE
16 geonames (0.1+16.04.20160315-0ubuntu1) xenial; urgency=medium
17
18 [ Lars Uebernickel ]
19@@ -31,6 +32,15 @@
20
21 -- Ken VanDine <ken.vandine@canonical.com> Tue, 15 Mar 2016 13:33:03 +0000
22
23+=======
24+geonames (0.2) UNRELEASED; urgency=medium
25+
26+ * Add geonames_city_get_country_code, geonames_city_get_latitude,
27+ geonames_city_get_longitude, and geonames_city_get_population
28+
29+ -- Michael Terry <mterry@ubuntu.com> Fri, 26 Feb 2016 15:17:11 -0500
30+
31+>>>>>>> MERGE-SOURCE
32 geonames (0.1-0ubuntu1) xenial; urgency=low
33
34 * Initial release
35
36=== modified file 'debian/libgeonames0.symbols'
37--- debian/libgeonames0.symbols 2015-12-09 14:10:20 +0000
38+++ debian/libgeonames0.symbols 2016-03-21 23:37:48 +0000
39@@ -1,7 +1,11 @@
40 libgeonames.so.0 libgeonames0 #MINVER#
41 geonames_city_free@Base 0.1
42 geonames_city_get_country@Base 0.1
43+ geonames_city_get_country_code@Base 0replaceme
44+ geonames_city_get_latitude@Base 0replaceme
45+ geonames_city_get_longitude@Base 0replaceme
46 geonames_city_get_name@Base 0.1
47+ geonames_city_get_population@Base 0replaceme
48 geonames_city_get_state@Base 0.1
49 geonames_city_get_timezone@Base 0.1
50 geonames_get_city@Base 0.1
51
52=== modified file 'src/geonames-mkdb.c'
53--- src/geonames-mkdb.c 2015-09-15 09:59:14 +0000
54+++ src/geonames-mkdb.c 2016-03-21 23:37:48 +0000
55@@ -139,12 +139,15 @@
56 if (country == NULL)
57 return;
58
59- g_variant_builder_add (&data->builder, "(@s@s@s@su)",
60+ g_variant_builder_add (&data->builder, "(@s@s@s@su@sdd)",
61 variant_new_normalize_string (fields[CITIES_NAME]),
62 variant_new_normalize_string (admin1),
63 variant_new_normalize_string (country),
64 variant_new_normalize_string (fields[CITIES_TIMEZONE]),
65- strtoul (fields[CITIES_POPULATION], NULL, 10));
66+ strtoul (fields[CITIES_POPULATION], NULL, 10),
67+ variant_new_normalize_string (fields[CITIES_COUNTRY_CODE]),
68+ g_ascii_strtod (fields[CITIES_LATITUDE], NULL),
69+ g_ascii_strtod (fields[CITIES_LONGITUDE], NULL));
70 }
71
72 static gboolean
73@@ -213,7 +216,7 @@
74
75 data.admin1 = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
76 data.countries = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
77- g_variant_builder_init (&data.builder, G_VARIANT_TYPE ("a(ssssu)"));
78+ g_variant_builder_init (&data.builder, G_VARIANT_TYPE ("a(ssssusdd)"));
79
80 if (!parse_geo_names_file (admin1_file, 4, handle_admin1_line, data.admin1, &error))
81 {
82
83=== modified file 'src/geonames-query.c'
84--- src/geonames-query.c 2015-10-05 09:33:43 +0000
85+++ src/geonames-query.c 2016-03-21 23:37:48 +0000
86@@ -126,7 +126,7 @@
87 gsize i;
88 GArray *indices;
89
90- g_return_val_if_fail (g_variant_is_of_type (db, G_VARIANT_TYPE ("a(ssssu)")), NULL);
91+ g_return_val_if_fail (g_variant_is_of_type (db, G_VARIANT_TYPE ("a(ssssusdd)")), NULL);
92 g_return_val_if_fail (query != NULL, NULL);
93
94 query_tokens = g_str_tokenize_and_fold (query, NULL, NULL);
95@@ -139,7 +139,7 @@
96 guint population;
97 gdouble weight;
98
99- g_variant_get_child (db, i, "(&s&s&s&su)", &name, NULL, NULL, NULL, &population);
100+ g_variant_get_child (db, i, "(&s&s&s&su&sdd)", &name, NULL, NULL, NULL, &population, NULL, NULL, NULL);
101
102 weight = match_query (query_tokens, name);
103 weight *= (gdouble) CLAMP (population, 1, 1000000) / 1000000;
104
105=== modified file 'src/geonames.c'
106--- src/geonames.c 2016-03-01 20:03:50 +0000
107+++ src/geonames.c 2016-03-21 23:37:48 +0000
108@@ -30,7 +30,7 @@
109 * and country data of geonames.org.
110 */
111
112-static GVariant *geonames_data;
113+static GVariant *geonames_data = NULL;
114
115 static void
116 ensure_geonames_data (void)
117@@ -43,7 +43,7 @@
118 data = g_resources_lookup_data ("/com/ubuntu/geonames/cities.compiled", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
119 g_assert (data);
120
121- v = g_variant_new_from_bytes (G_VARIANT_TYPE ("a(ssssu)"), data, TRUE);
122+ v = g_variant_new_from_bytes (G_VARIANT_TYPE ("a(ssssusdd)"), data, TRUE);
123
124 g_once_init_leave (&geonames_data, v);
125 }
126@@ -270,6 +270,22 @@
127 }
128
129 /**
130+ * geonames_city_get_country_code:
131+ * @city: a #GeonamesCity
132+ *
133+ * Returns: the ISO-3166 two-letter country code of @city
134+ */
135+const gchar *
136+geonames_city_get_country_code (GeonamesCity *city)
137+{
138+ const gchar *country_code;
139+
140+ g_variant_get_child (city, 5, "&s", &country_code);
141+
142+ return country_code;
143+}
144+
145+/**
146 * geonames_city_get_timezone:
147 * @city: a #GeonamesCity
148 *
149@@ -284,3 +300,52 @@
150
151 return timezone;
152 }
153+
154+/**
155+ * geonames_city_get_latitude:
156+ * @city: a #GeonamesCity
157+ *
158+ * Returns: the latitude of @city
159+ */
160+gdouble
161+geonames_city_get_latitude (GeonamesCity *city)
162+{
163+ gdouble latitude;
164+
165+ g_variant_get_child (city, 6, "d", &latitude);
166+
167+ return latitude;
168+}
169+
170+/**
171+ * geonames_city_get_longitude:
172+ * @city: a #GeonamesCity
173+ *
174+ * Returns: the longitude of @city
175+ */
176+gdouble
177+geonames_city_get_longitude (GeonamesCity *city)
178+{
179+ gdouble longitude;
180+
181+ g_variant_get_child (city, 7, "d", &longitude);
182+
183+ return longitude;
184+}
185+
186+
187+/**
188+ * geonames_city_get_population:
189+ * @city: a #GeonamesCity
190+ *
191+ * Returns: the population of @city
192+ */
193+guint
194+geonames_city_get_population (GeonamesCity *city)
195+{
196+ guint population;
197+
198+ g_variant_get_child (city, 4, "u", &population);
199+
200+ return population;
201+}
202
203=== modified file 'src/geonames.h'
204--- src/geonames.h 2016-02-26 21:26:48 +0000
205+++ src/geonames.h 2016-03-21 23:37:48 +0000
206@@ -78,8 +78,20 @@
207 const gchar * geonames_city_get_country (GeonamesCity *city);
208
209 _GEONAMES_EXPORT
210+const gchar * geonames_city_get_country_code (GeonamesCity *city);
211+
212+_GEONAMES_EXPORT
213 const gchar * geonames_city_get_timezone (GeonamesCity *city);
214
215+_GEONAMES_EXPORT
216+gdouble geonames_city_get_latitude (GeonamesCity *city);
217+
218+_GEONAMES_EXPORT
219+gdouble geonames_city_get_longitude (GeonamesCity *city);
220+
221+_GEONAMES_EXPORT
222+guint geonames_city_get_population (GeonamesCity *city);
223+
224 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GeonamesCity, geonames_city_free)
225
226 G_END_DECLS
227
228=== modified file 'tests/test-geonames.c'
229--- tests/test-geonames.c 2015-10-05 10:27:50 +0000
230+++ tests/test-geonames.c 2016-03-21 23:37:48 +0000
231@@ -24,7 +24,11 @@
232 static void
233 assert_first (const gchar *query,
234 const gchar *expected_city,
235- const gchar *expected_country)
236+ const gchar *expected_country,
237+ const gchar *expected_country_code,
238+ gdouble expected_latitude,
239+ gdouble expected_longitude,
240+ guint expected_population)
241 {
242 g_autofree gint *indices;
243 guint len;
244@@ -39,17 +43,21 @@
245
246 g_assert_cmpstr (geonames_city_get_name (city), ==, expected_city);
247 g_assert_cmpstr (geonames_city_get_country (city), ==, expected_country);
248+ g_assert_cmpstr (geonames_city_get_country_code (city), ==, expected_country_code);
249+ g_assert_cmpfloat (geonames_city_get_latitude (city), ==, expected_latitude);
250+ g_assert_cmpfloat (geonames_city_get_longitude (city), ==, expected_longitude);
251+ g_assert_cmpint (geonames_city_get_population (city), ==, expected_population);
252 }
253
254 static void
255 test_common_cities (void)
256 {
257- assert_first ("berlin", "Berlin", "Germany");
258- assert_first ("new york", "New York City", "United States");
259- assert_first ("san fran", "San Francisco", "United States");
260- assert_first ("amster", "Amsterdam", "Netherlands");
261- assert_first ("montreal", "Montréal", "Canada");
262- assert_first ("montréal", "Montréal", "Canada");
263+ assert_first ("berlin", "Berlin", "Germany", "DE", 52.52437, 13.41053, 3426354);
264+ assert_first ("new york", "New York City", "United States", "US", 40.71427, -74.00597, 8175133);
265+ assert_first ("san fran", "San Francisco", "United States", "US", 37.77493, -122.41942, 805235);
266+ assert_first ("amster", "Amsterdam", "Netherlands", "NL", 52.37403, 4.88969, 741636);
267+ assert_first ("montreal", "Montréal", "Canada", "CA", 45.50884, -73.58781, 3268513);
268+ assert_first ("montréal", "Montréal", "Canada", "CA", 45.50884, -73.58781, 3268513);
269 }
270
271 static void

Subscribers

People subscribed via source and target branches