Results 1 to 5 of 5

Thread: Shifting a continent

  1. #1
    Professional Artist Naima's Avatar
    Join Date
    Mar 2010
    Location
    Italy
    Posts
    1,583

    Default Shifting a continent

    Hellp , I am in the need to shift a continental mass for an already made heightmap from center of Equator zone , down to lower degrees, but how can I do so to enlarge and deform its dimensions ? I do not want to just copy /paste and manually edit it but wanted to know if there is a better more precise method eventually ?
    I thought about Hugin but it has a limited map size if I am not wrong.

  2. #2
    Administrator waldronate's Avatar
    Join Date
    Mar 2007
    Location
    The High Desert
    Posts
    3,607

    Default

    It depends on how big your image is, what format your pixels are, how big the continent is, how far you're moving it in latitude, what your starting projection is, and what your desired end projection is.

    GDAL's reprojectimage tool might work for you if you're starting with a common image format for your heightmap.

    It should be pretty straightforward to write a program to move a block of pixels in latitude for the Plate Caree (Equirectangular with uniform scaling in X and Y).
    The code below doesn't correctly recenter the result, but it does scale each scanline correctly.
    Code:
            m_SrcImage.Read(m_SrcName.GetBuffer());
    
    	int srcheight = m_SrcImage.GetYMax();
    	int srcwidth  = m_SrcImage.GetXMax();
    
    	double maxlat = M_PI / 2.0 - 0.01;
    	double deltalat = (srctop - srcbottom) / srcheight;
    
    	double maxscaling = 0;
    	for (int srcrow = 0; srcrow < srcheight; ++srcrow) {
    		double dstlat = dsttop - srcrow * deltalat;
    		double srclat = srctop - srcrow * deltalat;
    		if (fabs(dstlat) > maxlat || fabs(srclat) > maxlat) {
    			continue;
    		}
    		double scaling = cos(srclat) / cos(dstlat);
    		maxscaling = max(maxscaling, scaling);
    	}
    
    	int dstheight = srcheight;
    	int dstwidth = maxscaling * srcwidth;
    
    	m_DstImage.Open(maxscaling * srcwidth, srcheight);
    	for (int dstrow = 0; dstrow < dstheight; ++dstrow) {
    		for (int dstcol = 0; dstcol < dstwidth; ++dstcol) {
    			m_DstImage.PlotPixel(dstcol, dstrow, RGB(255, 0, 255));
    		}
    	}
    
    	for (int dstrow = 0; dstrow < dstheight; ++dstrow) {
    		double dstlat = dsttop - dstrow * deltalat;
    		double srclat = srctop - dstrow * deltalat;
    		if (fabs(dstlat) > maxlat || fabs(srclat) > maxlat) {
    			continue;
    		}
    		double scaling = cos(srclat) / cos(dstlat);
    		int dstcolofs = 0;// math is hard. too hard for me today...
    		for (int dstcol = 0; dstcol < dstwidth; ++dstcol) {
    			float srccol = dstcol / scaling;
    			if (srccol < 0 || srccol > srcwidth) {
    				continue;
    			}
    			auto srcPixel = m_SrcImage.ReadPixel(srccol, dstrow * 1.0f);
    			m_DstImage.PlotPixel(dstcolofs + dstcol, dstrow, srcPixel);
    		}
    	}
    
             m_DstImage.Write(m_DstName.GetBuffer())
    My compiler is acting up at the moment for making new projects or I'd write you one.
    I'm not mentally up with trying to wrassle JavaScript to the ground at the moment so that it will run in the browser, sorry.

    There's also a chance that I have from from/to scaling upside down. Equirectangular scaling should be x = 1/cos(lat), so the transform from lat0 to lat1 should be undo X at lat0 then redo at lat1, which should be 1/1/cos(lat0) * 1/cos(lat1). Maybe I did do it right, but I haven't checked it out.

    update: fixed the code to something that sort of works. I had a few sign and scale errors in the original code.
    Last edited by waldronate; 11-12-2022 at 06:52 PM.

  3. #3
    Professional Artist Naima's Avatar
    Join Date
    Mar 2010
    Location
    Italy
    Posts
    1,583

    Default

    Thanks for your answer, Ok my image is 21000 pixel wide x equirectangular , the continent is centered in 0 and spans from -35 deg to + 30 , I wanted to shift of 20 degrees south going from 10 to -55 or even more , the thing is I can of course make it manually by circle cutting the continent from the base heightmap , repaste it and shapeshift with grid manipulations in Photoshop according to a idea guess of the location but I wanted to try something more precise, also I have rivers that flow as pixel lines in already wilbur made erosion system in the original continent, I wonder if those could be shifted too but I fear that they might become stretched or enlarged and broken ,but anyway I am fine by remaking them manually after eventualy.
    So projection is equirectangular to equirectangular and the map is classic proportions of equirectangular earth but 21000 pixels wide. PNG image format.
    How I can use that tool program?
    https://gdal.org/programs/gdalwarp.html

  4. #4
    Administrator waldronate's Avatar
    Join Date
    Mar 2007
    Location
    The High Desert
    Posts
    3,607

    Default

    How wide is your continent (of the 21000-wide planetary map)? For transformations like this, you'd generally want to distort as little of the world as possible, so starting with a cropped continental area might be useful.

    Annoyingly, it turns out that I didn't get GDAL installed on my machine again when I had to reinstall everything last year and it didn't go well when I tried again just now. In theory, it should be a matter of doing something similar to https://blog.mastermaps.com/2014/01/...with-gdal.html (create a GeoTIFF using gdal_translate that describes the input image, then use gdalwarp to convert that to the desired output area). I can't tell you the exact command lines, but I think that the idea is to warp from one center in EPSG:4326 to a different center (you're basically doing an oblique equirectangular projection if I recall correctly).

    Sorry I can't be quite as much help as I'd hoped to be. I did write a little windows version of the program I described above, but it doesn't properly recenter the image, just stretches it on a scanline basis as shown below. I adjusted the code in the post above to be what's used in this program because it had several errors in it.
    Untitled-1.bmp.png
    It also only works on 24-bit uncompressed windows bitmap files because the library that I was using doesn't handle images much above 8K without problems. In theory, you can read a small enough PNG or JPG with it, but it will only output BMPs.
    http://www.fracterra.com/EquiSlide.zip is the executable if you'd like to try it. No guarantees about anything at all, as always (make a backup of your files before starting!) I really need to go about getting a security certificate for that site one of these years...

  5. #5
    Professional Artist Naima's Avatar
    Join Date
    Mar 2010
    Location
    Italy
    Posts
    1,583

    Default

    Quote Originally Posted by waldronate View Post
    How wide is your continent (of the 21000-wide planetary map)? For transformations like this, you'd generally want to distort as little of the world as possible, so starting with a cropped continental area might be useful.

    Annoyingly, it turns out that I didn't get GDAL installed on my machine again when I had to reinstall everything last year and it didn't go well when I tried again just now. In theory, it should be a matter of doing something similar to https://blog.mastermaps.com/2014/01/...with-gdal.html (create a GeoTIFF using gdal_translate that describes the input image, then use gdalwarp to convert that to the desired output area). I can't tell you the exact command lines, but I think that the idea is to warp from one center in EPSG:4326 to a different center (you're basically doing an oblique equirectangular projection if I recall correctly).

    Sorry I can't be quite as much help as I'd hoped to be. I did write a little windows version of the program I described above, but it doesn't properly recenter the image, just stretches it on a scanline basis as shown below. I adjusted the code in the post above to be what's used in this program because it had several errors in it.
    Untitled-1.bmp.png
    It also only works on 24-bit uncompressed windows bitmap files because the library that I was using doesn't handle images much above 8K without problems. In theory, you can read a small enough PNG or JPG with it, but it will only output BMPs.
    http://www.fracterra.com/EquiSlide.zip is the executable if you'd like to try it. No guarantees about anything at all, as always (make a backup of your files before starting!) I really need to go about getting a security certificate for that site one of these years...
    Thankyou , I ended up doing a hybrid way , I picked up Hugin , I did a translate manually of the whole heightmap where I wanted, then I cropped and faded parts of it and overlayed on older map working out inconsistencies ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •