4

I'm trying to reproject Mapbox maps from whatever projection they come in (which I believe is EPSG:3857) to what I believe should be a Gnomonic projection.

Let me try to be more clear actually. I'd like to use the map tiles to generate UV faces for a cube like this one:

Earth Cube

The image below uses an equirectangular environment texture as the diffuse shader for the cube, and baking a single face of the cube would result in an image like this one:

North Face

What I'm trying to do is get a similar "cube face" texture, but without using Blender to shade and bake the texture. Instead I'm trying to use GDAL to reproject the texture to what I believe should be a Gnomonic projection, with radius equal to half the diagonal of a cube face, and the centre of projection being the coordinates that map to the centre of the cube face. So for the North Pole, that would be 90°N 0°E, and for the front face that would just be 0°N 0°E.

So to get the face that would contain the British isles, I thought these GDAL commands should suffice:

gdal_translate -a_srs EPSG:3857 -a_ullr -20026376.39 20048966.10 20026376.39 -20048966.10
gdalwarp -t_srs +proj=gnom

But if I do that, I instead get a very high image with narrow width, that seems to contain mostly just ocean.

The question is, what would be the right projection string to get a cube-face like the picture above?


Note that I've been using gdal-js to do the transformations in the browser. See this CodePen for example, which contains an example that converts the source image to equirectangular projection. The projection string can be edited in the JS editor and the result is updated real-time (this is what I used to experiment with projections.)


UPDATE:

I think I'm doing something wrong with the reprojection. The following commands give me the wonky looking result below:

gdal_translate -a_srs EPSG:3857 -a_ullr -20026376.39 20048966.10 20026376.39 -20048966.10
gdalwarp -t_srs +proj=ortho

+proj=ortho

I'm pretty sure that transparent band around the equator should not be there. Instead, there should be a transparent bit around the poles, since web mercator does not cover the last 5°s or so.

1 Answer 1

5

Gnomonic projection is OK. The radius must be a half of one side, not one diagonal.

You are projecting longitudes +90 and -90 degrees until infinite, but GDAL stops at some point. Since the poles are not present in the source image, the image is infinite just in width. Strange that you see it as a high image, maybe rotated by some reason, I don't know.

About the Orthographic projection, the image is cutted by 5 degrees at poles. The equator issue is because you are reprojecting also the dark side of the Earth. Always avoid to reproject coordinates that are not in the domain of the projection.

Let me start with the wikimedia image of the Mercator projection.

If the world is a 1 meter radius sphere, the circumference is 2 pi, so georreference the image:

gdal_translate -a_srs '+proj=merc +R=1' -a_ullr -3.14159 3.14159 3.14159 -3.14159 Mercator_projection_Square.JPG translated.tif

Now, reproject the first face to a cube of 2 meters side:

gdalwarp -t_srs '+proj=gnom +R=1 +lat_0=0 +lon_0=0' -te -1 -1 1 1 translated.tif face1.tif

2


Face 2:

gdalwarp -t_srs '+proj=gnom +R=1 +lat_0=0 +lon_0=90' -te -1 -1 1 1 translated.tif face2.tif

3


For the 180 degrees center you will need a image with some continuity there:

gdal_translate -a_srs '+proj=merc +R=1' -a_ullr 3.14159 3.14159 9.42478 -3.14159 Mercator_projection_Square.JPG translated2.tif
gdal_merge.py -o extended.tif translated.tif translated2.tif

4

Maybe some rounding coordinates or just source image problems, you will be do it better. Let's reproject:

gdalwarp -t_srs '+proj=gnom +R=1 +lat_0=0 +lon_0=180' -te -1 -1 1 1 extended.tif face3.tif

5


No problem with face 4:

gdalwarp -t_srs '+proj=gnom +R=1 +lat_0=0 +lon_0=-90' -te -1 -1 1 1 translated.tif face4.tif

6


And well, the poles, they are not included in the Mercator projection, just start with a good map.

6
  • Hi, thanks for the detailed answer! I think the main takeaway here was the use of -a_srs "+proj=merc +R=1". Next, I changed -a_ullr from (-π, π, π, -π) to (-π, π*85.06/90, π, -π*85.06/90) as web mercator only goes until 85.06°. I'm not entirely sure that is correct, but that fixes the "glitch" in the orthographic projection, for example.
    – Attila O.
    Commented Jan 15, 2021 at 10:17
  • OK I got it to work finally! So just adding -te -1 -1 1 1 to gdalwarp would still fail for me, with the error "Attempt to create 0x0 dataset is illegal, sizes must be larger than zero". But not adding -te would make the image infinitely large and only contain distorted data coming from near the horizon. The solution was to add both -te -1 -1 1 1 and specify the target size, i.e. -ts 1024 1024 works just fine.
    – Attila O.
    Commented Jan 15, 2021 at 10:29
  • Also note that I don't need to merge two tiles to do the gnomonic projection at 180° longitude. Looks like GDAL can do the projection simply by joining the two ends. (But I still get the same "gap" that you get". And there is also a tiny ~1px "glitch" near the equator, but I'm assuming that is due to floating point errors.)
    – Attila O.
    Commented Jan 15, 2021 at 10:35
  • You are welcome. The web Mercator image is a square, so coordinates of the extents are symmetric (-π, π, π, -π). But if you have it worked that other way is ok. Commented Jan 15, 2021 at 10:37
  • BTW the weird black band on the +lon_0=180 face is gone when using GDAL 3. Might be a bug in GDAL 2, not sure which version you were using. In any case, updating GDAL seems to fix that.
    – Attila O.
    Commented Jan 15, 2021 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.