С помощью libosmium я загрузил карту, и достал из неё водоёмы. У меня есть массив вида
614879291:551879409; 614880288:551870745; 614883306:551866963; 614884798:551865497; 614884826:551864871; 614884138:551863174; 614882791:551862009; 614880428:551852906; 614879853:551844234; 614879730:551842378; 614879776:551841969; 614881010:551831052;
в котором хранятся координаты границ водоёма.
Проблема в том, что 1. координаты - очень "большие" числа(может быть это не проблема?), и 2. координаты очень близки и когда я их пытаюсь нарисовать, получается, что все они находятся в одной точки
Вот мой код:
#include <cstdio>
#include <cstdlib>
#include <iostream>
// For the location index. There are different types of indexes available.
// This will work for all input files keeping the index in memory.
#include <osmium/index/map/flex_mem.hpp>
// For the NodeLocationForWays handler
#include <osmium/handler/node_locations_for_ways.hpp>
// The type of index used. This must match the include file above
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
// The location handler always depends on the index type
using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
// For assembling multipolygons
#include <osmium/area/assembler.hpp>
#include <osmium/area/multipolygon_manager.hpp>
// Allow any format of input files (XML, PBF, ...)
#include <osmium/io/any_input.hpp>
// For osmium::geom::Coordinates
#include <osmium/geom/coordinates.hpp>
#include <osmium/geom/projection.hpp>
#include "GL/glut.h"
int WinWidth = 640;
int WinHeight = 480;
float zPos = -250;
struct Cords {
Cords(int x, int y) : x(x), y(y) {}
int x = 0, y = 0;
};
std::vector<Cords> lake;
class WaterHandler : public osmium::handler::Handler {
void print_water(const char *type, const char *name, const osmium::geom::Coordinates &c) {
std::printf("%8.4f,%8.4f %-15s %s\n", c.x, c.y, type, name ? name : "");
}
osmium::geom::Coordinates calc_center(const osmium::NodeRefList &nr_list) {
osmium::geom::Coordinates c{0.0, 0.0};
for (const auto &nr : nr_list) {
c.x += nr.lon();
c.y += nr.lat();
}
c.x /= nr_list.size();
c.y /= nr_list.size();
return c;
}
public:
void area(const osmium::Area &area) {
const char *water = area.tags()["water"];
if (water) {
const auto center = calc_center(*area.cbegin<osmium::OuterRing>());
for (const auto &nr : *area.cbegin<osmium::OuterRing>()) {
std::cout << nr.x() << ":" << nr.y() << "; ";
}
std::cout << std::endl;
print_water(water, area.tags()["name"], center);
if (lake.empty()) {
for (const auto &nr : *area.cbegin<osmium::OuterRing>()) {
lake.emplace_back(nr.x(), nr.y());
}
glutMainLoop();
}
}
}
}; // class WaterHandler
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0, 0, zPos);
glRotatef(90, 1.0, 0.0, 0.0);
glRotatef(0, 0.0, 1.0, 0.0);
glRotatef(0, 0.0, 0.0, 1.0);
glScalef(1, 1, 1);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor4f(0, 0, 1, 0.1);
glBegin(GL_QUADS);
glVertex3d(-60, 0, -70);
glVertex3d(60, 0, -70);
glVertex3d(60, 0, 70);
glVertex3d(-60, 0, 70);
glEnd();
glColor4f(0, 0, 1, 1);
glPolygonMode(GL_FRONT_AND_BACK, GL_POINTS);
glBegin(GL_POINTS);
for (const Cords &c : lake) {
glVertex3f(c.x, 0, c.y);
}
glEnd();
glFlush();
glutSwapBuffers();
}
void reshape(int w, int h) {
if (w == 0 || h == 0) return;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, w / h, 0.5, 5000);
glMatrixMode(GL_MODELVIEW);
WinWidth = w;
WinHeight = h;
}
void mouse(int btn, int state, int x, int y) {
if(btn == 3) { // Scroll down
zPos += 0.1;
} else if(btn == 4) { // Scroll up
zPos -= 0.1;
}
glutPostRedisplay();
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WinWidth, WinHeight);
glutCreateWindow("Test");
glPolygonMode(GL_FRONT_AND_BACK, GL_POINTS);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(1, 1, 1, 1.0);
glOrtho(-WinWidth, WinWidth, WinHeight, -WinHeight, 100, -100);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
const osmium::io::File input_file{"input.osm.pbf"};
osmium::area::Assembler::config_type assembler_config;
assembler_config.create_empty_areas = false;
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config};
std::cout << "Pass 1..." << std::endl;
osmium::relations::read_relations(input_file, mp_manager);
std::cout << "Pass 1 done" << std::endl;
index_type index;
location_handler_type location_handler{index};
location_handler.ignore_errors();
WaterHandler data_handler;
std::cout << "Pass 2..." << std::endl;
osmium::io::Reader reader{input_file, osmium::io::read_meta::no};
osmium::apply(reader, location_handler, data_handler,
mp_manager.handler([&data_handler](const osmium::memory::Buffer &area_buffer) {
osmium::apply(area_buffer, data_handler);
}));
reader.close();
std::cout << "Pass 2 done" << std::endl;
}
Я видел проекты для рисования карт, типа mapnik, или mapbox, но не смог разобраться в их коде.
C OpenGL, я работаю недавно, поэтому, возможно я делаю что-то глупое. Помогите, пожалуйста править этот код или хотя-бы подскажите, в каком направлении двигаться.
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Как понять какой #include нужно написать для MemoryStatusПотому что MemoryStatus выделяется в коде красным и говорит что идентификатор не определен
После получения настроек для входа через OAuth2 от Google, при попытке отправить запрос на вход через метод grant() появляется ошибка ShellExecute "<ссылка>"...
возник вопрос, написал я такой себе серверЕсли я запрашиваю картинку, то получаю следующее: Чтение для открытия HTML страниц вопросов не вызывает: