47 if(locid == -1)
return;
55 "DELETE FROM data.locations WHERE tagid=?1",
59 sqlite3_finalize(stmt);
100 " FROM main.tagged_images"
105 if(sqlite3_step(stmt) == SQLITE_ROW)
106 count = sqlite3_column_int(stmt, 0);
107 sqlite3_finalize(stmt);
113 const gboolean remove_root)
117 gchar *path1, *path2;
121 path2 = g_strdup_printf(
"%s|", path1);
126 path2 = g_strdup_printf(
"%s|", path1);
133 "SELECT t.id, t.name, ti.count"
134 " FROM data.tags AS t"
135 " LEFT JOIN (SELECT tagid,"
136 " COUNT(DISTINCT imgid) AS count"
137 " FROM main.tagged_images"
138 " GROUP BY tagid) AS ti"
139 " ON ti.tagid = t.id"
140 " WHERE name = ?1 OR SUBSTR(name, 1, LENGTH(?2)) = ?2",
145 while(sqlite3_step(stmt) == SQLITE_ROW)
147 const char *
name = (
const char *)sqlite3_column_text(stmt, 1);
155 t->tag = g_strdup(
name);
156 t->id = sqlite3_column_int(stmt, 0);
157 t->count = sqlite3_column_int(stmt, 2);
158 locs = g_list_prepend(locs,
t);
162 sqlite3_finalize(stmt);
177 " FROM data.locations AS t"
178 " WHERE latitude IS NOT NULL"
179 " AND (latitude + delta2) > ?2"
180 " AND (latitude - delta2) < ?1"
181 " AND (longitude + delta1) > ?3"
182 " AND (longitude - delta1) < ?4",
191 while(sqlite3_step(stmt) == SQLITE_ROW)
196 t->id = sqlite3_column_int(stmt, 0);
197 t->data.shape = sqlite3_column_int(stmt, 1);
198 t->data.lon = sqlite3_column_double(stmt, 2);
199 t->data.lat = sqlite3_column_double(stmt, 3);
200 t->data.delta1 = sqlite3_column_double(stmt, 4);
201 t->data.delta2 = sqlite3_column_double(stmt, 5);
202 t->data.ratio = sqlite3_column_double(stmt, 6);
203 locs = g_list_prepend(locs,
t);
206 sqlite3_finalize(stmt);
218 "SELECT polygons FROM data.locations AS t"
224 if(sqlite3_step(stmt) == SQLITE_ROW)
228 memcpy(
p, sqlite3_column_blob(stmt, 0), ld->
data.
plg_pts);
232 pol = g_list_prepend(pol,
p);
233 pol = g_list_reverse(pol);
236 sqlite3_finalize(stmt);
254 gboolean inside =
FALSE;
256 float lat1 = plp->
lat;
257 float lon1 = plp->
lon;
259 for(
int i = 0;
i < plg_pts;
i++)
272 if(!(((lat1 > pt->
lat) && (lat2 > pt->
lat)) ||
273 ((lat1 < pt->
lat) && (lat2 < pt->
lat))))
275 const float sl = lon1 + (lon2 - lon1) * (pt->
lat - lat1) / (lat2 - lat1);
294 if(result && *result)
306 return g_strcmp0(tuple_a->
tag, tuple_b->
tag);
314 for(GList *taglist = tags; taglist; taglist = g_list_next(taglist))
317 for(
char *letter = tag; *letter; letter++)
318 if(*letter ==
'|') *letter =
'\1';
321 for(GList *taglist = sorted_tags; taglist; taglist = g_list_next(taglist))
324 for(
char *letter = tag; *letter; letter++)
325 if(*letter ==
'\1') *letter =
'|';
333 if(locid == -1)
return NULL;
338 "SELECT type, longitude, latitude, delta1, delta2, ratio"
339 " FROM data.locations"
340 " JOIN data.tags ON id = tagid"
341 " WHERE tagid = ?1 AND longitude IS NOT NULL"
342 " AND SUBSTR(name, 1, LENGTH(?2)) = ?2",
348 if(sqlite3_step(stmt) == SQLITE_ROW)
351 g->shape = sqlite3_column_int(stmt, 0);
352 g->lon = sqlite3_column_double(stmt, 1);
353 g->lat = sqlite3_column_double(stmt, 2);
354 g->delta1 = sqlite3_column_double(stmt, 3);
355 g->delta2 = sqlite3_column_double(stmt, 4);
356 g->ratio = sqlite3_column_double(stmt, 5);
358 sqlite3_finalize(stmt);
365 if(locid == -1)
return;
369 "INSERT OR REPLACE INTO data.locations"
370 " (tagid, type, longitude, latitude, delta1, delta2, ratio, polygons)"
371 " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
391 sqlite3_finalize(stmt);
401 "SELECT l.tagid, l.type, i.longitude, i.latitude FROM main.images AS i"
402 " JOIN data.locations AS l"
404 " AND ((((i.longitude-l.longitude)*(i.longitude-l.longitude))/"
406 " ((i.latitude-l.latitude)*(i.latitude-l.latitude))/"
407 "(delta2*delta2)) <= 1)"
408 " OR ((l.type = ?3 OR l.type = ?4)"
409 " AND i.longitude>=(l.longitude-delta1)"
410 " AND i.longitude<=(l.longitude+delta1)"
411 " AND i.latitude>=(l.latitude-delta2)"
412 " AND i.latitude<=(l.latitude+delta2)))"
414 " AND i.latitude IS NOT NULL AND i.longitude IS NOT NULL",
422 while(sqlite3_step(stmt) == SQLITE_ROW)
424 const int id = sqlite3_column_int(stmt, 0);
428 pt.
lon = sqlite3_column_double(stmt, 2);
429 pt.
lat = sqlite3_column_double(stmt, 3);
432 "SELECT polygons FROM data.locations "
436 if(sqlite3_step(stmt2) == SQLITE_ROW)
441 tags = g_list_prepend(tags, GINT_TO_POINTER(
id));
444 sqlite3_finalize(stmt2);
448 tags = g_list_prepend(tags, GINT_TO_POINTER(
id));
451 sqlite3_finalize(stmt);
463 "SELECT i.id FROM main.images AS i"
464 " JOIN data.locations AS l"
466 " AND ((((i.longitude-l.longitude)*(i.longitude-l.longitude))/"
468 " ((i.latitude-l.latitude)*(i.latitude-l.latitude))/"
469 "(delta2*delta2)) <= 1))"
470 " WHERE l.tagid = ?1 ",
476 "SELECT i.id FROM main.images AS i"
477 " JOIN data.locations AS l"
479 " AND i.longitude>=(l.longitude-delta1)"
480 " AND i.longitude<=(l.longitude+delta1)"
481 " AND i.latitude>=(l.latitude-delta2)"
482 " AND i.latitude<=(l.latitude+delta2))"
483 " WHERE l.tagid = ?1 ",
489 "SELECT i.id, i.longitude, i.latitude FROM main.images AS i"
490 " JOIN data.locations AS l"
492 " AND i.longitude>=(l.longitude-delta1)"
493 " AND i.longitude<=(l.longitude+delta1)"
494 " AND i.latitude>=(l.latitude-delta2)"
495 " AND i.latitude<=(l.latitude+delta2))"
496 " WHERE l.tagid = ?1 ",
502 while(sqlite3_step(stmt) == SQLITE_ROW)
504 const int id = sqlite3_column_int(stmt, 0);
508 pt.
lon = sqlite3_column_double(stmt, 1);
509 pt.
lat = sqlite3_column_double(stmt, 2);
511 imgs = g_list_prepend(imgs, GINT_TO_POINTER(
id));
514 imgs = g_list_prepend(imgs, GINT_TO_POINTER(
id));
516 sqlite3_finalize(stmt);
524 GList *old_tags = NULL;
528 "SELECT t.id FROM main.tagged_images ti"
529 " JOIN data.tags AS t ON t.id = ti.tagid"
530 " JOIN data.locations AS l ON l.tagid = t.id"
536 while(sqlite3_step(stmt) == SQLITE_ROW)
538 const int id = sqlite3_column_int(stmt, 0);
539 old_tags = g_list_prepend(old_tags, GINT_TO_POINTER(
id));
541 sqlite3_finalize(stmt);
544 for(GList *tag = old_tags; tag; tag = g_list_next(tag))
546 if(!g_list_find((GList *)tags, tag->data))
554 for(GList *tag = (GList *)tags; tag; tag = g_list_next(tag))
556 if(!g_list_find(old_tags, tag->data))
562 g_list_free(old_tags);
575 gboolean res =
FALSE;
577 for(GList *img = imgs; img; img = g_list_next(img))
579 if(!g_list_find(new_imgs, img->data))
587 for(GList *img = new_imgs; img; img = g_list_next(img))
589 if(!g_list_find(imgs, img->data))
595 g_list_free(new_imgs);
612 gboolean included =
FALSE;
614 (((
g->lon -
lon) * (
g->lon -
lon) / (
g->delta1 *
g->delta1) +
615 (
g->lat -
lat) * (
g->lat -
lat) / (
g->delta2 *
g->delta2)) <= 1.0))
618 lon >
g->lon -
g->delta1 && lon < g->
lon +
g->delta1 &&
619 lat >
g->lat -
g->delta2 && lat < g->
lat +
g->delta2))
629 const int nb = g_list_length(polygons);
635 for(GList *pol = polygons; pol; pol = g_list_next(pol),
p++)
640 npol = g_list_prepend(npol,
p);
649 npol = g_list_reverse(npol);
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
GList * dt_map_location_sort(GList *tags)
static void _free_result_item(dt_map_location_t *t, gpointer unused)
GList * dt_map_location_get_locations_by_path(const gchar *path, const gboolean remove_root)
void dt_map_location_update_locations(const int32_t imgid, const GList *tags)
dt_map_location_data_t * dt_map_location_get_data(const guint locid)
static gboolean _is_point_in_polygon(const dt_geo_map_display_point_t *pt, const gint plg_pts, const dt_geo_map_display_point_t *plp)
const char * dt_map_location_data_tag_root()
gboolean dt_map_location_update_images(dt_location_draw_t *ld)
void dt_map_location_free_result(GList **result)
GList * dt_map_location_convert_polygons(void *polygons, dt_map_box_t *bbox, int *nb_pts)
void dt_map_location_set_data(const guint locid, const dt_map_location_data_t *g)
void dt_map_location_delete(const guint locid)
void dt_map_location_get_polygons(dt_location_draw_t *ld)
gboolean dt_map_location_included(const float lon, const float lat, dt_map_location_data_t *g)
void dt_map_location_free_polygons(dt_location_draw_t *ld)
void dt_map_location_rename(const guint locid, const char *const name)
GList * dt_map_location_find_locations(const int32_t imgid)
GList * _map_location_find_images(dt_location_draw_t *ld)
const char * location_tag_prefix
gboolean dt_map_location_name_exists(const char *const name)
int dt_map_location_get_images_count(const guint locid)
guint dt_map_location_new(const char *const name)
static gint _sort_by_path(gconstpointer a, gconstpointer b)
const char * location_tag
GList * dt_map_location_get_locations_on_map(const dt_map_box_t *const bbox)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
sqlite3 * dt_database_get(const dt_database_t *db)
#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)
@ MAP_LOCATION_SHAPE_POLYGONS
@ MAP_LOCATION_SHAPE_RECTANGLE
@ MAP_LOCATION_SHAPE_ELLIPSE
const struct dt_database_t * db
dt_map_location_data_t data