aresta / OSM_Extract

Extract OSM features in a configurable way to files to be used in other projects
GNU General Public License v3.0
8 stars 2 forks source link

Map question #8

Open jgauchia opened 2 months ago

jgauchia commented 2 months ago

Hi @aresta , how are you?

I've a little question.

It is possible to know, for the map being viewed (and with zoom level), the boundaries? (min-max latitude and longitude)

Thank you so much!

aresta commented 17 hours ago

Hi Jordi, sorry, I forgot the question. yes, the screen coordinates are in the viewPort struct, in mercator projection. To get latitude and longitude from mercator coordinates you need a function. In C it would be (thanks to chatgpt :-) :

#include <math.h>

// Earth's radius in meters (WGS 84)
#define EARTH_RADIUS 6378137.0

double mercator_X_to_lon( double x) {
    return (x / EARTH_RADIUS) * (180.0 / M_PI);
}

double mercator_Y_to_lat( double y) {
    return (atan(sinh(y / EARTH_RADIUS))) * (180.0 / M_PI);
}

Then, in the viewPort you have the boundary box visible in screen. The corners of the visible map would be:

viewPort.bbox.min.x
viewPort.bbox.min.y
viewPort.bbox.max.x
viewPort.bbox.max.y

They are already adjusted depending on the zoom level and the position. You can pass them to the functions above to get the lat/lon coordinates. If you would need the coordinates of the center of the display only, you have it also: viewPort.center.x, viewPort.center.y

I think that it should work, but I have not tested it, maybe I miss something. Let me know if it works. Salutacions!

jgauchia commented 12 hours ago

Hi @aresta no problem, I've closed the issue , but i needed this info. Oks, no problem I'll test It soon thank you! (Moltes gràcies)