I'm attempting to render continental geometric data stored within an R-Tree in a SQlite database. The data is store as long/lat WGS84 and I'm trying to render it to 256px PNGs for displaying on a slippy map. Keep in mind I have no training in GIS mapping and rendering and everything I know is self taught.
When I render it using OpenGL, I'm simply remapping the long/lat coordinates of each of the polygons returned from the SQLite query into a 0px to 256px x/y coordinate space for rendering on a slippy map tile using the following code:
X = (long - extent.X1) / (extent.X2 - extent.X1) * ImageSize; Y = (((lat - extent.Y1) / (extent.Y2 - extent.Y1) * ImageSize) *-1) + ImageSize;
For the Y coordinate, I'm switching the axis so that 0:0 is the top left of the image.
The extent information in the above code is built by taking X/Y and Zoom data from a slippy map (leaflet.js in this case) and converted into long/lat bounds using the code provided by OSM here
Thats all I do before I send the X & Y data over to OpenGL.
At the higher zoom levels (5+). The polygons render okay, heres Australia at zoom level 5 (there are 1 or 2 exceptions around the equator where there are some glitches at zoom level 5, but they seem to completely disappear at zoom levels 6+):
However, at zoom levels below 5, things start to go hay wire, here's Australia and South Asia at zoom level 3:
There are significant glitches in the rendering, (repetition and misalignment with the rendered polygons on the tiles and stretching of the continents) And it only gets worse as I zoom out more. Here's part of the map at zoom level 2:
It seemed weird to me that everything would render well at the higher zoom levels but fail so badly at the lower ones. But then it occurred to me that the closer to earth I go, the flatter (and more 2D like) it becomes, so I'm now wondering if the reason for the major issues I'm having is because I'm not projecting to a Cartesian coordinate system first.
Can anyone confirm whether this is the case and if so, what should I be using to convert the coordinates from WGS84 to Cartesian X/Y?