bgp2000
bgp2000

Reputation: 1124

Using gdalwarp to extract same dimension thumbnails of cities

I have a georeferenced tiff of Europe and I would like to extract thumbnails of cities, with the same size and GSD.

Say the inputs are.

What gdalwarp command will result in a 100x100 pixel thumbnail of Paris?

Upvotes: 1

Views: 113

Answers (1)

L. Meyer
L. Meyer

Reputation: 3253

As it's not mentioned, I will consider the SRS as EPSG:4326. At the scale of the Europe, you won't have the same resolution depending on the latitude.

First, let's compute the boundaries of a square (approximated) of side d in km centered on a specific coordinate.

degree_to_rad(r):
  return r * 2 * PI / 360

delta_latitude  = d / (degree_to_rad(1) * 6370)
delta_longitude = delta_latitude / cosinus(degree_to_rad(lat))

xmin = lng - delta_longitude/2
xmax = lng + delta_longitude/2
ymin = lat - delta_latitude/2
ymax = lat + delta_latitude/2

This gives for lat=48.8566, lng=2.3522:

xmin = 1.6686613990086685
xmax = 3.035738600991331
ymin = 48.406868606647706
ymax = 49.306331393352295

Now using the te option of gdalwrap https://gdal.org/programs/gdalwarp.html#cmdoption-gdalwarp-te:

gdalwrap -te 1.6686613990086685 48.406868606647706 3.035738600991331 49.306331393352295 input.tif output.tif

You will have the same resolution of your original tiff.

Upvotes: 0

Related Questions