30 sqlite3_stmt *stmt = NULL;
33 "DELETE FROM data.locations WHERE tagid=?1", -1, &stmt, NULL);
37 sqlite3_finalize(stmt);
42 sqlite3_stmt *stmt = NULL;
48 "SELECT tagid, type, longitude, latitude, delta1, delta2, ratio"
49 " FROM data.locations AS t"
50 " WHERE latitude IS NOT NULL"
51 " AND (latitude + delta2) > ?2"
52 " AND (latitude - delta2) < ?1"
53 " AND (longitude + delta1) > ?3"
54 " AND (longitude - delta1) < ?4",
63 while(sqlite3_step(stmt) == SQLITE_ROW)
68 t->id = sqlite3_column_int(stmt, 0);
69 t->data.shape = sqlite3_column_int(stmt, 1);
70 t->data.lon = sqlite3_column_double(stmt, 2);
71 t->data.lat = sqlite3_column_double(stmt, 3);
72 t->data.delta1 = sqlite3_column_double(stmt, 4);
73 t->data.delta2 = sqlite3_column_double(stmt, 5);
74 t->data.ratio = sqlite3_column_double(stmt, 6);
75 locs = g_list_prepend(locs,
t);
78 sqlite3_finalize(stmt);
85 sqlite3_stmt *stmt = NULL;
88 "SELECT type, longitude, latitude, delta1, delta2, ratio"
89 " FROM data.locations"
90 " JOIN data.tags ON id = tagid"
91 " WHERE tagid = ?1 AND longitude IS NOT NULL"
92 " AND SUBSTR(name, 1, LENGTH(?2)) = ?2",
99 if(sqlite3_step(stmt) == SQLITE_ROW)
102 g->shape = sqlite3_column_int(stmt, 0);
103 g->lon = sqlite3_column_double(stmt, 1);
104 g->lat = sqlite3_column_double(stmt, 2);
105 g->delta1 = sqlite3_column_double(stmt, 3);
106 g->delta2 = sqlite3_column_double(stmt, 4);
107 g->ratio = sqlite3_column_double(stmt, 5);
109 sqlite3_finalize(stmt);
115 sqlite3_stmt *stmt = NULL;
118 "INSERT OR REPLACE INTO data.locations"
119 " (tagid, type, longitude, latitude, delta1, delta2, ratio, polygons)"
120 " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
140 sqlite3_finalize(stmt);
149 sqlite3_stmt *stmt = NULL;
152 "SELECT polygons FROM data.locations WHERE tagid = ?1",
157 gboolean found =
FALSE;
158 if(sqlite3_step(stmt) == SQLITE_ROW)
160 const int n = sqlite3_column_bytes(stmt, 0);
161 const void *src = sqlite3_column_blob(stmt, 0);
179 sqlite3_finalize(stmt);
185 sqlite3_stmt *stmt = NULL;
188 "SELECT l.tagid, l.type, i.longitude, i.latitude FROM main.images AS i"
189 " JOIN data.locations AS l"
191 " AND ((((i.longitude-l.longitude)*(i.longitude-l.longitude))/"
193 " ((i.latitude-l.latitude)*(i.latitude-l.latitude))/"
194 "(delta2*delta2)) <= 1)"
195 " OR ((l.type = ?3 OR l.type = ?4)"
196 " AND i.longitude>=(l.longitude-delta1)"
197 " AND i.longitude<=(l.longitude+delta1)"
198 " AND i.latitude>=(l.latitude-delta2)"
199 " AND i.latitude<=(l.latitude+delta2)))"
201 " AND i.latitude IS NOT NULL AND i.longitude IS NOT NULL",
209 GList *candidates = NULL;
210 while(sqlite3_step(stmt) == SQLITE_ROW)
215 c->id = sqlite3_column_int(stmt, 0);
216 c->shape = sqlite3_column_int(stmt, 1);
217 c->lon = sqlite3_column_double(stmt, 2);
218 c->lat = sqlite3_column_double(stmt, 3);
219 candidates = g_list_prepend(candidates, c);
222 sqlite3_finalize(stmt);
224 return g_list_reverse(candidates);
229 sqlite3_stmt *stmt = NULL;
235 "SELECT i.id, i.longitude, i.latitude FROM main.images AS i"
236 " JOIN data.locations AS l"
238 " AND ((((i.longitude-l.longitude)*(i.longitude-l.longitude))/"
240 " ((i.latitude-l.latitude)*(i.latitude-l.latitude))/"
241 "(delta2*delta2)) <= 1))"
242 " WHERE l.tagid = ?1 ",
250 "SELECT i.id, i.longitude, i.latitude FROM main.images AS i"
251 " JOIN data.locations AS l"
253 " AND i.longitude>=(l.longitude-delta1)"
254 " AND i.longitude<=(l.longitude+delta1)"
255 " AND i.latitude>=(l.latitude-delta2)"
256 " AND i.latitude<=(l.latitude+delta2))"
257 " WHERE l.tagid = ?1 ",
265 "SELECT i.id, i.longitude, i.latitude FROM main.images AS i"
266 " JOIN data.locations AS l"
268 " AND i.longitude>=(l.longitude-delta1)"
269 " AND i.longitude<=(l.longitude+delta1)"
270 " AND i.latitude>=(l.latitude-delta2)"
271 " AND i.latitude<=(l.latitude+delta2))"
272 " WHERE l.tagid = ?1 ",
280 GList *candidates = NULL;
281 while(sqlite3_step(stmt) == SQLITE_ROW)
286 c->id = sqlite3_column_int(stmt, 0);
288 c->lon = sqlite3_column_double(stmt, 1);
289 c->lat = sqlite3_column_double(stmt, 2);
290 candidates = g_list_prepend(candidates, c);
293 sqlite3_finalize(stmt);
298 return g_list_reverse(candidates);
303 sqlite3_stmt *stmt = NULL;
306 "SELECT t.id FROM main.tagged_images ti"
307 " JOIN data.tags AS t ON t.id = ti.tagid"
308 " JOIN data.locations AS l ON l.tagid = t.id"
315 while(sqlite3_step(stmt) == SQLITE_ROW)
316 ids = g_list_prepend(ids, GINT_TO_POINTER(sqlite3_column_int(stmt, 0)));
317 sqlite3_finalize(stmt);
sqlite3 * dt_database_get_sqlite3_global(void)
memcpy(roundtrip, origin, sizeof(roundtrip))
GList * dt_location_repository_get_in_bbox(const dt_map_box_t *const bbox)
Locations whose extent overlaps bbox.
gboolean dt_location_repository_get_polygon(const guint locid, void **blob, gint *bytes)
The raw polygon blob of locid.
GList * dt_location_repository_find_images_for_location(const guint locid, const int shape)
Images whose coordinates fall inside location locid.
GList * dt_location_repository_get_image_locations(const int32_t imgid)
Location (tag) ids currently attached to imgid. GINT_TO_POINTER list.
void dt_location_repository_set_data(const guint locid, const dt_map_location_data_t *g)
Insert or replace the geometry of locid, polygon blob included.
void dt_location_repository_delete(const guint locid)
Drop the geometry row of locid. The tag itself is the tag repository's.
GList * dt_location_repository_find_locations_for_image(const int32_t imgid)
Locations whose shape contains imgid's coordinates.
dt_map_location_data_t * dt_location_repository_get_data(const guint locid, const char *name_prefix)
The geometry of locid, if it is a real location.
data.locations: the geometry of a geotagging location.
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
@ MAP_LOCATION_SHAPE_POLYGONS
@ MAP_LOCATION_SHAPE_RECTANGLE
@ MAP_LOCATION_SHAPE_ELLIPSE
Checked wrappers around the sqlite3_* calls: trace the statement, assert the return code,...
#define DT_DEBUG_SQLITE3_BIND_BLOB(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_PREPARE_V2(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_BIND_TEXT(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_BIND_INT(a, b, c)
#define DT_DEBUG_SQLITE3_BIND_DOUBLE(a, b, c)
One row of a geo query: an id with the position that matched.