1

I downloaded the UN population density raster map (the 2020 prognosis) from here. I want to open this data in QGIS and have it projected correctly, but I can't seem to figure out how.

The following files are in the archive:

Files in archive

I am not sure what the xml files are for, but I know the tfw file is used to georeference the image so that the pixel coordinates can be mapped to WGS84 coordinates.

If I open the gpw-v4-population-density-adjusted-to-2015-unwpp-country-totals_2020.tif, which appears to be the main file, as raster file in QGIS, I get a correctly georefenced outline of the landmass of the world, but without any values representing population density (see here).

If I open the gpw-v4-population-density-adjusted-to-2015-unwpp-country-totals_2020.tif.ovr as raster file in QGIS, I get the population densities, but without proper georeferencing (see here). Strangely, this file seems to contain all relevant information, but is 1/4 the size of the other file, which seems to be useless.

How can I open the files in such a way that I have the population densities with the correct georeferencing? I thought QGIS would know how to do this automatically, but apparently not...

2 Answers 2

0

I think the problem is not that the data aren't loading in the first image, but rather, that they aren't being displayed the way you think they are.

Because the histogram of the population values is strongly skewed, QGIS loads 0,0 as the min,max values and everything shows up as black.

Try going into the style tab of the layer properties, and changing the "min" and "max" values to something like 1 and 50.

Alternately, you could classify them manually by changing the render type to "singleband pseudocolor" Like this image here

0

Here is a code to read qgis tiff file chunk wise,

import rasterio
import numpy as np
import cv2
from tqdm import tqdm

file_path = 'your_large_tiff_file.tif'

# Define chunk size (rows, columns)
chunk_size = (1000, 1000)
cv2.namedWindow('img', cv2.WINDOW_NORMAL)

# Open the QGIS TIFF file with Rasterio
with rasterio.open(file_path) as src:
    # Get image dimensions
    height, width = src.shape
    print(f'height, width: ({height, width})')
    k=-1

    # Iterate over chunks in both dimensions
    for y in tqdm(range(0, height, chunk_size[0])):
        for x in tqdm(range(0, width, chunk_size[1]),leave=False):
            # Calculate chunk window coordinates
            window = ((y, y + chunk_size[0]), (x, x + chunk_size[1]))

            # Read the chunk data directly using the window
            chunk = src.read(window=window)

            # Process the chunk as needed
            # ...your code here...
            # if np.any(chunk):
            if np.count_nonzero(chunk)>chunk.size * 0.95:
                # breakpoint()
                chunk1 = chunk[0:3]
                chunk_img=np.moveaxis(chunk1, 0,2)

                cv2.imshow('img',chunk_img)
                k=cv2.waitKey(10)
                if k==27: #Esc
                    break
        if k==27: #Esc
            break

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.