I'm currently working on a project that represents geographic data in 3D using Unity. It basically loads, when given a GPS position, the area around it. For example, given the coordinate 50.5N 6.5E it will load the terrain from 50N to 51N and 6E to 7E. Once the terrain is loaded a texture is applied to the 3D mesh, this texture can be a Landsat image or a Openstreetmap map for example.
I downloaded elevation data (*.hgt files) from NASA’s Shuttle Radar Topography Mission (SRTM). These files have a resolution of 1 arc-second (30m) and contain a 3601 x 3601 matrix of points that represent the height for that coordinate, being the first value of the file the bottom-left coordinate (50N, 6E in my previous example).
To calculate the distance along the longitude between the height points I represent, I apply Haversine's formula (in the file distances between points are not specified). With it I obtain the distance between longitudes for the given latitude, which I can then divide by 3600, obtaining the distance between points.
For Haversine's formula i don't use a fixed value for earth's radius. Depending on the latitude I adjust it between the value at equator and the value at the poles.
For the distance along the latitude its easier since I only have to divide the constant distance (111.2 Km) by the number of points (3600).
Up to here I think that everything is fine and that I have done everything properly. The problem comes now, when applying a texture to the 3D mesh.
To obtain an aerial image of the area I am representing I decided to use Universal Maps Downloader. It allows you to introduce a set of latitudes and longitudes, choose a source (Google Street Maps, ArcGis Online Topography, Open Street Maps...), a level of zoom, and downloads the images of the area as a set of tiles that can be merged into a single image file using the included Map Combiner.
I import this image into Unity and apply it as a texture to the mesh (I don't think that talking about how I adjust the UVs is relevant), and it works, but not perfectly.
The problem is that the texture (call it aerial image or map, as you prefer) doesn't match the topographic data well. Depending on the location I load the image has an offset to the 3D mesh, the direction in which the image is displaced follows no pattern apparently (sometimes a bit to the left sometimes to the right, sometimes a lot, sometimes not much, sometimes up, sometimes down....).
I can adjust it manually adding an offset to the UV mapping, but that is only possible if I have visual references like rivers or coastlines. And since the offset doesn't follow a pattern I can't program my own offset adjustment.
The question is basically: does anyone know where is my mistake or how could I improve my results?
Maybe I'm downloading aerial imagery from the wrong place (and it is not precise) and I should use a different source. So far this option is the only one that lets me obtain images of quality for a given area defined by a set of coordinates in a quite simple and fast way. I couldn't find anything similar.
Maybe I'm doing something wrong when representing the SRTM files.
Perhaps I took a wrong approach from the beginning...
28N, 17W Tenerife and 50N, 6E NRW-Cologne