Make it easier to support other map backgrounds, added Europe map

sql-rework
Tomasz Golinski 2019-09-08 22:18:13 +02:00
rodzic 54e240f910
commit 6f440ed97e
8 zmienionych plików z 69 dodań i 33 usunięć

BIN
Europe.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 239 KiB

Wyświetl plik

@ -19,6 +19,7 @@ Generate stats from Opencaching data or GPX files.
-D print furthest and closest caches
-H file render a heat map to a file
-s n stamp size for a heat map (default = 15)
-m map chosen map (Poland, Poland_relief, Europe)
-L print all caches
-T print D/T matrix
-h display this help screen
@ -39,5 +40,6 @@ To build the project run `meson build; cd build; ninja`. You might need to set `
### Credits
Map of Poland `Poland.png` comes from `https://pl.wikipedia.org/wiki/Plik:Poland_location_map.svg` and is licenced under CC-BY-SA and GNU FDL.
Map of Poland `Poland_relief.png` comes from `https://commons.wikimedia.org/wiki/File:Relief_Map_of_Poland.svg` and is licenced under CC-BY-SA.
Map of Poland `Poland.png` comes from `https://pl.wikipedia.org/wiki/Plik:Poland_location_map.svg` and is licensed under CC-BY-SA and GNU FDL.
Map of Poland `Poland_relief.png` comes from `https://commons.wikimedia.org/wiki/File:Relief_Map_of_Poland.svg` and is licensed under CC-BY-SA.
Map of Europe `Europe.png` comes from `https://pl.wikipedia.org/wiki/Plik:Europe_location_map.svg` and is licensed under PD.

Wyświetl plik

@ -32,6 +32,9 @@ class Position {
public:
float lat;
float lon;
Position() = default;
Position(float y, float x) : lat(y), lon(x) {}
};
class Cache {

Wyświetl plik

@ -16,7 +16,7 @@ int main(int argc, char** argv) {
bool show_dt = 0;
std::string heat_file;
int heat_stamp_size = 15;
bool heat_relief = 0;
std::string heat_map;
bool use_ocpl = 0;
std::string ocpl_user;
std::string ocpl_url = "https://opencaching.pl/okapi/";
@ -25,7 +25,7 @@ int main(int argc, char** argv) {
#include "config_user.h"
int o;
while ((o = getopt(argc, argv, "g:d:pu:MDH:s:rLTh")) != -1)
while ((o = getopt(argc, argv, "g:d:pu:MDH:s:m:LTh")) != -1)
switch (o) {
case 'd':
try {
@ -68,8 +68,8 @@ int main(int argc, char** argv) {
std::exit(EXIT_FAILURE);
}
break;
case 'r':
heat_relief = 1;
case 'm':
heat_map = optarg;
break;
case 'L':
show_list = 1;
@ -91,6 +91,7 @@ int main(int argc, char** argv) {
std::cout << "\t-D\tprint furthest and closest caches\n";
std::cout << "\t-H file\trender a heat map to a file\n";
std::cout << "\t-s n\tstamp size for a heat map (default = 15)\n";
std::cout << "\t-m map\tchosen map (Poland, Poland_relief, Europe)\n";
std::cout << "\t-L\tprint all caches\n";
std::cout << "\t-T\tprint D/T matrix\n";
std::cout << "\t-h\tdisplay this help screen\n";
@ -117,8 +118,19 @@ int main(int argc, char** argv) {
Debug(2) << "Caches read: " << cc.size() << '\n';
if (!heat_file.empty()) {
Heat hmap(&cc);
hmap.generate(heat_file, heat_stamp_size, heat_relief);
const Map* chosen_map;
if (heat_map == "Poland_relief")
chosen_map = &Poland_relief;
else if (heat_map == "Poland")
chosen_map = &Poland;
else if (heat_map == "Europe")
chosen_map = &Europe;
else {
std::cout << "Map " << heat_map << " not found.\n";
std::exit(EXIT_FAILURE);
}
Heat hmap(&cc, chosen_map);
hmap.generate(heat_file, heat_stamp_size);
}
if (show_minmax) {

Wyświetl plik

@ -9,33 +9,29 @@
#include <vector>
#include <string>
Heat::Heat(Caches* cc) : points(cc) {
Heat::Heat(Caches* cc, const Map* m) : points(cc), mp(m) {
#ifdef graphicsmagick
Magick::InitializeMagick(nullptr);
#endif
}
void Heat::generate(std::string filename, int size, bool relief, std::string theme) {
heatmap_t* hm = heatmap_new(size_x, size_y);
void Heat::generate(std::string filename, int size, std::string theme) {
heatmap_t* hm = heatmap_new(mp->size_x, mp->size_y);
heatmap_stamp_t* stamp = heatmap_stamp_gen(size);
std::vector<unsigned char> image(size_x * size_y * 4);
std::vector<unsigned char> image(mp->size_x * mp->size_y * 4);
for (auto el : *points) {
if (el.pos.lon >= lon_min && el.pos.lon <= lon_max && el.pos.lat >= lat_min && el.pos.lat <= lat_max)
heatmap_add_point_with_stamp(hm, (el.pos.lon - lon_min) / (lon_max - lon_min) * size_x, size_y - static_cast<int>((el.pos.lat - lat_min) / (lat_max - lat_min) * size_y), stamp);
// Debug(2) << static_cast<int>((el.pos.lon - lon_min) / (lon_max - lon_min) * size_x) << " " << size_y - static_cast<int>((el.pos.lat - lat_min) / (lat_max - lat_min) * size_y) << "\n";
if (mp->contains(Position(el.pos.lat, el.pos.lon))) {
heatmap_add_point_with_stamp(hm, mp->coordinate_x(Position(el.pos.lat, el.pos.lon)), mp->coordinate_y(Position(el.pos.lat, el.pos.lon)), stamp);
// std::cout << mp->coordinate_x(Position(el.pos.lon, el.pos.lat)) << '\t' << mp->coordinate_y(Position(el.pos.lon, el.pos.lat)) << '\n';
}
}
heatmap_render_to(hm, heatmap_cs_Spectral_soft, &image[0]);
heatmap_free(hm);
Magick::Image contour;
if (relief)
contour.read(relief_file);
else
contour.read(contour_file);
Magick::Image heatmap(size_x, size_y, "RGBA", Magick::CharPixel, &image[0]);
Magick::Image contour(mp->map_file);
Magick::Image heatmap(mp->size_x, mp->size_y, "RGBA", Magick::CharPixel, &image[0]);
contour.composite(heatmap, 0, 0, Magick::OverCompositeOp);
contour.write(filename);

15
heat.h
Wyświetl plik

@ -1,6 +1,7 @@
#pragma once
#include "cache.h"
#include "maps.h"
#include <set>
#include <string>
@ -8,18 +9,10 @@
class Heat {
private:
Caches* points;
const int size_x = 1000;
const int size_y = 972;
const float lat_max = 55.2;
const float lat_min = 48.7;
const float lon_max = 24.5;
const float lon_min = 13.8;
const std::string contour_file = "Poland.png";
const std::string relief_file = "Poland_relief.png";
const Map* mp;
public:
Heat(Caches* cc);
Heat(Caches* cc, const Map* m);
void generate(std::string filename, int size, bool relief, std::string theme = "");
void generate(std::string filename, int size, std::string theme = "");
};

29
maps.h 100644
Wyświetl plik

@ -0,0 +1,29 @@
#pragma once
class Map {
public:
const int size_x;
const int size_y;
const float lat_max;
const float lat_min;
const float lon_max;
const float lon_min;
const std::string map_file;
Map(int sx, int sy, float lat_mi, float lat_ma, float lon_mi, float lon_ma, std::string file) : size_x(sx), size_y(sy), lat_max(lat_ma), lat_min(lat_mi), lon_max(lon_ma), lon_min(lon_mi), map_file(file) {};
bool contains(Position pos) const {
return (pos.lon >= lon_min && pos.lon <= lon_max && pos.lat >= lat_min && pos.lat <= lat_max);
}
int coordinate_x(Position pos) const {
return (pos.lon - lon_min) / (lon_max - lon_min) * size_x;
}
int coordinate_y(Position pos) const {
return size_y - static_cast<int>((pos.lat - lat_min) / (lat_max - lat_min) * size_y);
}
};
const Map Poland(1000, 972, 48.7, 55.2, 13.8, 24.5, "Poland.png");
const Map Poland_relief(1000, 972, 48.7, 55.2, 13.8, 24.5, "Poland_relief.png");
const Map Europe(1249, 1024, 28, 82, -25, 54, "Europe.png");

Wyświetl plik

@ -20,3 +20,4 @@ executable('geostat', src, dependencies : [curl_dep, json_dep, magick_dep], link
configure_file(input: 'Poland.png', output: 'Poland.png', copy: true)
configure_file(input: 'Poland_relief.png', output: 'Poland_relief.png', copy: true)
configure_file(input: 'Europe.png', output: 'Europe.png', copy: true)