I'm using gdal_rasterize function to create a raster from my PostGIS database which contains measurements over the entire earth of a gas concentration. (almost 600'000 points over the polygon below) my goal is to create a raster with resolution 700x700 over a rectangular polygon.

'POLYGON ((-11.0000000000000000 34.0000000000000000, 42.0000000000000000 34.0000000000000000, 42.0000000000000000 72.0000000000000000, -11.0000000000000000 72.0000000000000000, -11.0000000000000000 34.0000000000000000))'),4326))

my problem is that setting:

-ts 700.0 700.0

-te 34 -11 72 42

does not return a correct raster over the polygon but a smaller square with latitude in (34,42) and longitude in (33,42)

I have tried to set the normal -te -180 -90 180 90 but then i get the correct polygon but not with the resolution i want (since the whole world is 700x700).

this is the full command i'm using

gdal_rasterize -l public.measurements -a no2_tropo -ts 700.0 700.0 -a_nodata 0.0 -te -180.0 -90.0 180.0 90.0 -ot Float32 -of GTiff "PG:dbname='testdb' host=localhost port=5432 user='postgres' password='admin' sslmode=disable" /home/dave/Desktop/fullPoints4k.tif^C
  • 2
    You should read carefully the manual page gdal.org/gdal_rasterize.html and double check the usage of terms resolution (-tr, pixel size), size of the output image (-ts, width and height in pixels), and extent (-te, the geographical area covered) in your question. – user30184 Nov 18 '18 at 23:37

I guess that it is an issue a specific vocabulary.

-ts is the Target Size, but not the size of the pixels: the size of the image in terms of number of pixels. It is expressed in number of lines and number of columns. First the number of columns (width) then the number of lines (heigth)

-tr is the Target Resolution, which correspond in gdal to the pixel size in two dimensions (pixels are not necessarily squares, but they often are). It is expressed in the coordinate system of the output. First along X (or longitude) then along Y (or latitude)

-te is the Target Extent, in other words the coordinates of the bounding box of the output image. It is expressed in the coordinate system of the output. xmin ymin xmax ymax

-ts, -te and -tr are lated to each other, so you only need to set two of them. Here is the simplified relationship for one dimension (assuming that there is no rotation) :

**width** (from ts) * **xres** (from tr) = **(xmax - xmin)** (from te)

Going back to your specific problem, I think that you want a resolution of 700 meters, but according to your polygon you are in WGS 84 (EPSG:4326). So you should set your resolution in degrees (approximately 700/110000 = 0.006363). For clipping, then make sure that you use xmin ymin xmax ymax: -11 34 42 72 So, here are your parameters :

-tr 0.006363 -te -11 34 42 72

As a remark, there is no unique conversion of meters into lat/long degrees because this is a function of the latitude and it would depend on a projection, but 110 km/degree is a good approximation along the equator and the meridians.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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