GDAL Contour Polygons – Resolving Issues with Flipped Contour Polygons in GDAL

contourdemgdalgdal-contour

UPDATE # 01 : Links to related past questions:

Mirrored Contours from DEM in QGIS

gdal_translate creates images that are mirrored

This question has been asked before, but I can't fix my personal issue, perhaps because the coordinate-less TIFF I'm using to produce my contour is one made up of bits of DEMs.

How can I have the contour appear exactly on top of my landmass?

GDAL command:
gdalinfo -mm -stats D:/H09.tiff
GDAL command output:
Driver: GTiff/GeoTIFF 
Files: D:/H09.tiff 
Size is 2244, 3564 
Metadata: 
TIFFTAG_DATETIME=2022:04:01 09:57:47 
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) 
TIFFTAG_XRESOLUTION=96 
TIFFTAG_YRESOLUTION=96 
Image Structure Metadata: 
COMPRESSION=DEFLATE 
INTERLEAVE=PIXEL 
PREDICTOR=2 
Corner Coordinates: 
Upper Left ( 0.0, 0.0) 
Lower Left ( 0.0, 3564.0) 
Upper Right ( 2244.0, 0.0) 
Lower Right ( 2244.0, 3564.0) 
Center ( 1122.0, 1782.0) 
Band 1 Block=2244x1 Type=UInt16, ColorInterp=Gray 
Computed Min/Max=0.000,36355.000 
Minimum=0.000, Maximum=36355.000, Mean=3509.658, StdDev=6167.460 
Mask Flags: PER_DATASET ALPHA 
Metadata: 
STATISTICS_MAXIMUM=36355 
STATISTICS_MEAN=3509.6577052462 
STATISTICS_MINIMUM=0 
STATISTICS_STDDEV=6167.4600463843 
STATISTICS_VALID_PERCENT=100 
Band 2 Block=2244x1 Type=UInt16, ColorInterp=Alpha 
Computed Min/Max=0.000,65535.000 
Minimum=0.000, Maximum=65535.000, Mean=21887.963, StdDev=30885.667 
Metadata: 
STATISTICS_MAXIMUM=65535 
STATISTICS_MEAN=21887.962675002 
STATISTICS_MINIMUM=0 
STATISTICS_STDDEV=30885.666560733 
STATISTICS_VALID_PERCENT=100
Process completed successfully
Execution completed in 0.34 seconds

enter image description here

Best Answer

You seem to have a DEM that is not georeferenced and then GDAL is using the default values:

  • origin at (0 0) - this is at the top left corner
  • pixel size (1 1) - coordinates are increased by one unit for each pixel to the right and towards the bottom from the top left corner

This leads sometimes into issues because in georeferenced data the Y coordinate is usually increasing from bottom to top - from the South towards the North.

I would try a workaround by creating a world file (.tfw) into the same directory where you have the image "H09.tiff". Name the world file as "H09.tfw" or "H09.wld". Both should work. Write these six lines into the world file:

1
0
0
-1
0
0