[geocode-glib] forward: add search area property
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] forward: add search area property
- Date: Thu, 5 Dec 2013 15:07:41 +0000 (UTC)
commit f153ec788bf5b6741d8904584f4cfdaa5eefa906
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Tue Dec 3 13:00:03 2013 +0100
forward: add search area property
Nominatim allows searches to be limited to a viewbox. In
order to take advantage of this we need a new property.
The search area is specified as a GeocodeBoundingBox.
https://bugzilla.gnome.org/show_bug.cgi?id=719585
geocode-glib/geocode-forward.c | 89 +++++++++++++++++++++++++++++++++++-
geocode-glib/geocode-forward.h | 14 ++++--
geocode-glib/geocode-glib.symbols | 2 +
3 files changed, 97 insertions(+), 8 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index b8b05f6..2b69479 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -27,6 +27,7 @@
#include <json-glib/json-glib.h>
#include <libsoup/soup.h>
#include <geocode-glib/geocode-forward.h>
+#include <geocode-glib/geocode-bounding-box.h>
#include <geocode-glib/geocode-error.h>
#include <geocode-glib/geocode-glib-private.h>
@@ -43,12 +44,14 @@ struct _GeocodeForwardPrivate {
GHashTable *ht;
SoupSession *soup_session;
guint answer_count;
+ GeocodeBoundingBox *search_area;
};
enum {
PROP_0,
- PROP_ANSWER_COUNT
+ PROP_ANSWER_COUNT,
+ PROP_SEARCH_AREA
};
G_DEFINE_TYPE (GeocodeForward, geocode_forward, G_TYPE_OBJECT)
@@ -67,6 +70,11 @@ geocode_forward_get_property (GObject *object,
geocode_forward_get_answer_count (forward));
break;
+ case PROP_SEARCH_AREA:
+ g_value_set_object (value,
+ geocode_forward_get_search_area (forward));
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -88,6 +96,11 @@ geocode_forward_set_property(GObject *object,
g_value_get_uint (value));
break;
+ case PROP_SEARCH_AREA:
+ geocode_forward_set_search_area (forward,
+ g_value_get_object (value));
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -138,6 +151,19 @@ geocode_forward_class_init (GeocodeForwardClass *klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gforward_class, PROP_ANSWER_COUNT, pspec);
+
+ /**
+ * GeocodeForward:search-area:
+ *
+ * The bounding box that limits the search area.
+ */
+ pspec = g_param_spec_object ("search-area",
+ "Search area",
+ "The area to limit search within",
+ GEOCODE_TYPE_BOUNDING_BOX,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (gforward_class, PROP_SEARCH_AREA, pspec);
}
static void
@@ -148,6 +174,7 @@ geocode_forward_init (GeocodeForward *forward)
g_free, g_free);
forward->priv->soup_session = soup_session_new ();
forward->priv->answer_count = DEFAULT_ANSWER_COUNT;
+ forward->priv->search_area = NULL;
}
static struct {
@@ -432,8 +459,11 @@ get_search_query_for_params (GeocodeForward *forward,
if (location != NULL) {
/* Prepare the search term */
search_term = soup_uri_encode (location, NULL);
- uri = g_strdup_printf ("http://nominatim.gnome.org/search?q=%s&limit=%u&%s",
- search_term, forward->priv->answer_count, params);
+ uri = g_strdup_printf ("http://nominatim.gnome.org/search?q=%s&limit=%u&bounded=%d&%s",
+ search_term,
+ forward->priv->answer_count,
+ forward->priv->search_area ? 1 : 0,
+ params);
g_free (search_term);
g_free (location);
} else {
@@ -985,6 +1015,45 @@ geocode_forward_set_answer_count (GeocodeForward *forward,
}
/**
+ * geocode_forward_set_search_area:
+ * @forward: a #GeocodeForward representing a query
+ * @box: a bounding box to limit the search area.
+ *
+ * Sets the area to limit searches within.
+ **/
+void
+geocode_forward_set_search_area (GeocodeForward *forward,
+ GeocodeBoundingBox *bbox)
+{
+ char *area;
+ char top[G_ASCII_DTOSTR_BUF_SIZE];
+ char left[G_ASCII_DTOSTR_BUF_SIZE];
+ char bottom[G_ASCII_DTOSTR_BUF_SIZE];
+ char right[G_ASCII_DTOSTR_BUF_SIZE];
+
+ g_return_if_fail (GEOCODE_IS_FORWARD (forward));
+
+ forward->priv->search_area = bbox;
+
+ /* need to convert with g_ascii_dtostr to be locale safe */
+ g_ascii_dtostr (top, G_ASCII_DTOSTR_BUF_SIZE,
+ geocode_bounding_box_get_top (bbox));
+
+ g_ascii_dtostr (bottom, G_ASCII_DTOSTR_BUF_SIZE,
+ geocode_bounding_box_get_bottom (bbox));
+
+ g_ascii_dtostr (left, G_ASCII_DTOSTR_BUF_SIZE,
+ geocode_bounding_box_get_left (bbox));
+
+ g_ascii_dtostr (right, G_ASCII_DTOSTR_BUF_SIZE,
+ geocode_bounding_box_get_right (bbox));
+
+ area = g_strdup_printf ("%s,%s,%s,%s", left, top, right, bottom);
+ geocode_forward_add (forward, "viewbox", area);
+ g_free (area);
+}
+
+/**
* geocode_forward_get_answer_count:
* @forward: a #GeocodeForward representing a query
*
@@ -997,3 +1066,17 @@ geocode_forward_get_answer_count (GeocodeForward *forward)
return forward->priv->answer_count;
}
+
+/**
+ * geocode_forward_get_search_area:
+ * @forward: a #GeocodeForward representing a query
+ *
+ * Gets the area to limit searches within.
+ **/
+GeocodeBoundingBox *
+geocode_forward_get_search_area (GeocodeForward *forward)
+{
+ g_return_val_if_fail (GEOCODE_IS_FORWARD (forward), NULL);
+
+ return forward->priv->search_area;
+}
diff --git a/geocode-glib/geocode-forward.h b/geocode-glib/geocode-forward.h
index 022e9e6..a274484 100644
--- a/geocode-glib/geocode-forward.h
+++ b/geocode-glib/geocode-forward.h
@@ -26,6 +26,7 @@
#include <glib.h>
#include <gio/gio.h>
#include <geocode-glib/geocode-glib.h>
+#include <geocode-glib/geocode-bounding-box.h>
G_BEGIN_DECLS
@@ -63,11 +64,14 @@ struct _GeocodeForwardClass {
GObjectClass parent_class;
};
-GeocodeForward *geocode_forward_new_for_string (const char *str);
-GeocodeForward *geocode_forward_new_for_params (GHashTable *params);
-guint geocode_forward_get_answer_count (GeocodeForward *forward);
-void geocode_forward_set_answer_count (GeocodeForward *forward,
- guint count);
+GeocodeForward *geocode_forward_new_for_string (const char *str);
+GeocodeForward *geocode_forward_new_for_params (GHashTable *params);
+guint geocode_forward_get_answer_count (GeocodeForward *forward);
+void geocode_forward_set_answer_count (GeocodeForward *forward,
+ guint count);
+GeocodeBoundingBox * geocode_forward_get_search_area (GeocodeForward *forward);
+void geocode_forward_set_search_area (GeocodeForward *forward,
+ GeocodeBoundingBox *box);
void geocode_forward_search_async (GeocodeForward *forward,
GCancellable *cancellable,
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index 9a09bb5..bbca565 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -13,6 +13,8 @@ geocode_forward_new_for_string
geocode_forward_new_for_params
geocode_forward_get_answer_count
geocode_forward_set_answer_count
+geocode_forward_get_search_area
+geocode_forward_set_search_area
geocode_forward_search_async
geocode_forward_search_finish
geocode_forward_search
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]